开发者

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

开发者 https://www.devze.com 2022-12-19 18:45 出处:网络
How can I add 开发者_如何学Ca C++ DLL file in my .NET application?You would use an \"extern\" function, marked with the DllImport attribute.

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

精彩评论

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