Article View: borland.public.cppbuilder.nativeapi
Article #2014Re: GetUserName(....) problem
From: Alan Bellingham
Date: Thu, 10 May 2007 13:07
Date: Thu, 10 May 2007 13:07
33 lines
1905 bytes
1905 bytes
"patrickartaud" <patrickartaud@aidedecision.com> wrote:
>Hello,
>I would change my application for Vista and I got a problem to fin the
>username.Using this function my code is :
>LPSTR utilisateur;
>LPDWORD taille;
>GetUserName(utilisateur,taille);
>When I insspec the user name I obtain anything else that the user
>name.Something strange in the pointer.
>Must I do something else
Yes.
You have done no initialisation whatsoever in that code, just used
random values and handed them to a function. I'm surprised it isn't
crashing.
Something more like
char utilisateur[200] = { 0 };
DWORD taille = sizeof(utilisateur)/sizeof(utilisateur[0]);
if (GetUserName(&utilisateur[0], &taille) != 0)
{
...
}
(though I'd personally use vectors, using a two stage process to firstly
get the size, secondly get the content into a resized vector).
Alan Bellingham
--
ACCU Conference 2008: 2-5 April 2008 - Oxford (probably), UK
Technical Details
Message-ID:
<62664395r3827nh4kgs2eq3qbprgh3uni7@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4643141c$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,bbdeb6775df07400 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: Alan Bellingham <alan@lspace.org> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: GetUserName(....) problem Date: Thu, 10 May 2007 14:07:59 +0100 Organization: Private Reply-To: alan@lspace.org Message-ID: <62664395r3827nh4kgs2eq3qbprgh3uni7@4ax.com> References: <4643141c$1@newsgroups.borland.com> X-Newsreader: Forte Agent 4.2/32.1118 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 193.129.251.253 X-Trace: newsgroups.borland.com 1178802478 193.129.251.253 (10 May 2007 06:07:58 -0700) Lines: 33 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail