473,498 Members | 310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ code called from C#

I have some legacy code I would like to wrap by some new managed C++
classes, put them all into a DLL and then call the managed classes from a C#
app.

Can anyone recommend me a link with some info about this?

Also, can I statically link my DLL to my C# application or I have to ship
the Managed C++ DLL with the C# exe appllication?

Thanks!

Nov 16 '05 #1
6 4289
"Daniel P." <da******@hotmail.comU> wrote in message
news:Os**************@TK2MSFTNGP09.phx.gbl...
I have some legacy code I would like to wrap by some new managed C++
classes, put them all into a DLL and then call the managed classes from a C# app.
The second part of your question is a gimme. Once you have an MC++ object,
any .Net code in any CLS compliant language can make use of it. Now it is
true that some languages don't support all of the types supported by MC++
(unsigned's as I recall) that is often little more than a nit.
Can anyone recommend me a link with some info about this?
As to the first part of your question you can use "IJW" or it just works so
that a managed C++ member function can call an unmanged C++ function. The
MC++ compiler writes the code to hop the fence between the two environments.

For tips on interoperability take a look at this:

http://msdn.microsoft.com/library/de...part2start.asp

and this

http://msdn.microsoft.com/library/de...part2start.asp

I like the treatment of interoperability in the book "Essential Guide to
Managed Extensions for C++" (Apress) by Challa and Laksberg of the VC team.
Also, can I statically link my DLL to my C# application or I have to ship
the Managed C++ DLL with the C# exe appllication?


Well, if you want to call into a DLL, you'll have to ship it. :-) As to the
linking mechanism used by C# sorry but I don't know what your options are.
That'll probably be answered in the C# group.

Regards,
Will
Nov 16 '05 #2
"William DePalo [MVP VC++]" <wi***********@mvps.org> wrote in
news:Op**************@TK2MSFTNGP12.phx.gbl:
Also, can I statically link my DLL to my C# application or I have to
ship the Managed C++ DLL with the C# exe appllication?


Well, if you want to call into a DLL, you'll have to ship it. :-) As
to the linking mechanism used by C# sorry but I don't know what your
options are. That'll probably be answered in the C# group.


Using VS2002/2003, you'll need to ship two physical files. The tools do
not expose a way to link them into one image.

In VS2005, you'll be able to compile your code as .netmodules and link
them into a single-file assembly.

Thanks,
--
Tarek Madkour, Visual C++ Team
This posting is provided "AS IS" with no warranties, and confers
no rights.
Nov 16 '05 #3
Tarek,

IMO the linker (link.exe) refuses to merge pure .netmodules (C#, VB, C++
/clr:safe or /clr:pure) and .netmodules containing native code (C++
/clr)into a single assembly .
So in the case you wrap native code with managed code, you will always need
the separate mixed code assembly, or am I missing something?

Willy.

"Tarek Madkour [MSFT]" <ta****@online.microsoft.com> wrote in message
news:Xn*****************************@207.46.248.16 ...
"William DePalo [MVP VC++]" <wi***********@mvps.org> wrote in
news:Op**************@TK2MSFTNGP12.phx.gbl:
Also, can I statically link my DLL to my C# application or I have to
ship the Managed C++ DLL with the C# exe appllication?


Well, if you want to call into a DLL, you'll have to ship it. :-) As
to the linking mechanism used by C# sorry but I don't know what your
options are. That'll probably be answered in the C# group.


Using VS2002/2003, you'll need to ship two physical files. The tools do
not expose a way to link them into one image.

In VS2005, you'll be able to compile your code as .netmodules and link
them into a single-file assembly.

Thanks,
--
Tarek Madkour, Visual C++ Team
This posting is provided "AS IS" with no warranties, and confers
no rights.

Nov 16 '05 #4
Willy Denoyette [MVP] wrote:
IMO the linker (link.exe) refuses to merge pure .netmodules (C#, VB, C++
/clr:safe or /clr:pure) and .netmodules containing native code (C++
/clr)into a single assembly .
So in the case you wrap native code with managed code, you will always
need the separate mixed code assembly, or am I missing something?


If it comes from another language, you'll pass a .netmodule to the linker.
If it comes from C++, you're almost always better off passing object files
rather than .netmodule files to the linker.

Remember that object files can have metadata too, so other compilers can
reference them.

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.
Nov 16 '05 #5
Brandon,

Thanks for the prompt reply.

I just tried to link a C# netmodule and a mixed mode .netmodule (C++
14.00.40603) and this is what the linker say's...
fatal error LNK1302: unable to link .netmodule containing native code
So it looks like we should never use mixed mode .netmodules (using C++) to
be passed to the linker, but instead link the .obj files.

