News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

API Return values to string?

Started by Cyrus, November 12, 2007, 02:38:08 AM

Previous topic - Next topic

Cyrus

Well Im still getting deeper into asm, and the fundamentals. I want to say before I ask my question, thank you all for providing help to my kind that aren't experienced without flaming us up one side and down the other. I appreciate it.

The following command:

invoke SendDlgItemMessage,hWin,List1,LB_GETCOUNT,0,0

will, upon success return the count of items in the listbox to eax. That part I've confirmed through olly and is working. It does however store it in eax with the hex value of course.

What I want to do is be able to use this somehow as a string. For now, I am trying to simply set the dialog's caption to the listcount.

Of course invoke SetWindowText,hWin,eax doesnt work. So how can I use the literal values in eax returned by api's in string format to do this? And wont I need to convert it back to decimal first?

Thanks guys for any help.

Mark Jones

Hi Cyrus, yes there are many ways in which to do this. The easiest may be to study the \help\masmlib.hlp file, look under "Conversions" as well as "Hex to Binary Conversions."  :U
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Cyrus

Awesome man thank you. Several help files and I missed that! Looks like htodw will help with the conversion.

Now what I still need to know is how do I convert the literal value of eax?

After I do this:

invoke SendDlgItemMessage,hWin,List1,LB_GETCOUNT,0,0

Eax is 4CA hex which we know to be 1226 in decimal. Now how do i use this? I attempted invoke htodw,eax and disaster.

Literally I want to take the 4CA from EAX, convert it to DEC and then be able to use it as a string in invoke SetWindowText,hWin,variable.here

Thank you

TNick

You have to convert it to a string. You may use dwtoa to convert the number to a decimal string like this:

.DATA
stringbuffer  BYTE 24 dup (0)
.CODE
invoke SendDlgItemMessage,hWin,List1,LB_GETCOUNT,0,0
invoke dwtoa,eax,ADDR stringbuffer

at this point, stringbuffer will hold the decimal representation of numbers of items in your list box. If you want hexadecimal representation replace dwtoa with dw2hex.

Nick

Cyrus


jj2007

Quote from: Cyrus on November 12, 2007, 02:38:08 AM
It does however store it in eax with the hex value of course.
Cyrus, Olly displays the value of eax as hex, but eax remains what it is: a 32-bit register aka "dword". Therefore, the appropriate routine is dwtoa. Here are some lines for testing it.

    .data
AppName db 'Test the dwtoa',0
NumBuf db "Wow, a number: "  ; ** NO 0 byte here! **
dwtoaBuf db "This is a buffer for dwtoa",0

.code
...
mov eax, 123456
invoke dwtoa,eax,ADDR dwtoaBuf
invoke MessageBox,NULL,addr NumBuf,addr AppName,MB_OK

Cyrus