.386 .model flat, stdcall option casemap:none include \masm32\include\windows.inc include \masm32\include\kernel32.inc include \masm32\include\user32.inc include \masm32\include\advapi32.inc includelib \masm32\lib\kernel32.lib includelib \masm32\lib\user32.lib includelib \masm32\lib\advapi32.lib .data MsgCaption db "User Info:",0 MsgBoxText db "The current user logged in is: %s",0 .data? UserName db 127 dup (?) Buffer dd sizeof Username .code start: invoke GetUserName, addr UserName, addr Buffer invoke wsprintf, addr Buffer, addr MsgBoxText, addr UserName invoke MessageBox, NULL,addr Buffer, addr MsgCaption, MB_OK invoke ExitProcess,NULL end start Why won't this work??? Thanks Nok.
Posted on 2001-04-03 10:24:00 by Nokturnal
nok, Username is not UserName forge
Posted on 2001-04-03 10:35:00 by forge
Because its broken? :P Seriously though, you've got a bit messed up...
invoke wsprintf, addr Buffer, addr MsgBoxText, addr UserName
You've declared Buffer as a DWORD, so you are passing the address of a DWORD, not a pointer to the output buffer as is required. You need a second buffer, and use this to output to.

.data
MsgCaption db "User Info:",0
MsgBoxText db "The current user logged in is: %s",0

.data?
UserName     db 127 dup (?)
UserNameSize dd sizeof Username
Buffer       db 256 dup (?)

.code
start:
invoke GetUserName, addr UserName, addr UserNameSize
invoke wsprintf, addr Buffer, addr MsgBoxText, addr UserName
invoke MessageBox, NULL, addr Buffer, addr MsgCaption, MB_OK
invoke ExitProcess,NULL
end start
Mirno Oops, missed Forge's Username/UserName thing :P He posted while I was writing this :D This message was edited by Mirno, on 4/3/2001 11:04:36 AM
Posted on 2001-04-03 10:38:00 by Mirno
Thanks again Forge. That was a typo. Mirno, thanks. It still doesn't work though. Try it out yourself. I can't figure out what is wrong with it. I mean it looks like it should work no problem. But all it says is "The current user logged in is:" Hmmmmm. So back to the workshop for now...
Posted on 2001-04-03 11:18:00 by Nokturnal
OK, got it... You (and then I) declared "UserNameSize" in .data? rather than .data No change to the actual code needed:

.CONST
MaxNameSize equ 256

.data
MsgCaption   db "User Info:",0
MsgBoxText   db "The current user logged in is: %s",0
UserNameSize dd MaxNameSize


.data?
UserName     db MaxNameSize dup (?)
Buffer       db 256 dup (?)
Try that! It worked for me (Win2k). Mirno
Posted on 2001-04-03 11:45:00 by Mirno
Nokturnal, You have tried to put a number in the .data? segment.... you need to put it in the .data segment, or just get rid of that line, and it's all fine :) I chopped it down to this, which works:-

.586
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\advapi32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\advapi32.lib

.data
UserName     db 127 dup (?)
UserNameSize dd 127
Buffer       db 256 dup (?)

.code
start:
	invoke GetUserName, addr UserName, addr UserNameSize
	invoke ExitProcess,NULL
end start


Umbongo
Posted on 2001-04-03 11:46:00 by umbongo