473,770 Members | 1,902 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 4297
"Daniel P." <da******@hotma il.comU> wrote in message
news:Os******** ******@TK2MSFTN GP09.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 interoperabilit y 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 interoperabilit y 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******** ******@TK2MSFTN GP12.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.2 48.16...
"William DePalo [MVP VC++]" <wi***********@ mvps.org> wrote in
news:Op******** ******@TK2MSFTN GP12.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******@onlin e.microsoft.com > wrote in message
news:ex******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP09.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******@onlin e.microsoft.com > wrote in message
news:ex******** ******@TK2MSFTN GP09.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
1921
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 and one of A). C frd_fun(A a, B b)
6
2020
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 instantiation of foo:
12
2493
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 Visual Studio. #include <malloc.h> #include <map>
10
1403
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 Derived and New it as Derived the code in the Derived class is called. However, if I Dim the variable as type Base but New it as type Derived the Base class code is called - I would expect the code in
1
4163
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 linked lists as follows: (a) A double linked list called NAMES which will contain all C like identifiers of less than 256 characters long identified in the input file F. Each identifier
6
2347
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 solution. My code can be downloaded from here: http://www.tprimke.net/konto/PyObject-problem.tar.bz2. There are some scripts for GNU/Linux system (bash to be precise). All you need to know is that there are four classes. (Of course, you may...
4
4684
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 function exits as following: void func() { MyObj obj; .....
232
13343
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 set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
17
4709
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
1834
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 now on html process. So, I found a good class for getting html tag but I don't know how to use it I wrote this code for getting the tag A hopping some help please >>> <% import urllib from sgmllib import SGMLParser
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9453
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10099
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9904
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8929
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7451
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.