I'm wondering why, when I run the following code, the value of t is the same after the call to get as it was before.
I have a feeling that the issue is the reassignment in line 11, at c = tmp - But hopefully someone can point me in the right direction?
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
BOOL get(COMPUTER_NAME_FORMAT f, WCHAR* c) {
DWORD s = 0;
WCHAR* tmp = NULL;
GetComputerNameExW(f, tmp, &s);
tmp = (WCHAR*)realloc(tmp, sizeof(WCHAR) * s);
GetComputerNameExW(f, tmp, &s);
c = tmp;
return TRUE;
}
void _tmain(int argc, _TCHAR* argv[])
{
WCHAR* t = TEXT("thisisatest");
BOOL res = get(ComputerNameDnsHostname, t);
printf("%Ls\n", t);
}
The above code have, for the sake of brevity, been stripped of error handling code. Also, I suspect there's a race condition between the 2 calls to GetComputerNameExW().