Because you are calling LookupAccountSidW(...), myDwordNameLength
and myDwordDomLength
will contain the buffer size needed in wide chars. Thus on lines 23 and 24 you are only allocating half the required size for each buffer.
Change those lines to:
myTrusteeName = (LPWSTR)GlobalAlloc(GMEM_FIXED, myDwordNameLength * sizeof(wchar_t));
myDomainName = (LPWSTR)GlobalAlloc(GMEM_FIXED, myDwordDomLength * sizeof(wchar_t));