0

I understand PBYTE is unsigned char* from Windows Data Types.

I want to be able to print all the contents, either using printf() or cout:

PBYTE buffer;
ULONG buffersize = NULL;
serializeData(data, buffer, buffersize); 
//this function serializes "data" and stores the data in buffer and updates bufferSize).. 

Can you help me understand how to print this in C++?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
ccoding
  • 1
  • 2
  • 8

1 Answers1

4

If you want to print the memory address that buffer is pointing at, then you can do it like this:

PBYTE buffer;
ULONG buffersize = 0;
serializeData(data, buffer, buffersize); 
//this function serializes "data" and stores the data in buffer and updates bufferSize)...

printf("%p", buffer);
or
std::cout << (void*)buffer;

...

But, if you want to print the contents of the buffer, you need to loop through the buffer and print out each BYTE individually, eg:

PBYTE buffer;
ULONG buffersize = 0;
serializeData(data, buffer, buffersize); 
//this function serializes "data" and stores the data in buffer and updates bufferSize)...

for (DWORD i = 0; i < buffersize; ++i)
{
    printf("%02x ", buffer[i]);
    or
    std::cout << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)buffer[i] << " ";
}

...
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770