473,405 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

old C++ called from C#

How can I do that?

Would it work if I added the C++ code to the current C# project/colution? Do
I have to create another assembly with a managed C++ wrapper to the old C++
code?

Thanks!
Nov 17 '05 #1
3 806
Daniel,

One way to use ur old c++ code is to compile as a dll. In c#, you can access
the functions using "DllImport".

Unsafe c# is another way to use c++ code. Refer MSDN regarding that.

--
Shak
(Houston)


"Daniel P." <da******@hotmail.comU> wrote in message
news:Oo**************@TK2MSFTNGP11.phx.gbl...
How can I do that?

Would it work if I added the C++ code to the current C# project/colution? Do I have to create another assembly with a managed C++ wrapper to the old C++ code?

Thanks!

Nov 17 '05 #2
I used a managed C++ wrapper for my old C++ code.

In your solution add a managed C++ library. Add your existing C++
source to the project and compile. Once everything compiles, add
managed C++ classes to create the API that you want your C# code to see.

After doing this you will likely get a LNK 4243 warning. Search for
this warning in your local MSDN docs or the MSDN website to find out how
to initialize the C run time library.

If you don't already know managed C++ you might want to use a Beta
version of VS 2005, or wait until it is released. From what I here the
managed C++ syntax will change in VS 2005.

Another posibility is to use the Unix way. Set up your C++ code as a
separate process. Use sockets to communicate between the program
written in C++ and the one written in C#. I was just reading "The Art
of Unix Programming" on the weekend, so havn't tried this technique yet.

Bill

Nov 17 '05 #3
Beeeeeeeeeeeeves wrote:
What NOT to do: "MANAGED C++" - it is dire!

What *to* do: create an unmanaged C++ dll and call it using PInvoke (i.e.
the DllImport statement, in namespace System.Runtime.InteropServices)


Overall that is a rather broad statement and can lead to extreme problems.
DllImport is not type safe, so using it poses far more risk than "Managed
C++". Using C++ to create a type safe wrapper that can be exposed to other
..NET languages is by far a more superior approach.

There are instances where using DllImport is preferable (perhaps when
dealing with multiple AppDomains in the VC7 or VC7.1 products), but the
statement here doesn't discuss that at all.

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

Nov 17 '05 #4

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

Similar topics

0
by: beveled edges | last post by:
I'm using the XML functions in PHP 5. The callback function I set for namespace declarations doesn't get called. Can anyone help me out? The code is: $xml = '<addressbook...
1
by: beveled edges | last post by:
I'm using the XML functions in PHP 5. The callback function I set for namespace declarations doesn't get called. Can anyone help me out? The code is: $xml = '<addressbook...
3
by: Jun | last post by:
I have following script <script> var Animal = function(name){ this.name = name; } Animal.prototype.eat = function (food) {
3
by: Richard Urwin | last post by:
I'm using C# and having problems getting the 'Parse' EventHandler of my binding object to be called. Interestingly, the 'Format' method is always called however. A code snippet: (rdDocument is a...
8
by: Invalidlastname | last post by:
Hi, We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue...
5
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits...
20
by: Charles Law | last post by:
I have an application that creates a class. The class has unmanaged resources, so must end gracefully. How can I guarantee that the unmanaged resources are freed? I have looked at IDisposable,...
35
by: Peter Oliphant | last post by:
I'm programming in VS C++.NET 2005 using cli:/pure syntax. In my code I have a class derived from Form that creates an instance of one of my custom classes via gcnew and stores the pointer in a...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
5
by: peifeng_w | last post by:
Hi, try the following code with flag=0/1/2. #include<iostream> using namespace std; #define flag 2//option:0,1,2 class C {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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
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
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
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...

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.