Willy.

"Brandon Bray [MSFT]" <br******@online.microsoft.com> wrote in message
news:ex**************@TK2MSFTNGP09.phx.gbl... Willy Denoyette [MVP] wrote:
IMO the linker (link.exe) refuses to merge pure .netmodules (C#, VB, C++
/clr:safe or /clr:pure) and .netmodules containing native code (C++
/clr)into a single assembly .
So in the case you wrap native code with managed code, you will always
need the separate mixed code assembly, or am I missing something?


If it comes from another language, you'll pass a .netmodule to the linker.
If it comes from C++, you're almost always better off passing object files
rather than .netmodule files to the linker.

Remember that object files can have metadata too, so other compilers can
reference them.

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.

Nov 16 '05 #6
That is correct.

Ronald Laeremans
Visual C++ team

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
Brandon,

Thanks for the prompt reply.

I just tried to link a C# netmodule and a mixed mode .netmodule (C++
14.00.40603) and this is what the linker say's...
fatal error LNK1302: unable to link .netmodule containing native code


So it looks like we should never use mixed mode .netmodules (using C++) to
be passed to the linker, but instead link the .obj files.

Willy.

"Brandon Bray [MSFT]" <br******@online.microsoft.com> wrote in message
news:ex**************@TK2MSFTNGP09.phx.gbl...
Willy Denoyette [MVP] wrote:
IMO the linker (link.exe) refuses to merge pure .netmodules (C#, VB, C++
/clr:safe or /clr:pure) and .netmodules containing native code (C++
/clr)into a single assembly .
So in the case you wrap native code with managed code, you will always
need the separate mixed code assembly, or am I missing something?


If it comes from another language, you'll pass a .netmodule to the
linker.
If it comes from C++, you're almost always better off passing object
files
rather than .netmodule files to the linker.

Remember that object files can have metadata too, so other compilers can
reference them.

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.


Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1905
by: Silver | last post by:
Hi everyone, I'm writing a program that has to do them following main() : ------- 3 objects are declared (two of type A and one of type B) The function frd_fun is called for two objects (B...
6
2004
by: Dave | last post by:
Hello all, Consider this function template definition: template<typename T> void foo(T) {} If foo is never called, this template will never be instantiated. Now consider this explicit...
12
2453
by: Paul | last post by:
Hi, Global operator new and delete are overloaded and I am using stl map to store pointers, but this code crashes, can some one shed some light??? Compiler: MS VC++ 6.0 STL: Shipped with...
10
1373
by: Julia | last post by:
Hi Please can someone explain this behaviour: I have a MustInherit Base class and a Derived class that Inherits Base and Shadows a method in the base class. If I Dim a variable of type...
1
4128
by: Little | last post by:
Could someone help me figure out how to put my project together. I can't get my mind wrapped around the creation of the 4 double Linked Lists. Thank your for your insight. 1. Create 4 double...
6
2327
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
4
4674
by: Danny Liberty | last post by:
Hi, I would like to be able to execute code when a function exits. In c++ I would have created an object on the stack in the function entry point and it's destructor would be called when the...
232
13062
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
17
4672
by: radhikams | last post by:
Hi I want to create a drag drop tool box using javascript... Can anyone please guide me in this regard Thanks
0
1809
by: Formula | last post by:
Hello everybody,because I am newbie in python two weeks only but I had programming in another languages but the python take my heart there's 3 kind of arrays Wow now I hate JAVA :) . I am working...
0
6998
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5460
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4586
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.