c# 调用c++的dll有关问题
c# 调用c++的dll问题
有delphi调用的例子 可以正常运行:
TDeviceParam = packed record
devType: Integer;
Speed: Integer;
COMPort: Integer;
FlowCon: Integer;
locPort: Integer;
rmtPort: Integer;
memory: Pointer;
src_ident: Word;
src_udp_port: Word;
src_host: array [0..27] of Char;
Size: Integer;
Notify: Integer;
Window: Integer;
Message: Integer;
Handle: Integer;
End;
PDeviceParam = ^TDeviceParam;
function LED_Open(param: PDeviceParam; Notify, Window, Message: Integer): Integer; stdcall; external Sender; ----解释sender是dll
c# 这个是我写的
[StructLayout(LayoutKind.Sequential)]
public struct TDeviceParam
{
public int devType;
public int Speed;
public int COMPort;
public int FlowCon;
public int locPort;
public int rmtPort;
public int memory;
public uint src_ident;
public uint src_udp_port;//: Word;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 28)]
public char[] src_host;// array [0..27] of Char;
public int Size;
public int Notify;//: Integer;
public int Window;//: Integer;
public int Message;//: Integer;
public int Handle;//: Integer;
};
[DllImport("sender.dll")]
public static extern int LED_Open(IntPtr param, int Notify, int Window, int Message);
调用:
TDeviceParam ADevice= new TDeviceParam()
IntPtr intptr = Marshal.AllocHGlobal(Marshal.SizeOf( ADevice));
Marshal.StructureToPtr(ADevice, intptr, true);
Marshal.FreeHGlobal(intptr);
LED_Open( intptr, LedApi.NOTIFY_EVENT, (int)this.Handle, LedApi.WM_LED_NOTIFY);
错误:
无法加载 DLL xxx: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。
------解决方案--------------------
sender.dll放哪里了?
可以放到System32中,可以放到当前路径中。
------解决方案--------------------
把这个dll拷贝到你exe生成的那个目录下
有delphi调用的例子 可以正常运行:
TDeviceParam = packed record
devType: Integer;
Speed: Integer;
COMPort: Integer;
FlowCon: Integer;
locPort: Integer;
rmtPort: Integer;
memory: Pointer;
src_ident: Word;
src_udp_port: Word;
src_host: array [0..27] of Char;
Size: Integer;
Notify: Integer;
Window: Integer;
Message: Integer;
Handle: Integer;
End;
PDeviceParam = ^TDeviceParam;
function LED_Open(param: PDeviceParam; Notify, Window, Message: Integer): Integer; stdcall; external Sender; ----解释sender是dll
c# 这个是我写的
[StructLayout(LayoutKind.Sequential)]
public struct TDeviceParam
{
public int devType;
public int Speed;
public int COMPort;
public int FlowCon;
public int locPort;
public int rmtPort;
public int memory;
public uint src_ident;
public uint src_udp_port;//: Word;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 28)]
public char[] src_host;// array [0..27] of Char;
public int Size;
public int Notify;//: Integer;
public int Window;//: Integer;
public int Message;//: Integer;
public int Handle;//: Integer;
};
[DllImport("sender.dll")]
public static extern int LED_Open(IntPtr param, int Notify, int Window, int Message);
调用:
TDeviceParam ADevice= new TDeviceParam()
IntPtr intptr = Marshal.AllocHGlobal(Marshal.SizeOf( ADevice));
Marshal.StructureToPtr(ADevice, intptr, true);
Marshal.FreeHGlobal(intptr);
LED_Open( intptr, LedApi.NOTIFY_EVENT, (int)this.Handle, LedApi.WM_LED_NOTIFY);
错误:
无法加载 DLL xxx: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。
------解决方案--------------------
sender.dll放哪里了?
可以放到System32中,可以放到当前路径中。
------解决方案--------------------
把这个dll拷贝到你exe生成的那个目录下