【发布时间】:2020-04-15 03:36:51
【问题描述】:
我正在尝试在 ASP.Net MVC 5 应用程序中添加对使用 C++ 构建的 DLL 的引用。 我想从应用程序调用 DLL 中的函数。
【问题讨论】:
标签: c++ asp.net-mvc dll dllimport
我正在尝试在 ASP.Net MVC 5 应用程序中添加对使用 C++ 构建的 DLL 的引用。 我想从应用程序调用 DLL 中的函数。
【问题讨论】:
标签: c++ asp.net-mvc dll dllimport
是的,你可以。这里的关键是“平台调用”。
此示例取自 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);
}
}
【讨论】: