简体   繁体   中英

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

如何在.NET应用程序中添加C ++ DLL文件?

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 .

如果它在COM中注册,您只需在Visual Studio中添加COM引用,Visual Studio将为您创建所有Interop

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM