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