By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,724 Members | 863 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,724 IT Pros & Developers. It's quick & easy.

Delegate from C++ to C#

P: n/a
I have an application in managed C++, and a method in C# that I call. But now
I want to add the ability to tell the C# method a specific method in my C++
assembly to call back to. For example, to have the C++ call a sort routine in
C#, and send it a compare method, which the C## would call back to. I know
that within C# pointing to methods is done with delegates, but is it possible
between C++ and C#? Is there an example of this somewhere that anyone knows
of? Thanks for any help you can provide.

Feb 28 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Richard,
Welcome to MSDN Newsgroup!

I hope the following articles are helpful for you,
Title: Using C calling convention callback functions in C# and VB - the
easy way
URL: http://www.codeproject.com/dotnet/Cdecl_CSharp_VB.asp

Title: Delegates Tutorial - MC++ and C# - The dual perspective
URL:http://www.codeproject.com/managedcpp/csdeleg01.asp

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security

--------------------
Thread-Topic: Delegate from C++ to C#
thread-index: AcY8vySwZY6j6QVJS0qDqhdcP02TiA==
X-WBNR-Posting-Host: 205.207.165.144
From: "=?Utf-8?B?UmljaGFyZCBNU0w=?=" <Ri*************@nospam.nospam>
Subject: Delegate from C++ to C#
Date: Tue, 28 Feb 2006 15:31:47 -0800
Lines: 8
Message-ID: <A8**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.general
Path: TK2MSFTNGXA03.phx.gbl
Xref: TK2MSFTNGXA03.phx.gbl microsoft.public.dotnet.general:189842
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
X-Tomcat-NG: microsoft.public.dotnet.general

I have an application in managed C++, and a method in C# that I call. But nowI want to add the ability to tell the C# method a specific method in my C++assembly to call back to. For example, to have the C++ call a sort routine inC#, and send it a compare method, which the C## would call back to. I know
that within C# pointing to methods is done with delegates, but is it possiblebetween C++ and C#? Is there an example of this somewhere that anyone knowsof? Thanks for any help you can provide.


Mar 1 '06 #2

P: n/a
Thank you. The second article looks perfect, I will see what I can do with it.

""TerryFei"" wrote:
Hi Richard,
Welcome to MSDN Newsgroup!

I hope the following articles are helpful for you,
Title: Using C calling convention callback functions in C# and VB - the
easy way
URL: http://www.codeproject.com/dotnet/Cdecl_CSharp_VB.asp

Title: Delegates Tutorial - MC++ and C# - The dual perspective
URL:http://www.codeproject.com/managedcpp/csdeleg01.asp

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security

--------------------
Thread-Topic: Delegate from C++ to C#
thread-index: AcY8vySwZY6j6QVJS0qDqhdcP02TiA==
X-WBNR-Posting-Host: 205.207.165.144
From: "=?Utf-8?B?UmljaGFyZCBNU0w=?=" <Ri*************@nospam.nospam>
Subject: Delegate from C++ to C#
Date: Tue, 28 Feb 2006 15:31:47 -0800
Lines: 8
Message-ID: <A8**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.general
Path: TK2MSFTNGXA03.phx.gbl
Xref: TK2MSFTNGXA03.phx.gbl microsoft.public.dotnet.general:189842
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
X-Tomcat-NG: microsoft.public.dotnet.general

I have an application in managed C++, and a method in C# that I call. But

now
I want to add the ability to tell the C# method a specific method in my

C++
assembly to call back to. For example, to have the C++ call a sort routine

in
C#, and send it a compare method, which the C## would call back to. I know
that within C# pointing to methods is done with delegates, but is it

possible
between C++ and C#? Is there an example of this somewhere that anyone

knows
of? Thanks for any help you can provide.


Mar 1 '06 #3

P: n/a
Hi Richard,
We are glad to know our information is helpful for you. It's my pleasure to
work with you. Thanks!

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security

--------------------
Thread-Topic: Delegate from C++ to C#
thread-index: AcY9SdMxjtwJBQw2QOSL5vwicxG5sQ==
X-WBNR-Posting-Host: 205.207.165.144
From: "=?Utf-8?B?UmljaGFyZCBNU0w=?=" <Ri*************@nospam.nospam>
References: <A8**********************************@microsoft.co m> <Wz**************@TK2MSFTNGXA03.phx.gbl>Subject: RE: Delegate from C++ to C#
Date: Wed, 1 Mar 2006 08:04:31 -0800
Lines: 61
Message-ID: <FF**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.general
Path: TK2MSFTNGXA03.phx.gbl
Xref: TK2MSFTNGXA03.phx.gbl microsoft.public.dotnet.general:189914
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
X-Tomcat-NG: microsoft.public.dotnet.general

Thank you. The second article looks perfect, I will see what I can do with it.
""TerryFei"" wrote:
Hi Richard,
Welcome to MSDN Newsgroup!

I hope the following articles are helpful for you,
Title: Using C calling convention callback functions in C# and VB - the
easy way
URL: http://www.codeproject.com/dotnet/Cdecl_CSharp_VB.asp

