D
dvanderboom
How would I pass a structure like this by reference through an interop
call? I keep getting a NotSupportedException on the call that takes a
pointer to this structure as a parameter. The DLL I'm calling was
created by someone else in C++ and it's not a COM object.
The C++ definitions:
typedef struct {
int nPortIndex;
int nPortNumber;
TCHAR tszDeviceName[8];
DWORD dwMagic
DWORD dwReserved[5];
} RFID_FINDINFO;
DWORD WINAPI RFID_FindNext(
HANDLE hReader,
RFID_FINDINFO *lptRFIDFindInfo,
HANDLE hFind);
This is what I tried:
[StructLayout(LayoutKind.Sequential)]
public struct RFID_FINDINFO {
public int nPortIndex;
public int nPortNumber;
public StringBuilder tszDeviceName;
public UInt32 dwMagic;
public UInt32[] dwReserved;
};
[DllImport("RFIDAPI32.dll", EntryPoint="#149")]
public static extern uint FindFirst(
IntPtr hReader,
ref RFID_FINDINFO ptRFIDFindInfo,
ref IntPtr phFind);
Then when I called it, I did this to set up the struct:
RFID_FINDINFO fi = new RFID_FINDINFO();
fi.tszDeviceName = new StringBuilder("");
fi.tszDeviceName.Capacity = 8;
fi.dwReserved = new UInt32[5];
// This is the line it errors out on.
result = FindFirst(ReaderHandle, ref fi, ref FindHandle);
What am I doing wrong?
call? I keep getting a NotSupportedException on the call that takes a
pointer to this structure as a parameter. The DLL I'm calling was
created by someone else in C++ and it's not a COM object.
The C++ definitions:
typedef struct {
int nPortIndex;
int nPortNumber;
TCHAR tszDeviceName[8];
DWORD dwMagic
DWORD dwReserved[5];
} RFID_FINDINFO;
DWORD WINAPI RFID_FindNext(
HANDLE hReader,
RFID_FINDINFO *lptRFIDFindInfo,
HANDLE hFind);
This is what I tried:
[StructLayout(LayoutKind.Sequential)]
public struct RFID_FINDINFO {
public int nPortIndex;
public int nPortNumber;
public StringBuilder tszDeviceName;
public UInt32 dwMagic;
public UInt32[] dwReserved;
};
[DllImport("RFIDAPI32.dll", EntryPoint="#149")]
public static extern uint FindFirst(
IntPtr hReader,
ref RFID_FINDINFO ptRFIDFindInfo,
ref IntPtr phFind);
Then when I called it, I did this to set up the struct:
RFID_FINDINFO fi = new RFID_FINDINFO();
fi.tszDeviceName = new StringBuilder("");
fi.tszDeviceName.Capacity = 8;
fi.dwReserved = new UInt32[5];
// This is the line it errors out on.
result = FindFirst(ReaderHandle, ref fi, ref FindHandle);
What am I doing wrong?