[英]Import C++ DLL Pointers-to-functions to C#
I am working on import C++ DLL Pointers-to-functions to C#.我正在导入 C++ DLL 指向 C# 的函数指针。
My Code 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);
};
My code C#:我的代码 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???
I can import init function but can you help me to import Device_setPassword and Device_getDLLVersion functions?我可以导入 init function 但你能帮我导入 Device_setPassword 和 Device_getDLLVersion 函数吗?
I solved my question.我解决了我的问题。 It might help others.它可能会帮助其他人。 Solution:解决方案:
[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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.