BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GetUserName(....) problem

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API)
View previous topic :: View next topic  
Author Message
patrickartaud
Guest





PostPosted: Thu May 10, 2007 5:45 pm    Post subject: GetUserName(....) problem Reply with quote



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
I thank you in advance
Patrick
Back to top
Alan Bellingham
Guest





PostPosted: Thu May 10, 2007 6:07 pm    Post subject: Re: GetUserName(....) problem Reply with quote



"patrickartaud" <patrickartaud (AT) aidedecision (DOT) com> wrote:

Quote:
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
Back to top
patrickartaud
Guest





PostPosted: Fri May 11, 2007 8:10 am    Post subject: Re: GetUserName(....) problem Reply with quote



Thank you very much for your response I have done a big mistake and I thank
you again
Patrick
"Alan Bellingham" <alan (AT) lspace (DOT) org> a écrit dans le message de
news:62664395r3827nh4kgs2eq3qbprgh3uni7 (AT) 4ax (DOT) com...
Quote:
"patrickartaud" <patrickartaud (AT) aidedecision (DOT) 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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.