我正在尝试添加对在ASP.Net MVC 5应用程序中使用C ++构建的DLL的引用。我想从应用程序中调用DLL中的函数。
是的,可以。这里的关键是“平台调用”。
此示例摘自Microsoft documentation:
using System;
using System.Runtime.InteropServices;
public class Win32 {
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr MessageBox(int hWnd, String text,
String caption, uint type);
}
public class HelloWorld {
public static void Main() {
Win32.MessageBox(0, "Hello World", "Platform Invoke Sample", 0);
}
}