flat assembler
Message board for the users of flat assembler.

Index > Windows > [HELP] - sprintf from MSVCRT.DLL not working with floats.

Author
Thread Post new topic Reply to topic
ctl3d32



Joined: 30 Dec 2009
Posts: 204
Location: Brazil
ctl3d32
Hi, folks!

I'm trying to use sprintf from MSVCRT.DLL, but i can't get it to work with float-points. Please help me. Here is an example:

Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

section '.text' code readable executable

  start:

        invoke  GetModuleHandle,0
        mov     [h_exe],eax
        invoke  sprintf,message,fmt,[var]
        invoke  MessageBox,HWND_DESKTOP,message,caption,MB_OK
  exit:
        invoke  ExitProcess,0

section '.data' readable writable

  caption db 'MessageBox Caption!',0
  fmt db 'Variable value is: %e',0
  var dd 100.0

section '.bss' readable writeable

  h_exe dd ?
  message rb 100h

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL',\
          msvcrt,'MSVCRT.DLL'

  import kernel,\
         GetModuleHandle,'GetModuleHandleA',\
         ExitProcess,'ExitProcess'

  import user,\
         MessageBox,'MessageBoxA'

  import msvcrt,\
         sprintf,'sprintf'    


Thanks,
ctl3d32
Post 15 May 2010, 01:40
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
That function needs a double instead of simple float. A quick solution is to use win32ax.inc, use "var dq 100.0" and "invoke sprintf,message,fmt, double [var]"
Post 15 May 2010, 02:08
View user's profile Send private message Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 204
Location: Brazil
ctl3d32
LocoDelAssembly wrote:
That function needs a double instead of simple float. A quick solution is to use win32ax.inc, use "var dq 100.0" and "invoke sprintf,message,fmt, double [var]"


Thank you very much! It works perfectly now! Smile
Post 15 May 2010, 02:21
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.