mony
mony

Reputation: 51

How can I add a C++ DLL file in my .NET application?

How can I add a C++ DLL file in my .NET application?

Upvotes: 5

Views: 2777

Answers (4)

Steve Danner
Steve Danner

Reputation: 22148

If it's registered in COM, you can simply add a COM reference in Visual Studio and Visual Studio will do all the Interop creation for you.

Upvotes: 0

Roast
Roast

Reputation: 1755

Assuming you use Visual Studio, in your Solution right click "references" and choose "Add Reference". Select your dll file.

In the classes that will use the dll, add : using MyLibrarysName;

then you can call the functions in that DLL using Mylibraryname.myfunction

Upvotes: 0

dtb
dtb

Reputation: 217233

Depending on the nature of the DLL, you can

  1. Add a reference to a registered COM DLL,

  2. Call Win32 DLLs with P/Invoke, or

  3. Write a wrapper in C++/CLI.

Upvotes: 6

John Gietzen
John Gietzen

Reputation: 49534

You would use an "extern" function, marked with the DllImport attribute.

[DllImport(@“C:\mylib.dll”)]
public static extern int myFunc(int param);

Upvotes: 6

Related Questions