gpt4 book ai didi

c# - 在 C# 代码中导入 DLL 函数

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:55:00 27 4
gpt4 key购买 nike

我有一个 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com