Re: GetUserNameEx bug?
From: Drew Cooper [MSFT] (dcoop_at_online.microsoft.com)
Date: 11/04/03
- Next message: Eric Perlin [MS]: "Re: cxertificates on smart card"
- Previous message: Drew Cooper [MSFT]: "Re: GetUserNameEx bug?"
- In reply to: adam: "GetUserNameEx bug?"
- Next in thread: adam: "Re: GetUserNameEx bug?"
- Reply: adam: "Re: GetUserNameEx bug?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
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>
- Next message: Eric Perlin [MS]: "Re: cxertificates on smart card"
- Previous message: Drew Cooper [MSFT]: "Re: GetUserNameEx bug?"
- In reply to: adam: "GetUserNameEx bug?"
- Next in thread: adam: "Re: GetUserNameEx bug?"
- Reply: adam: "Re: GetUserNameEx bug?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|