471,326 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,326 software developers and data experts.

Calling C# method from C/C++ DLL

I have a simple Log method, signature : void(int,string), that I want to
be able to call from my C/C++ (unmanaged) code. Is there any reference
available to show how this may be done?

Thanks

Dec 3 '05 #1
2 1057
The only way to do this is to use COM interop.

See the article in MSDN entitled "Exposing .NET Framework Components to COM"

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Ann Huxtable" <an**********@research-labs.de> wrote in message
news:dm**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
I have a simple Log method, signature : void(int,string), that I want to be
able to call from my C/C++ (unmanaged) code. Is there any reference
available to show how this may be done?

Thanks

Dec 3 '05 #2
Ann Huxtable wrote:
I have a simple Log method, signature : void(int,string), that I want
to be able to call from my C/C++ (unmanaged) code. Is there any
reference available to show how this may be done?


As Bob says, you have to use COM interop to do this. Specifically, you
have to host the .NET runtime in the C++ application and then access the
..NET class and method through OLE Automation. If you have done any work
calling automation interfaces (IDispatch) in C++ then you will know how
tedious this is.

If it is "a simple Log method" then why not implement it in C++ in a DLL
and use this DLL in your C# code through Platform Invoke, and in your
C++ code through normal export (static) libraries?

Richard
--
http://www.grimes.demon.co.uk/workshops/fusionWS.htm
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Dec 4 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Klaus Friese | last post: by
5 posts views Thread by Dave Veeneman | last post: by
7 posts views Thread by JJ | last post: by
5 posts views Thread by Nick Flandry | last post: by
15 posts views Thread by =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post: by
7 posts views Thread by =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.