Callback from DLL

  • Thread starter Thread starter Nenad Dobrilovic
  • Start date Start date
N

Nenad Dobrilovic

Hi,

I have one annoying problem. I made callback function from DLL made in
C++ to C# program. As I can see, it is rather easy, and there was no
reported problems on Internet.
But, it doesn't work in my code...
It should work like this: I call 'Connect' function in DLL, which starts
the thread; the thread calls (using callback) functions in managed code.
When I walk through debbuger, and I stop the main thread in C#, it
really works for one or two times, but after that I get "privileged
instruction" exception. I opposite case, when main thread is not
stopped, I get exception immediately.
If I don't use debugger, it doesn't work at all. I get "null reference"
exception first time when callback should be called.

Can anyone help me?
Thank you in advance, Nenad
 
Nenad said:
Hi,

I have one annoying problem. I made callback function from DLL made in
C++ to C# program. As I can see, it is rather easy, and there was no
reported problems on Internet.
But, it doesn't work in my code...
It should work like this: I call 'Connect' function in DLL, which starts
the thread; the thread calls (using callback) functions in managed code.
When I walk through debbuger, and I stop the main thread in C#, it
really works for one or two times, but after that I get "privileged
instruction" exception. I opposite case, when main thread is not
stopped, I get exception immediately.
If I don't use debugger, it doesn't work at all. I get "null reference"
exception first time when callback should be called.

Can anyone help me?
Thank you in advance, Nenad

Problem is solved by moving the code for registering delegates to DLL
from main thread to working thread.

Nenad
 
Back
Top