tags:

views:

38

answers:

1

Hi,

I had written a code snippet in VC++. However, I cannot continue rest of the application in VC++, so would want to move to C#.

Can I make a dll of the VC++ code and call the functions written in VC++ to work in C#?

I'm quite un-aware if this will work, but I have seen how the native code is called in C# using dll.

Can anyone please help me on this.

Thanks.

+1  A: 

You could try compiling your C++ code as managed code using the /clr option and then use it directly or use P/Invoke to call the unmanaged functions from managed code.

Darin Dimitrov
do I need to compile the unmanaged code in some specific way to be call-able as a P/Invoke from managed code? can you please give me some links? Would be grateful.
James
@Joy, yes you need to export the functions you would like to use: http://msdn.microsoft.com/en-us/library/3y1sfaz2(VS.80).aspx with `__declspec(dllexport)`. To avoid name mangling make sure you use `extern "C"` as well: http://www.flipcode.com/archives/Creating_And_Using_DLLs.shtml
Darin Dimitrov
@Darin, thanks mate for the link. I found this link, it might be worth looking at too, http://goo.gl/EIth
James
@Joy, yes it's a nice and very useful tutorial you have found.
Darin Dimitrov