开发者

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

How can I add 开发者_如何学Ca C++ DLL file in my .NET application?


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

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


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