Click here to Skip to main content
15,912,493 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I recently downloaded a c/c++ algorithm, i have complete source code in c++.
I want to invoke the functions of c program in c#,

I read many articles about this, but can you tell how can I compile source into DLL in c++.

or is there any i can use the program in c#??

Prathamesh
Posted

The easiest way is to compile it to a dll. Assuming you aren't using the Express edition of VS, cerate a new project within your solution, and select "Other languages", "Visual C++", then either choose "MFC DLL" or "Class Library" depending on your original source requirements.

Once you build the DLL you should be able to invoke the functions from C#, using DllImport
 
Share this answer
 
Comments
Richard MacCutchan 2-Feb-12 4:57am    
You can create DLLs with Visual C++ Express, although not MFC.
OriginalGriff 2-Feb-12 5:13am    
You can, but you have to have the C++ Express version not just the C# one he may have - only reason I mentioned it.
Doing it in the Express version is probably as simple, but it can't be a part of the C# solution - it has be be separate. Since I don't have the express versions, I can't guide him through that! :laugh:
Richard MacCutchan 2-Feb-12 5:26am    
You are right of course, but since OP said they had C++ source I assumed they had the C++ Express as minimum.
OriginalGriff 2-Feb-12 5:34am    
I was assuming the other way round! :laugh:
Richard MacCutchan 2-Feb-12 5:39am    
My assumption was not the assumption that you assumed. :)
For creating DLL in VS you can refer here

http://msdn.microsoft.com/en-us/library/ms235636(v=vs.80).aspx[^]

And for calling these DLL functions in C# you can use p-invoke. Check here for more info

http://msdn.microsoft.com/en-us/library/aa288468%28v=vs.71%29.aspx[^]
 
Share this answer
 
There are a lot of C# to Cpp Convertors available
try this Software Convertor
Happy Programming:-)
 
Share this answer
 
 
Share this answer
 
Write your C++ code into C++ Dll and call it in .net using DllImport Attribute. This link will help you to use it. http://msdn.microsoft.com/en-us/library/aa984739(v=vs.71).aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900