Com Interoperabilty

G

Guest

Hi,

Am new to this topic & am stuck in the following. Any help is greatly
appreciated.

I have a unmanaged Dll written in vc++ 6.0 & it has an interface which can
be used for call back.

Now, I am trying to implement the call back interface in C# .net. which has
a single method "Call me".

Now, on some of the events of my application, it will call the Call the Call
back interface. & here I need to receive the call back in C#.net dll.

Can Somebody suggest me, how can I acheive this.

Thanks,
Kalicharan.
 
M

Michael C

Baji. said:
Hi,

Am new to this topic & am stuck in the following. Any help is greatly
appreciated.

I have a unmanaged Dll written in vc++ 6.0 & it has an interface which can
be used for call back.

Now, I am trying to implement the call back interface in C# .net. which
has
a single method "Call me".

Now, on some of the events of my application, it will call the Call the
Call
back interface. & here I need to receive the call back in C#.net dll.

Can Somebody suggest me, how can I acheive this.

You should create a delegate

public delegate void CallMeDelegate();

then create a function that will be called

public void CallMe()
{
}

then pass the delegate to an API call

CallMeDelegate x = new CallMeDelegate(CallMe);
SetCallback(x);

There's a couple of things to watch out for. The first is that you might
need to keep an instance of the delegate because there is nothing stop it
being GC'd. The second is that you have to be careful that you aren't
passing an object pointer to the instance of x, instead of passing a pointer
to the function. You do this by marking the parameter as
UnmanagedType.FunctionPointer I believe. It's been a while since I have done
this so that last step might not be required.

Michael
 
G

Guest

Hi Michael,

Here I can't change the unmanaged DLL source code. Do you think this wokrs
in this scenario too? Meanwhile, I can see some examples of delegates too.
Let me try with that.

Thanks,
Baji.
 
M

Michael C

Baji. said:
Hi Michael,

Here I can't change the unmanaged DLL source code. Do you think this wokrs
in this scenario too?

Yes, that's what it's designed for. You will need to modify the delegate to
add the required parameters.
Meanwhile, I can see some examples of delegates too.
Let me try with that.

Let me know how you go.

Michael
 

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