Below is my code to display some text. The problem is that the computer name only displays the first time. All the other text items display fine no matter how many times i call the menu item to display these things. I am clearing out the buffer using BitRakes example and i don't think it has anything to do with it.

any help appreciated

this "IS" weird


______________________________________________________
ELSEIF uMsg==WM_COMMAND ;MENU COMMANDS
mov eax,wParam
.IF ax==IDM_GETOSINFO
invoke InvalidateRect,hWnd,addr rect,TRUE
invoke UpdateWindow,hWnd

invoke DrawText,hdc,addr OsInfoString,-1,addr rect, DT_EDITCONTROL
invoke GetComputerName, addr buffer,addr buffersize
invoke StrLen,addr buffer
invoke TextOut,hdc,XPOS,YPOS,addr buffer,eax


xor eax,eax
mov edi, offset buffer
mov ecx,100
rep stosb
Posted on 2003-01-12 19:46:02 by IwasTitan
Well i am replying to my own thread because i found the problem and it has reassured me M$ truly are the biggest OS on the planet as well as the biggest A$$.


invoke GetComputerName, addr buffer,addr buffersize

This little gem overights buffersize with a value representing the length of the computer name less the Null terminating character.

In other words you have to repeatetly adjust buffersize to the size of the buffer if you want more than 1 call to GetComputeName. Usually you only want one call but that means buffersize is a useless variable there after if not LOCAL.

Seems inefficient to me.
Posted on 2003-01-12 20:08:13 by IwasTitan
Good to see you've sorted your problem...
This little gem overights buffersize with a value representing the length of the computer name less the Null terminating character

That's normally how things are done. and since it returns the number of bytes copied you don't have to use a separate function to get the length of the returned string.
'Sides the help files clearly state the buffer size gets overwritten with the number of bytes copied.

Most string functions which i write will return the string length and pointer. In asm we have the luxury of returning values in multiple registers if needed...not so in HLLs... blame HLLs for this restriction OR blame assembly for giving too much freedom:tongue:
Posted on 2003-01-12 20:51:13 by MArtial_Code
from PSDK
lpBuffer
Pointer to a buffer that receives a null-terminated string containing the computer name or the cluster virtual server name. The buffer size should be large enough to contain MAX_COMPUTERNAME_LENGTH + 1 characters.
lpnSize
On input, specifies the size of the buffer, in TCHARs. On output, the number of TCHARs copied to the destination buffer, not including the terminating null character.
If the buffer is too small, the function fails and GetLastError returns ERROR_MORE_DATA. The lpnSize parameter specifies the size of the buffer required, not including the terminating null character.
the function helps you from buffer size problem. ;)
Posted on 2003-01-12 20:59:29 by arkane
Ok i get what you guys are saying but is there really any savings in it when you don't have to get the string length but have to reset the variable. Some function you have to do this and other you don't.

That makes macros more difficult to build per categorie. For instance TextOut api.

_______________________________________________________

Which would you choose to do below. Use push/pop or use the mov method that is bleeped out.

.ELSEIF uMsg==WM_COMMAND ;MENU COMMANDS
mov eax,wParam
.IF ax==IDM_GETOSINFO
invoke InvalidateRect,hWnd,addr rect,TRUE
invoke UpdateWindow,hWnd
invoke DrawText,hdc,addr OsInfoString,-1,addr rect, DT_EDITCONTROL
push buffersize
invoke GetComputerName, addr buffer,addr buffersize
invoke TextOut,hdc,XPOS,YPOS,addr buffer,buffersize
pop buffersize
;mov eax ,100
;mov buffersize,eax
Posted on 2003-01-12 22:31:42 by IwasTitan
mov buffersize, 100

if GetComputerName fails, dynamically allocate the buffer in memory == buffersize.

:grin:
Posted on 2003-01-12 23:05:53 by arkane