[英]How to get number of bytes written successfully?
我正在做一个项目,将代码从C ++转换为C#用于打印机。 我用C#中的SerialPort.Write()
替换C ++中的WriteFile()
。
C#
public void Write(
byte[] buffer,
int offset,
int count
)
C ++
BOOL WINAPI WriteFile(
_In_ HANDLE hFile,
_In_ LPCVOID lpBuffer,
_In_ DWORD nNumberOfBytesToWrite,
_Out_opt_ LPDWORD lpNumberOfBytesWritten,
_Inout_opt_ LPOVERLAPPED lpOverlapped
);
在C ++中,我可以获得用lpNumberOfBytesWritten编写的字节数。 如何在C#中做同样的事情?
在c#中我们可以使用如下的API调用,
[DllImport("kernel32.dll")]
static extern bool WriteFile(IntPtr hFile, byte [] lpBuffer,
uint nNumberOfBytesToWrite, out uint lpNumberOfBytesWritten,
[In] ref System.Threading.NativeOverlapped lpOverlapped);
有关更多信息,请参阅http://www.pinvoke.net/default.aspx/kernel32.writefile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.