πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #2023

Re: GetUserName(....) problem

#2023
From: patrickartaud
Date: Fri, 11 May 2007 06:25
38 lines
2287 bytes
Thank you very much for your response I have done a big mistake and I thank 
you again
Patrick
"Alan Bellingham" <alan@lspace.org> a οΏ½crit dans le message de 
news:62664395r3827nh4kgs2eq3qbprgh3uni7@4ax.com...
> "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: <46440c5f@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <4643141c$1@newsgroups.borland.com> <62664395r3827nh4kgs2eq3qbprgh3uni7@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,bbdeb6775df07400
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII
From: "patrickartaud" <patrickartaud@aidedecision.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4643141c$1@newsgroups.borland.com> <62664395r3827nh4kgs2eq3qbprgh3uni7@4ax.com>
In-Reply-To: <62664395r3827nh4kgs2eq3qbprgh3uni7@4ax.com>
Subject: Re: GetUserName(....) problem
Date: Fri, 11 May 2007 08:25:04 +0200
Lines: 39
MIME-Version: 1.0
Content-Type: text/plain;
 format=flowed;
 charset="iso-8859-1";
 reply-type=original
Content-Transfer-Encoding: 8bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Windows Mail 6.0.6000.16386
X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6000.16386
NNTP-Posting-Host: 82.228.58.174
Message-ID: <46440c5f@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1178864735 82.228.58.174 (10 May 2007 23:25:35 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail