在c#代码中导入DLL函数
本文关键字:DLL 函数 导入 代码 | 更新日期: 2023-09-27 18:08:05
我有一个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似乎是在其他语言?
请查看下面关于Code Project的文章以获得更深入的解释
链接文章中的一个小示例如下
调用一个函数,输入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));
}
}
使用DllImport和MarshalAs属性