472,811 Members | 1,175 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 10999

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
1
by: sunil s via DotNetMonster.com | last post by:
Hi, I've got a native C++ app which calls a 3rd parth .NET DLL using the LoadLibrary/GetProcAddress functions. This works fine when the DLL is located in the app directory, but if I move it out...
24
by: Jazper | last post by:
hi i have this problem. i made a class deverted by CRootItem with implementation of IDisposable-Interface. i made a test-funktion to test my Dispose-Method.... but when set a breakpoint in my...
1
by: Tim Rogers | last post by:
We've currently got a C++ client/server app that uses DCOM in order to make remote calls. We want to replace DCOM with a .NET Web Service. The server piece seems clear to me. I can write it...
2
by: joye | last post by:
Hello, My question is how to use C# to call the existing libraries containing unmanaged C++ classes directly, but not use C# or managed C++ wrappers unmanaged C++ classes? Does anyone know how...
7
by: Carl | last post by:
Hello, I noticed an unexplained (for me) behaviour while wrapping unmanaged virtual methods. This is the test situation: An unmanaged class has four methods defined DoIt1 .. DoIt4. Each...
4
by: Peter Kirk | last post by:
Hi how do I call functions in a DLL written in C from C#. Eg. in Java it is necessary to use jni - is there something similar in C#? Thanks, Peter
0
by: =?Utf-8?B?Y2hlbG9tYW4=?= | last post by:
Hello, I’m trying to use an unmanaged C dll from a ASP.NET 2.0 web application using p/Invoke platform (dllImport attribute). The asp.net page instances a c# library and this loads the C dll....
9
by: blackirish | last post by:
Hi all, I want to load an unmanaged c++ exe file and then invoke methods inside it by using c#. I can load and invoke methods in .net exe files by using reflection but couldn't do that on unmanaged...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.