Callback from DLL

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
 
N

Nenad Dobrilovic

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top