Re: GetUserNameEx bug?

From: Drew Cooper [MSFT] (dcoop_at_online.microsoft.com)
Date: 11/04/03


Date: Tue, 4 Nov 2003 13:06:38 -0800

Ah - it turns out that this is by design. Quoth the dev:
when an Unicode string is converted to a multiple-byte string, this relation
is not necessarily true: wcslen(Unicode string)==strlen(multiple-byte
string). So we prepare for the worse, and double the size.

I'll try to get someone to doc this in the SDK.

-- 
Drew Cooper [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights.
"adam" <caradoc_google@hotmail.com> wrote in message
news:f7d56644.0311040819.5be2b2c4@posting.google.com...
> hi all!
>
> i am seeing some odd behaviour when calling GetUserNameEx.
> i am calling the function like this:
>
> ULONG bufsize = 0;
> BOOLEAN success = GetUserNameEx(NameSamCompatible, 0, &bufsize);
> if (GetLastError() == ERROR_MORE_DATA) {
>     _TCHAR* buf = new _TCHAR[bufsize];
>     success = GetUserNameEx(NameSamCompatible, buf, &bufsize);
>     if (success) {
>         _tprintf(_T("buf:%s\n"), buf);
>     }
>     delete buf;
> }
>
> my reading of the platform sdk documentation [1]
> is that after the first call to GetUserNameEx
> bufsize will be large enough to hold my name
> and include room for the terminating null.
>
> in the case of my logon, that would be a bufsize of 14.
>
> then, after the second call to GetUserNameEx
> bufsize should hold the number of characters copied
> to the buffer, not including the terminating null.
>
> so, in my case, that would be a bufsize of 13
>
> however, i am seeing the following results:
>
> on Windows 2000 Server SP3 & Windows 2000 Professional SP4:
>
>     GetUserNameExA
>         after first call bufsize = 14
>         after second call bufsize = 14
>
>     GetUserNameExW
>         after first call bufsize = 14
>         after second call bufsize = 13
>
> on Windows 2003 Server:
>
>     GetUserNameExA
>         after first call bufsize = 28
>         after second call bufsize = 13
>
>     GetUserNameExW
>         after first call bufsize = 14
>         after second call bufsize = 13
>
>
> so, is GetUserNameExA misbehaving on both win2000 & win2003?
> or have i misunderstood something?
>
>
> thanks,
> adam
>
>
> [1]
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/ba
se/getusernameex.asp>


Relevant Pages

  • GetUserNameEx bug?
    ... i am seeing some odd behaviour when calling GetUserNameEx. ... BOOLEAN success = GetUserNameEx(NameSamCompatible, 0, &bufsize); ... not including the terminating null. ...
    (microsoft.public.platformsdk.security)
  • Re: Verify a persons name?
    ... The GetUserNameEx API supposedly takes a NameDisplay parameter to return ... ByVal format As Long, ByVal Name As String, ByRef namlen As Long) As ... Dim lNamlen As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: EXE info
    ... VS_FIXEDFILEINFO, VarFileInfo, and StringFileInfo records. ... only one language. ... function GetVersionInfo(FileName, InfoName: string): string; ... var BufSize, Len: Integer; ...
    (alt.comp.lang.borland-delphi)
  • Re: How to use DbgPrompt in drivers?
    ... int DbgPrompt(PCHAR string, PCHAR buf, ULONG bufsize)) ... Windows 2k/XP/2k3 Filesystem and Driver Consulting ... DbgPrompt in any *.h files in Win DDK. ...
    (microsoft.public.development.device.drivers)
  • Re: App version information
    ... function GetVersionInfo(FileName, InfoName: string): string; ... LegalCopyright OriginalFilename ProductName ProductVersion} ... BufSize:= GetFileVersionInfoSize, BufSize); ...
    (comp.lang.pascal.delphi.misc)