B
bsnguy
I have two callback functions declared in my C# code:
public unsafe static void CallbackA()
/* yes, I do mean to declare this as unsafe and static in my real code...
read on */
{
MessageBox.Show(@"Debug.", @"Got Here A");
}
public void CallbackB()
{
MessageBox.Show(@"Debug.", @"Got Here B");
}
I assign them delegates and pass the pointers to my DLL (which is written in
unmanaged C code). In my C code, I use them like this:
void (CALLBACK *CallbackA)(void) = NULL;
void (CALLBACK *CallbackB)(void) = NULL;
int FunctionA (void) {
...
CallbackA();
...
}
void FunctionB (void) {
...
CallbackB();
...
}
in other words, things are pretty much the same except the return value.
- Every time I call FunctionB which uses CallbackB, all is fine (Callback B
runs as expected).
- When I call CallbackA in FunctionA, the very first time, it crashes with
an Illegal Instruction exception.
- if I call CallbackA from within FunctionB, it works just fine.
- if I call CallbackB from within FunctionA, it fails.
- When I ran the same DLL with unmanaged C code, all worked fine and as
expected.
So, it's something about FunctionA's return parameter that's causing this?
Doesn't make sense to me, but it sure looks that way.
Any ideas on what else to look for or how I might fix this?
I figure that the root cause is that the function pointer is bad and I'm
trying to execute data (the stack, heap, etc.). I cannot explain why, though.
When I look at the pointers passed, they look right.
public unsafe static void CallbackA()
/* yes, I do mean to declare this as unsafe and static in my real code...
read on */
{
MessageBox.Show(@"Debug.", @"Got Here A");
}
public void CallbackB()
{
MessageBox.Show(@"Debug.", @"Got Here B");
}
I assign them delegates and pass the pointers to my DLL (which is written in
unmanaged C code). In my C code, I use them like this:
void (CALLBACK *CallbackA)(void) = NULL;
void (CALLBACK *CallbackB)(void) = NULL;
int FunctionA (void) {
...
CallbackA();
...
}
void FunctionB (void) {
...
CallbackB();
...
}
in other words, things are pretty much the same except the return value.
- Every time I call FunctionB which uses CallbackB, all is fine (Callback B
runs as expected).
- When I call CallbackA in FunctionA, the very first time, it crashes with
an Illegal Instruction exception.
- if I call CallbackA from within FunctionB, it works just fine.
- if I call CallbackB from within FunctionA, it fails.
- When I ran the same DLL with unmanaged C code, all worked fine and as
expected.
So, it's something about FunctionA's return parameter that's causing this?
Doesn't make sense to me, but it sure looks that way.
Any ideas on what else to look for or how I might fix this?
I figure that the root cause is that the function pointer is bad and I'm
trying to execute data (the stack, heap, etc.). I cannot explain why, though.
When I look at the pointers passed, they look right.