Delegate from C++ to C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
Thank you. The second article looks perfect, I will see what I can do with it.

"TerryFei" said:
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=?=" <[email protected]>
Subject: Delegate from C++ to C#
Date: Tue, 28 Feb 2006 15:31:47 -0800
Lines: 8
Message-ID: <[email protected]>
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.
 
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=?=" <[email protected]>
References: <[email protected]>
Subject: RE: Delegate from C++ to C#
Date: Wed, 1 Mar 2006 08:04:31 -0800
Lines: 61
Message-ID: <[email protected]>
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" said:
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=?=" <[email protected]>
Subject: Delegate from C++ to C#
Date: Tue, 28 Feb 2006 15:31:47 -0800
Lines: 8
Message-ID: <[email protected]>
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.
 
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" said:
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=?=" <[email protected]>
References: <[email protected]>
Subject: RE: Delegate from C++ to C#
Date: Wed, 1 Mar 2006 08:04:31 -0800
Lines: 61
Message-ID: <[email protected]>
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" said:
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=?=" <[email protected]>
Subject: Delegate from C++ to C#
Date: Tue, 28 Feb 2006 15:31:47 -0800
Lines: 8
Message-ID: <[email protected]>
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.
 
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=?= <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: RE: Delegate from C++ to C#
Date: Tue, 7 Mar 2006 14:50:02 -0800
Lines: 113
Message-ID: <[email protected]>
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 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" said:
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=?=" <[email protected]>
References: <[email protected]>
Subject: RE: Delegate from C++ to C#
Date: Wed, 1 Mar 2006 08:04:31 -0800
Lines: 61
Message-ID: <[email protected]>
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.
:

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=?=" <[email protected]>
Subject: Delegate from C++ to C#
Date: Tue, 28 Feb 2006 15:31:47 -0800
Lines: 8
Message-ID: <[email protected]>
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.
 
Back
Top