我使用 winsock 接收一个 1024 字节的缓冲区,如下所示:
var
buffer : array[0..1023] of byte;
endarray : array of byte;
hFile : THandle;
dwWritten : DWORD;
dwRead : DWORD;
begin
SetLength (endarray, 3000); //fixxed size (doesn't really matter here, cause I know the size)
hFile := CreateFileW('test.bin', GENERIC_WRITE, FILE_SHARE_WRITE, nil, CREATE_NEW, 0, 0);
SetFilePointer(hFile, 0, nil, FILE_BEGIN);
repeat
dwRead := recv(MySock, Buffer, 1024, 0);
WriteFile(hFile, buffer[0], dwRead, dwWritten, nil); // works fine!
// Add the buffer to the endarray but how?
until (dwRead = 0) or (dwRead = -1)
[...]
CloseHandle (hFile);
end;
如何自动将缓冲区添加到 endarray 以便它实际上附加到末尾?