PC Review


Reply
Thread Tools Rate Thread

Com Interoperabilty

 
 
=?Utf-8?B?QmFqaS4=?=
Guest
Posts: n/a
 
      12th Nov 2007
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.


 
Reply With Quote
 
 
 
 
Michael C
Guest
Posts: n/a
 
      13th Nov 2007
"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


 
Reply With Quote
 
=?Utf-8?B?QmFqaS4=?=
Guest
Posts: n/a
 
      13th Nov 2007
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
>
>
>

 
Reply With Quote
 
Michael C
Guest
Posts: n/a
 
      13th Nov 2007
"Baji." <(E-Mail Removed)> wrote in message
news:F28C36BF-4338-46C5-AA5D-(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Interoperabilty with outlook 2003? =?Utf-8?B?Q2hyaXM=?= Microsoft Word Document Management 1 17th Feb 2004 11:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:23 PM.