I am trying to write data to a serial port through P / Invoke (obviously not with the SerialPort class). Here is what I still have:
[DllImport("kernel32", SetLastError = true)] static extern IntPtr CreateFile(string filename, // file name uint desiredAccess, // read? write? uint shareMode, // sharing uint attributes, // SecurityAttributes pointer uint creationDisposition, uint flagsAndAttributes, uint templateFile); [DllImport("kernel32", SetLastError = true)] static extern bool WriteFile(IntPtr hFile, // handle to file byte[] lpBuffer, // data buffer uint nBytesToWrite, // number of bytes to write out uint nBytesWritten, // number of bytes written [In] ref NativeOverlapped overlapped);
I get _portHandle! = -1 and can call WriteFile. But after the call, he does nothing. I can wait in VS-debug mode and wait for the call to return. In addition, an exception is not thrown.
Any kernel32.dll host that can help me?
source share