我有一个 DLL,我想在我的 C# 代码中使用它的函数 以下是该 DLL 的功能:
extern "C"
{
__declspec(dllimport)
const char* __stdcall ZAJsonRequestA(const char *szReq);
__declspec(dllimport)
const wchar_t* __stdcall ZAJsonRequestW(const wchar_t *szReq);
__declspec(dllimport)
const BSTR __stdcall ZAJsonRequestBSTR(BSTR sReq);
}
谁能告诉我如何在 c# 项目中使用它,因为这个 dll 似乎是用其他语言编写的?
最佳答案
请看下面article在代码项目上进行深入解释
链接文章中的一个小示例如下所示
要调用函数,说methodName
int __declspec(dllexport) methodName(int b)
{
return b;
}
在c#中包含包含上述方法的类库(MethodNameLibrary.dll),如下所示
class Program
{
[DllImport(@"c:\MethodNameLibrary.dll")]
private static extern int methodName(int b);
static void Main(string[] args)
{
Console.WriteLine(methodName(3));
}
}
关于c# - 在 C# 代码中导入 DLL 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15895112/