Hello all!
im having some trouble using the FpuAtoFL function with a memory var. code exmaple:

FPUtmp dt ?
kg1 dd ?
m1 dd ?
invoke GetDlgItemText,hWnd,IDC_kg1,addr kg1,12h ; eg 0.25
invoke GetDlgItemText,hWnd,IDC_m1,addr m1,12h ; eg 3
invoke FpuAtoFL,addr kg1,addr FPUtmp,DEST_MEM ; this gives FPUtmp the value 0.253!
invoke FpuAtoFL,addr m1,0,DEST_FPU ; this works nicely
fld FPUtmp
fmulp st(1),st(0) ; resulting in a wrong result here

Putting the value directly on the fpu works great but when passing it to the var..!
Posted on 2004-03-11 06:38:14 by sluggo
You must realize that the GetDlgItemText function returns a null-terminated string at the address indicated by the lpString member. If that string would be 10 bytes long, the buffer to receive it must be at least the same lenght +1 for the terminating zero.

You are using that function by passing it the address of a 4 byte buffer (i.e. kg1 dd ? and m1 dd ?). If your first string going into the kg1 variable is more than 3 bytes long, part of it will be overwritten when you place the second string into the m1 variable.

With the example you gave, the memory content after the 1st GetDlgItemText would become (in ascii except for the terminating 0 indicated by "Z"):
0 . 2 5 Z
Then your second call would place the 2nd string starting at the Z byte and give you:
0 . 2 5 3 Z
And the results you got at that point from the FpuAtoFL function were perfectly consistent.

Try your code with the following:

kg1 db 16 dup(?)
m1 db 16 dup(?)
Posted on 2004-03-11 10:41:24 by Raymond
thank you Raymond!
and thank you for not only providing a solution but explaining what i do wrong!
Posted on 2004-03-11 16:59:12 by sluggo
We all make errors while learning. My philosophy has been that if we fully understand the reason for the error, we lower the risk of repeating it. And, if we do repeat it, it becomes a lot easier to detect and correct it rapidly.

Glad to hear that my help has been appreciated.

Posted on 2004-03-11 20:02:31 by Raymond