473,387 Members | 1,669 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,387 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 16 '05 #1
3 1008
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 16 '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 16 '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 16 '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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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...

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.