Haix64
Haix64

Reputation: 806

Writing unmanaged C++ DLLs for use in C#

I'm a Linux C++ developer, and I need to write C++ dlls for windows, which is to be used in C# applications.

The problem is importing the DLLs into C#, which I have no idea how to do it. In my friends' project its probable that any kind of unmanaged dll will be used, and I'm charge of doing this :-D

I need to import all objects and functions in the DLL, and my search has led me to nothing more than DllImport and so.

Thanks so much for helps.

Upvotes: 2

Views: 4079

Answers (5)

manu_dilip_shah
manu_dilip_shah

Reputation: 898

You can use C++/CLI as a wrapper for your unmanaged C++.For more info on C++/CLI and what it does you can use this link

http://www.functionx.com/cppcli

You can have a quick look at this

http://www.codeproject.com/Articles/19354/Quick-C-CLI-Learn-C-CLI-in-less-than-10-minutes#A8

Upvotes: 2

Ove
Ove

Reputation: 6317

Take a look at this tutorial. It shows two methods for accomplishing what you want: How to Marshal a C++ Class

Upvotes: 0

Ian Finlay
Ian Finlay

Reputation: 119

Have you thought to keep the Dll's in C++ (port then recompiled under VS.NET) less effort than a C# port.

I have in the past made a shared memory DLL to allow LabVIEW (Windows7) and a Winforms C#.NET appl. to share data storage via this dll.

Upvotes: 0

Brian
Brian

Reputation: 1164

There are many ways to go about this. You can write a CLR dll in C++ which puts an interface that C# can directly "talk" to. This is a nice option cause you can keep native C++ still and not have all of your code be CLR based.

Do some searches for C++/CLI

You can also use dllimport and friends and create a standard dll.

Upvotes: 0

Keith Nicholas
Keith Nicholas

Reputation: 44316

you want DllImport

There's a bunch of info here :-

http://msdn.microsoft.com/en-us/library/aa288468(v=vs.71).aspx

and lots lots more all over google, and many stackoverflow questions related to DllImport

Upvotes: 0

Related Questions