Title: Delegates Tutorial - MC++ and C# - The dual perspective
URL:http://www.codeproject.com/managedcpp/csdeleg01.asp

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security

--------------------
>Thread-Topic: Delegate from C++ to C#
>thread-index: AcY8vySwZY6j6QVJS0qDqhdcP02TiA==
>X-WBNR-Posting-Host: 205.207.165.144
>From: "=?Utf-8?B?UmljaGFyZCBNU0w=?=" <Ri*************@nospam.nospam>
>Subject: Delegate from C++ to C#
>Date: Tue, 28 Feb 2006 15:31:47 -0800
>Lines: 8
>Message-ID: <A8**********************************@microsoft.co m>
>MIME-Version: 1.0
>Content-Type: text/plain;
> charset="Utf-8"
>Content-Transfer-Encoding: 7bit
>X-Newsreader: Microsoft CDO for Windows 2000
>Content-Class: urn:content-classes:message
>Importance: normal
>Priority: normal
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
>Newsgroups: microsoft.public.dotnet.general
>Path: TK2MSFTNGXA03.phx.gbl
>Xref: TK2MSFTNGXA03.phx.gbl microsoft.public.dotnet.general:189842
>NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
>X-Tomcat-NG: microsoft.public.dotnet.general
>
>I have an application in managed C++, and a method in C# that I call. But
now
>I want to add the ability to tell the C# method a specific method in my

C++
>assembly to call back to. For example, to have the C++ call a sort
routine in
>C#, and send it a compare method, which the C## would call back to. I

know >that within C# pointing to methods is done with delegates, but is it

possible
>between C++ and C#? Is there an example of this somewhere that anyone

knows
>of? Thanks for any help you can provide.
>
>



Mar 2 '06 #4

P: n/a
Just a note to follow up in case anyone has a similar problem, I was able to
make a C++ program with a method in it, then call a C# function, sending in
the delegate to the method, and the C# called back to the C++ method.

Thanks again for the help.
""TerryFei"" wrote:
Hi Richard,
We are glad to know our information is helpful for you. It's my pleasure to
work with you. Thanks!

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security

--------------------
Thread-Topic: Delegate from C++ to C#
thread-index: AcY9SdMxjtwJBQw2QOSL5vwicxG5sQ==
X-WBNR-Posting-Host: 205.207.165.144
From: "=?Utf-8?B?UmljaGFyZCBNU0w=?=" <Ri*************@nospam.nospam>
References: <A8**********************************@microsoft.co m>

<Wz**************@TK2MSFTNGXA03.phx.gbl>
Subject: RE: Delegate from C++ to C#
Date: Wed, 1 Mar 2006 08:04:31 -0800
Lines: 61
Message-ID: <FF**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.general
Path: TK2MSFTNGXA03.phx.gbl
Xref: TK2MSFTNGXA03.phx.gbl microsoft.public.dotnet.general:189914
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
X-Tomcat-NG: microsoft.public.dotnet.general

Thank you. The second article looks perfect, I will see what I can do with

it.

""TerryFei"" wrote:
Hi Richard,
Welcome to MSDN Newsgroup!

I hope the following articles are helpful for you,
Title: Using C calling convention callback functions in C# and VB - the
easy way
URL: http://www.codeproject.com/dotnet/Cdecl_CSharp_VB.asp

Title: Delegates Tutorial - MC++ and C# - The dual perspective
URL:http://www.codeproject.com/managedcpp/csdeleg01.asp

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security

--------------------
>Thread-Topic: Delegate from C++ to C#
>thread-index: AcY8vySwZY6j6QVJS0qDqhdcP02TiA==
>X-WBNR-Posting-Host: 205.207.165.144
>From: "=?Utf-8?B?UmljaGFyZCBNU0w=?=" <Ri*************@nospam.nospam>
>Subject: Delegate from C++ to C#
>Date: Tue, 28 Feb 2006 15:31:47 -0800
>Lines: 8
>Message-ID: <A8**********************************@microsoft.co m>
>MIME-Version: 1.0
>Content-Type: text/plain;
> charset="Utf-8"
>Content-Transfer-Encoding: 7bit
>X-Newsreader: Microsoft CDO for Windows 2000
>Content-Class: urn:content-classes:message
>Importance: normal
>Priority: normal
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
>Newsgroups: microsoft.public.dotnet.general
>Path: TK2MSFTNGXA03.phx.gbl
>Xref: TK2MSFTNGXA03.phx.gbl microsoft.public.dotnet.general:189842
>NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
>X-Tomcat-NG: microsoft.public.dotnet.general
>
>I have an application in managed C++, and a method in C# that I call. But now
>I want to add the ability to tell the C# method a specific method in my
C++
>assembly to call back to. For example, to have the C++ call a sort routine in
>C#, and send it a compare method, which the C## would call back to. I know >that within C# pointing to methods is done with delegates, but is it
possible
>between C++ and C#? Is there an example of this somewhere that anyone
knows
>of? Thanks for any help you can provide.
>
>


Mar 7 '06 #5

