 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
patrickartaud Guest
|
Posted: Thu May 10, 2007 5:45 pm Post subject: GetUserName(....) problem |
|
|
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
|
Posted: Thu May 10, 2007 6:07 pm Post subject: Re: GetUserName(....) problem |
|
|
"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
|
Posted: Fri May 11, 2007 8:10 am Post subject: Re: GetUserName(....) problem |
|
|
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 |
|
 |
|
|
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
|
|