我正在致力于将 C++ DLL 函数指针导入到 C#。
我的代码 C++:
class __declspec(dllexport) deviceImport
{
public:
deviceImport();
virtual ~deviceImport();
int __stdcall init(char* deviceName);
int __stdcall close();
int __stdcall getDLLVersion(char* value);
private:
int handle;
HINSTANCE hDLLDevice;
bool __stdcall getProcAddresses( HINSTANCE *p_hLibrary, const char* p_dllName, int p_count, ... );
int (__stdcall *Device_setPassword)(const char* value);
int (__stdcall *Device_getDLLVersion)(int p_handle, char* value);
};
我的C#代码:
[DllImport(dllLocation, CallingConvention = CallingConvention.Cdecl)]
public static extern int init([MarshalAs(UnmanagedType.LPStr)]string device);
//How to Import Device_setPassword and Device_getDLLVersion functions???
我可以导入 init 函数,但是你能帮我导入 Device_setPassword 和 Device_getDLLVersion 函数吗?
最佳答案
我解决了我的问题。它可能对其他人有帮助。解决方案:
[DllImport(dllLocation, CallingConvention = CallingConvention.StdCall)]
public static extern int Device_setPassword(string password);
[DllImport(dllLocation, CallingConvention = CallingConvention.StdCall)]
public static extern int Device_getDLLVersion(int handle, out string value);
关于c# - 将 C++ DLL 函数指针导入到 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67001163/