P: n/a
Hi Richard,
You are welcome. Thanks!

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
--------------------
Thread-Topic: Delegate from C++ to C#
thread-index: AcZCOXf/Nxnm/ZZOQpiUMKTzvwqQqA==
X-WBNR-Posting-Host: 205.207.165.144
From: =?Utf-8?B?UmljaGFyZCBNU0w=?= <Ri*************@nospam.nospam>
References: <A8**********************************@microsoft.co m> <Wz**************@TK2MSFTNGXA03.phx.gbl>
<FF**********************************@microsoft.co m>
<AP**************@TK2MSFTNGXA03.phx.gbl>Subject: RE: Delegate from C++ to C#
Date: Tue, 7 Mar 2006 14:50:02 -0800
Lines: 113
Message-ID: <0D**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
Newsgroups: microsoft.public.dotnet.general
Path: TK2MSFTNGXA03.phx.gbl
Xref: TK2MSFTNGXA03.phx.gbl microsoft.public.dotnet.general:190365
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
X-Tomcat-NG: microsoft.public.dotnet.general

Just a note to follow up in case anyone has a similar problem, I was able tomake a C++ program with a method in it, then call a C# function, sending inthe delegate to the method, and the C# called back to the C++ method.

Thanks again for the help.
""TerryFei"" wrote:
Hi Richard,
We are glad to know our information is helpful for you. It's my pleasure to work with you. Thanks!

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security

--------------------
>Thread-Topic: Delegate from C++ to C#
>thread-index: AcY9SdMxjtwJBQw2QOSL5vwicxG5sQ==
>X-WBNR-Posting-Host: 205.207.165.144
>From: "=?Utf-8?B?UmljaGFyZCBNU0w=?=" <Ri*************@nospam.nospam>
>References: <A8**********************************@microsoft.co m>

<Wz**************@TK2MSFTNGXA03.phx.gbl>
>Subject: RE: Delegate from C++ to C#
>Date: Wed, 1 Mar 2006 08:04:31 -0800
>Lines: 61
>Message-ID: <FF**********************************@microsoft.co m>
>MIME-Version: 1.0
>Content-Type: text/plain;
> charset="Utf-8"
>Content-Transfer-Encoding: 7bit
>X-Newsreader: Microsoft CDO for Windows 2000
>Content-Class: urn:content-classes:message
>Importance: normal
>Priority: normal
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
>Newsgroups: microsoft.public.dotnet.general
>Path: TK2MSFTNGXA03.phx.gbl
>Xref: TK2MSFTNGXA03.phx.gbl microsoft.public.dotnet.general:189914
>NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
>X-Tomcat-NG: microsoft.public.dotnet.general
>
>Thank you. The second article looks perfect, I will see what I can do with
it.
>
>""TerryFei"" wrote:
>
>> Hi Richard,
>> Welcome to MSDN Newsgroup!
>>
>> I hope the following articles are helpful for you,
>> Title: Using C calling convention callback functions in C# and VB -
the >> easy way
>> URL: http://www.codeproject.com/dotnet/Cdecl_CSharp_VB.asp
>>
>> Title: Delegates Tutorial - MC++ and C# - The dual perspective
>> URL:http://www.codeproject.com/managedcpp/csdeleg01.asp
>>
>> Best Regards,
>>
>> Terry Fei [MSFT]
>> Microsoft Community Support
>> Get Secure! www.microsoft.com/security
>>
>> --------------------
>> >Thread-Topic: Delegate from C++ to C#
>> >thread-index: AcY8vySwZY6j6QVJS0qDqhdcP02TiA==
>> >X-WBNR-Posting-Host: 205.207.165.144
>> >From: "=?Utf-8?B?UmljaGFyZCBNU0w=?=" <Ri*************@nospam.nospam>
>> >Subject: Delegate from C++ to C#
>> >Date: Tue, 28 Feb 2006 15:31:47 -0800
>> >Lines: 8
>> >Message-ID: <A8**********************************@microsoft.co m>
>> >MIME-Version: 1.0
>> >Content-Type: text/plain;
>> > charset="Utf-8"
>> >Content-Transfer-Encoding: 7bit
>> >X-Newsreader: Microsoft CDO for Windows 2000
>> >Content-Class: urn:content-classes:message
>> >Importance: normal
>> >Priority: normal
>> >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
>> >Newsgroups: microsoft.public.dotnet.general
>> >Path: TK2MSFTNGXA03.phx.gbl
>> >Xref: TK2MSFTNGXA03.phx.gbl microsoft.public.dotnet.general:189842
>> >NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
>> >X-Tomcat-NG: microsoft.public.dotnet.general
>> >
>> >I have an application in managed C++, and a method in C# that I call. But
>> now
>> >I want to add the ability to tell the C# method a specific method in
my >> C++
>> >assembly to call back to. For example, to have the C++ call a sort

routine
>> in
>> >C#, and send it a compare method, which the C## would call back to. I know
>> >that within C# pointing to methods is done with delegates, but is it
>> possible
>> >between C++ and C#? Is there an example of this somewhere that

anyone >> knows
>> >of? Thanks for any help you can provide.
>> >
>> >
>>
>>
>



Mar 8 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.