AngryBear
AngryBear

Reputation: 1

unsigned char to SetWindowTextA

I trying to fetch and display the host mac id

HWND Ui_Item = GetDlgItem(Wwnd_Mess, IDC_MYMAC);
unsigned char MACData[6];
UUID uuid;

UuidCreateSequential( &uuid );          
for (int i = 2; i < 8; i++){        
    MACData[i - 2] = uuid.Data4[i];
}

char HostMAC[13] = {MACData[0], '-', MACData[1], '-', MACData[2], '-', MACData[3], '-', MACData[4], '-', MACData[5], '-', '\0'};
SetWindowTextA( Ui_Item, HostMAC);

but this looks to just be spitting out random chars? Any thoughts on what I'm missing?

Thanks

Upvotes: 0

Views: 218

Answers (1)

David Heffernan
David Heffernan

Reputation: 612854

The MAC address is just 6 bytes of data. Your code attempts to interpret each byte as though it were an ANSI encoded character. The result you get is exactly what would be expected. You need to convert each byte to a hexadecimal representation.

For example:

char HostMAC[18];
sprintf(HostMAC, "%.2X-%.2X-%.2X-%.2X-%.2X-%.2X", MACData[5], MACData[4], MACData[3], 
  MACData[2], MACData[1], MACData[0]);

I'm not sure whether or not I put the bytes in the right order, but I'm sure you know.

Upvotes: 1

Related Questions