469,283 Members | 2,263 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,283 developers. It's quick & easy.

How to Call .NET C# DLL methods from unmanaged C++?

Well - from my initial research, this doesn't seem to be an easy solution if
it is doable at all.

I have .NET 2.0 C# Classes compiled into DLLs.

I also have older unmanaged (non-.NET) C++ code which I would like to have
use the code in those C# DLLs.

Anyone have a step-by-step simple example for doing such?

Thanks,
Jeff
Aug 20 '07 #1
5 10841

"Jeff" <Je**@discussions.microsoft.comwrote in message
news:9B**********************************@microsof t.com...
Well - from my initial research, this doesn't seem to be an easy solution
if
it is doable at all.

I have .NET 2.0 C# Classes compiled into DLLs.

I also have older unmanaged (non-.NET) C++ code which I would like to have
use the code in those C# DLLs.

Anyone have a step-by-step simple example for doing such?
Use the C++/CLI compiler, which turns any sort of C++ code into a .NET
application, and lets C++ make calls into other .NET languages.

For an example, choose New Project Visual C++ CLR CLR Console
Application (or Windows Forms Application).
>
Thanks,
Jeff

Aug 20 '07 #2
Thanks Ben. However, compiling the existing C++ unmanaged code using /CLI is
not an option.

We need to have a native C++ program using methods from a C# .NET DLL. Is
that possible?

Thanks,
Jeff
Aug 20 '07 #3
Jeff wrote:
Thanks Ben. However, compiling the existing C++ unmanaged code using /CLI is
not an option.

We need to have a native C++ program using methods from a C# .NET DLL. Is
that possible?
Make the .NET DLL a COM DLL and call that from your native C++ code.

Not easy. But possible.

Arne
Aug 21 '07 #4
Jeff wrote:
Thanks Ben. However, compiling the existing C++ unmanaged code using /CLI is
not an option.

We need to have a native C++ program using methods from a C# .NET DLL. Is
that possible?

Thanks,
Jeff
Try using IJW (It Just works). I figured out how to do it from the
following link.
http://www.codeproject.com/managedcpp/ijw_unmanaged.asp
It just works like magic.

Hope this helps
Leon Lambert

Aug 21 '07 #5

"Jeff" <Je**@discussions.microsoft.comwrote in message
news:08**********************************@microsof t.com...
Thanks Ben. However, compiling the existing C++ unmanaged code using /CLI
is
not an option.
Why? What is your requirement that is not met by linking with /clr?
>
We need to have a native C++ program using methods from a C# .NET DLL. Is
that possible?
Knowing why you are required to have a "native" program will answer whether
C# can be used in that scenario.

Loading the .NET runtime into a native application to call C# is not (in any
meaningful way) so different from linking with /clr and having some native
and some managed parts.

In either case you have a dependency on having .NET installed, extra memory
used by .NET, and the possibility of the GC suspending any thread that does
not run purely native code (and the possibility to have purely native
threads the GC doesn't care about).
Aug 22 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by sunil s via DotNetMonster.com | last post: by
4 posts views Thread by Peter Kirk | last post: by
reply views Thread by =?Utf-8?B?Y2hlbG9tYW4=?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.