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.
"Michael C" wrote:
> "Baji." <Baji.@discussions.microsoft.com> wrote in message
> news:45BD8461-DD5A-427B-B61E-(E-Mail Removed)...
> > 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
>
>
>
|