WinSock:如何send()一个PByte类型?

时间:2019-04-16 02:15:11

标签: sockets delphi winsock delphi-10-seattle

首先,我想知道PByte类型是否等效于C ++中的BYTE*(字节指针)。在负面情况下,Delphi上最接近C ++ BYTE*的是什么?

好吧,假设我对PByteBYTE*(C ++)是正确的,然后根据下面的C ++代码,如何send()这种数据类型(PByte )正确使用本机WinSock?

请参阅:

C ++:

SOCKET sock;
BITMAPINFO bmpInfo;
BYTE *bytes = NULL;
BYTE *temp_bytes = NULL;
DWORD workSpaceSize, fragmntWorkSpaceSize, size;

 RtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_LZNT1, &workSpaceSize, &fragmntWorkSpaceSize);

 bytes = (BYTE *) Alloc(bmpInfo.bmiHeader.biSizeImage);
 temp_bytes = (BYTE *) Alloc(bmpInfo.bmiHeader.biSizeImage);
 BYTE *memory = (BYTE *) Alloc(workSpaceSize);

 RtlCompressBuffer(COMPRESSION_FORMAT_LZNT1, 
             bytes, 
             bmpInfo.bmiHeader.biSizeImage, 
             temp_bytes, 
             bmpInfo.bmiHeader.biSizeImage, 
             2048,
             &size,
             memory);

 free(bytes);
 free(memory);

 if(Send(sock, (char *) temp_bytes, size, 0) <= 0) return;

 free(temp_bytes);

Delphi:

var
 Sock: TSocket;
 bmpInfo: TBitMapInfo;
 bytes: PByte = nil;
 temp_bytes: PByte = nil;
 memory: PByte;
 workSpaceSize, fragmntWorkSpaceSize, Size: Cardinal;

 //...

RtlGetCompressionWorkSpaceSize(COMPRESSION_FORMAT_LZNT1, @workSpaceSize, @fragmntWorkSpaceSize);

bytes := AllocMem(bmpInfo.bmiHeader.biSizeImage);
temp_bytes := AllocMem(bmpInfo.bmiHeader.biSizeImage);
memory := AllocMem(workSpaceSize);

RtlCompressBuffer(COMPRESSION_FORMAT_LZNT1, bytes, bmpInfo.bmiHeader.biSizeImage, 
                  temp_bytes, bmpInfo.bmiHeader.biSizeImage, 2048, @Size, memory);

FreeMem(bytes);
FreeMem(memory);

if send(Sock, temp_bytes^, Size, 0) <= 0 then Exit;

FreeMem(temp_bytes);
  • ReferenceRtlGetCompressionWorkSpaceSize()RtlCompressBuffer() C ++ 中的功能。
  • ReferenceRtlGetCompressionWorkSpaceSize()RtlCompressBuffer() Delphi 中的功能。

0 个答案:

没有答案