这是我使用未知 dll 从字符串中写入字节数组后的下一个问题
所以我设法写了字节数组,现在我想用同一个 dll 读回它。
我尝试了以下方法:
int BufSize = 60000000; // Size of file I/O buffers.
int BufSizeM1M = BufSize - 1000000; // The max amount of data read in at any one time.
using (WinFileIO WFIO = new WinFileIO())
{
WFIO.OpenForReading(path);
WFIO.ReadBlocks(BufSizeM1M);
WFIO.Close();
WFIO.Dispose();
}
这是 WinFileIO.ReadBlocks 函数:
public int ReadBlocks(int BytesToRead)
{
// This function reads a total of BytesToRead at a time. There is a limit of 2gb per call.
int BytesReadInBlock = 0, BytesRead = 0, BlockByteSize;
byte* pBuf = (byte*)pBuffer;
// Do until there are no more bytes to read or the buffer is full.
do
{
BlockByteSize = Math.Min(BlockSize, BytesToRead - BytesRead);
if (!ReadFile(pHandle, pBuf, BlockByteSize, &BytesReadInBlock, 0))
{
Win32Exception WE = new Win32Exception();
ApplicationException AE = new ApplicationException("WinFileIO:ReadBytes - Error occurred reading a file. - "
+ WE.Message);
throw AE;
}
if (BytesReadInBlock == 0)
break;
BytesRead += BytesReadInBlock;
pBuf += BytesReadInBlock;
} while (BytesRead < BytesToRead);
return BytesRead;
}
我的问题是,如何使用该功能来读取实际文件?