Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages
Started by patrickartaud
Thu, 10 May 2007 12:45
GetUserName(....) problem
Author: patrickartaud
Date: Thu, 10 May 2007 12:45
Date: Thu, 10 May 2007 12:45
11 lines
1274 bytes
1274 bytes
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
Re: GetUserName(....) problem
Author: 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
Re: GetUserName(....) problem
Author: patrickartaud
Date: Fri, 11 May 2007 06:25
Date: Fri, 11 May 2007 06:25
38 lines
2287 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads