Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Current Active User

Author
Message
Diablo 3D
21
Years of Service
User Offline
Joined: 23rd May 2005
Location:
Posted: 12th Sep 2011 18:58
I've been searching the forums on here for hours now, and can't seem to find the anwers I'm looking for.

I'm trying to find out who is currently logged onto the computer, so my game can display their name on the screen. For example, if John logs on and loads the game, he will see "Welcome John", and if Ann logs on, she will see "Welcome Ann" and so on.

Any ideas?

Thanks in advance

Self Destruction Computer Entertainment
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Sep 2011 19:26
Download and install my free plug-ins, then use the WINDOWS USERNAME$() function.

JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 12th Sep 2011 19:56
Nice one IanM.

However I am curious.. shouldn't this work just as well ? For some reason it doesn't.



For learning reasons, I would like to know what I am doing wrong here.

"Life is like a box of chocolates.. eat it before it melts."
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Sep 2011 22:58
Maybe because there's no such function called GetUserName - it's actually either GetUsernameA or GetUserNameW, depending on whether you are using multibyte or UNICODE. DBPro used multibyte, so you want the function name with an 'A' at the end.

The confusion is due to the fact that both C and C++ will translate GetUserName automatically, depending on which mode (multibyte or UNICODE) you are compiling in.

JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 13th Sep 2011 00:04
Yea that code bombs when I tried it with the A.



I tried this.. does not work. So not sure what I'm doing wrong here.

"Life is like a box of chocolates.. eat it before it melts."
Thebeely
21
Years of Service
User Offline
Joined: 4th May 2005
Location: Croatia
Posted: 13th Sep 2011 00:55
Maybe it returns a pointer?
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Sep 2011 01:12
No, and I should have spotted the problem immediately - it requires a pointer to some memory to dump the name into.

Here's the way I'd do it:


Others would muck around with memblocks and convert the memblock into string data byte-by-byte - however, since DBPro passes strings around as pointers anyway, we can simply pass the string (it's pointer actually) directly into the function call.

JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 13th Sep 2011 04:48
I am soo going to have to buy the DarkBasic Books. Another Hundred bucks to sink into. :/

I never would have seen the idea of using the Space$ or make memory() functions. Those are not something that just "hits" ya in the face when you look in the help file.

Thanks for the info. And yea it works great this time.

"Life is like a box of chocolates.. eat it before it melts."
Diablo 3D
21
Years of Service
User Offline
Joined: 23rd May 2005
Location:
Posted: 13th Sep 2011 10:14
Thank you IanM, this is fantastic!

Self Destruction Computer Entertainment
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Sep 2011 16:16
Quote: "I am soo going to have to buy the DarkBasic Books"

Is that kind of thing covered in the books? I'd be very surprised if it was.

JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 13th Sep 2011 19:07
I'm not sure if it is. Its why I was going to get the books to see what other commands are not obvious. If its worth it that is.

"Life is like a box of chocolates.. eat it before it melts."
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 13th Sep 2011 19:31
I'd say the help files would be more up to date and more accurate than the contents of the books...

Warning! May contain Nuts!
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 13th Sep 2011 19:39
Quote: "I'd say the help files would be more up to date and more accurate than the contents of the books..."


Yea, I am seeing that. The date is old compared to the current help files. Would be nice to have copies of updated books.

"Life is like a box of chocolates.. eat it before it melts."

Login to post a reply

Server time is: 2026-07-10 23:33:43
Your offset time is: 2026-07-10 23:33:43