why not using the unsafe
example
Code
- [DllImport("coredll.dll", EntryPoint="DeviceIoControl", SetLastError = true)]
- private unsafe static extern bool _unsafe_DeviceIoControl(
- Int32 *hDevice,
- UInt32 dwIoControlCode,
- void *lpInBuffer,
- UInt32 nInBufferSize,
- void *lpOutBuffer,
- UInt32 nOutBufferSize,
- UInt32 *lpBytesReturned,
- Int32 *lpOverlapped);
- public unsafe static bool _unsafe_sendCanMessage(
- Int32 *hDevice,
- tagCAN_TRANSMIT_DATA *transmit,
- UInt32 *dw)
- {
- return (_unsafe_DeviceIoControl(
- hDevice,
- IOCTL_CAN_WRITE_TRANSMIT_DATA,
- transmit,
- (uint)Marshal.SizeOf(typeof(tagCAN_TRANSMIT_DATA)),
- null,
- 0,
- dw,
- null));
- }