C# 使用非托管C++;带C的lib#
我仍在尝试将C++非托管dll与C#一起使用 我的问题是: 我(从我的dll)获得了一个函数: C++: 我还有一个相同函数的VB示例:C# 使用非托管C++;带C的lib#,c#,marshalling,C#,Marshalling,我仍在尝试将C++非托管dll与C#一起使用 我的问题是: 我(从我的dll)获得了一个函数: C++: 我还有一个相同函数的VB示例: ReDim DevID(10) As Byte Dim RetStat Dim picb As PIC DevID(0) = CMD_READ_VERSION DevID(1) = 0 picb.BootAddr = &H3FFFFE picb.BootCmd = CMD_READ_PROG_MEM picb.BootDatLen = 2
ReDim DevID(10) As Byte
Dim RetStat
Dim picb As PIC
DevID(0) = CMD_READ_VERSION
DevID(1) = 0
picb.BootAddr = &H3FFFFE
picb.BootCmd = CMD_READ_PROG_MEM
picb.BootDatLen = 2
picb.MaxRetrys = PicBootS.MaxRetry
picb.BytesPerBlock = 1
picb.BytesPerAddr = 1
RetStat = ReadPIC(PicBootS.PortHandle, picb, DevID(0))
If RetStat <= 0 Then
ReadDeviceID = "0"
Else
ReadDeviceID = CStr(((DevID(1) * 256) + DevID(0)) \ 32)
End If
地雷:
public struct PIC
{
public byte BootCmd;//{ get; set; }
public byte BootDatLen ;//{ get; set; }
public ulong BootAddr ; //{ get; set; }
public byte BytesPerBlock; //{ get; set; }
public byte BytesPerAddr ; //{ get; set; }
public ushort MaxRetrys; //{ get; set; }
}
BootAddr
应该是uint
,而不是ulong
。在哪里可以为u共享a+1?thx它起作用了我没看见我很难过。。。浪费了太多时间!发布解决方案作为答案,并获得一些代表;p我已经够了。
ReDim DevID(10) As Byte
Dim RetStat
Dim picb As PIC
DevID(0) = CMD_READ_VERSION
DevID(1) = 0
picb.BootAddr = &H3FFFFE
picb.BootCmd = CMD_READ_PROG_MEM
picb.BootDatLen = 2
picb.MaxRetrys = PicBootS.MaxRetry
picb.BytesPerBlock = 1
picb.BytesPerAddr = 1
RetStat = ReadPIC(PicBootS.PortHandle, picb, DevID(0))
If RetStat <= 0 Then
ReadDeviceID = "0"
Else
ReadDeviceID = CStr(((DevID(1) * 256) + DevID(0)) \ 32)
End If
//PIC structure used for some functions
typedef struct _PIC {
BYTE BootCmd;
BYTE BootDatLen; //Number of bytes to read/write
DWORD BootAddr; //24 bit memory address (Prog or EE)
BYTE BytesPerBlock;
BYTE BytesPerAddr;
WORD MaxRetrys; //Number of retries before failure
} PIC;
public struct PIC
{
public byte BootCmd;//{ get; set; }
public byte BootDatLen ;//{ get; set; }
public ulong BootAddr ; //{ get; set; }
public byte BytesPerBlock; //{ get; set; }
public byte BytesPerAddr ; //{ get; set; }
public ushort MaxRetrys; //{ get; set; }
}