flat assembler
Message board for the users of flat assembler.

Index > Windows > [The newbie (again)] : API

Author
Thread Post new topic Reply to topic
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith
It's me, again !!!

just don't get it why nothing appears ? (still learning, sorry)

PS: now i'm sure to continue learning asm with FASM Wink

Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

ID_DIALOG          = 10
ID_LABEL_DATE      = 101
ID_EDIT_DATE       = 102
ID_OK              = 103
ID_CANCEL          = 104

section '.data' data readable writeable

  hinstance        dd ?
  IsError          dd ?
  lpSystemTime     SYSTEMTIME                                   ; API struct
  buffer_format    db '%s/%s/%s',0
  output           rb 11                                        ; 11 bytes reserved (xx/xx/xxxx0)

  dday             db '22',0
  dmon             db '09',0
  dyear            db '1967',0

section '.code' code readable executable

  start:
;        invoke  SetDlgItemText,ID_DIALOG,ID_LABEL_DATE,output
        invoke  GetModuleHandle,0
        mov     [hinstance],eax
        invoke  DialogBoxParam,[hinstance],ID_DIALOG,HWND_DESKTOP,DialogProc,0
        invoke  ExitProcess,0

proc DialogProc,hwnddlg,msg,wparam,lparam
        push    ebx esi edi
        cmp     [msg],WM_INITDIALOG
        je      wminitdialog                                    ; call before dialog box is displayed
        cmp     [msg],WM_COMMAND
        je      wmcommand
        cmp     [msg],WM_CLOSE
        je      wmclose
        xor     eax,eax                                         ; eax = 0
        jmp     finish
  wminitdialog:
        invoke  GetSystemTime,lpSystemTime
        mov     eax, lpSystemTime.wDay
        mov     ebx, lpSystemTime.wMonth
        mov     edi, lpSystemTime.wYear
        invoke  wsprintf,output,buffer_format,dday,dmon,dyear   ;,eax,ebx,edi
        invoke  SetDlgItemText,ID_DIALOG,ID_LABEL_DATE,output
        mov     [IsError],eax
        jmp     processed
  wmcommand:
        cmp     [wparam],BN_CLICKED shl 16 + ID_CANCEL
        je      wmclose                                         ; goto close if click on Cancel
        cmp     [wparam],BN_CLICKED shl 16 + ID_OK
        jne     processed                                       ; <> Ok

        invoke  EndDialog,[hwnddlg],1                           ; click on OK => End
        jmp     processed
  wmclose:
        invoke  EndDialog,[hwnddlg],0
  processed:
        mov     eax,1
  finish:
        pop     edi esi ebx
        return
endp

section '.idata' import data readable writeable

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

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

  import user,\
         DialogBoxParam,'DialogBoxParamA',\
         GetDlgItemText,'GetDlgItemTextA',\
         SetDlgItemText,'SetDlgItemTextA',\
         MessageBox,'MessageBoxA',\
         wsprintf,'wsprintfA',\
         EndDialog,'EndDialog'


section '.rsrc' resource data readable

  directory RT_DIALOG,dialogs

  resource dialogs,\
           ID_DIALOG,LANG_NEUTRAL+SUBLANG_DEFAULT,datesysteme

  dialog datesysteme,"System Date by Flaith", 70, 70, 132, 80,DS_CENTER+DS_MODALFRAME+WS_POPUP+WS_VISIBLE+WS_CAPTION+WS_SYSMENU
    dialogitem 'STATIC','System date :', ID_LABEL_DATE, 11, 15, 50, 14 ,SS_LEFT + SS_CENTERIMAGE + WS_CHILD + WS_VISIBLE + WS_GROUP, 0x00000000
;    dialogitem 'EDIT'  ,'', ID_EDIT_DATE, 69, 15, 50, 14 , ES_LEFT + ES_AUTOHSCROLL + WS_CHILD + WS_VISIBLE + WS_TABSTOP
    dialogitem 'STATIC','__/__/____', ID_EDIT_DATE, 69, 15, 50, 14 ,SS_CENTER + SS_CENTERIMAGE + WS_CHILD + WS_VISIBLE + WS_GROUP, 0x00000203 ; 0x00000204

    dialogitem 'BUTTON','Ok', ID_OK, 10, 52, 50, 18, BS_PUSHBUTTON + WS_CHILD + WS_VISIBLE + WS_TABSTOP
    dialogitem 'BUTTON','Cancel', ID_CANCEL, 73, 52, 50, 18, BS_PUSHBUTTON + WS_CHILD + WS_VISIBLE + WS_TABSTOP
  enddialog
    

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.


Last edited by flaith on 06 May 2005, 13:56; edited 1 time in total
Post 05 May 2005, 23:16
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1608
Location: Ukraine
shoorick
Code:
invoke  SetDlgItemText,[hwnddlg],ID_LABEL_DATE,output     
Post 06 May 2005, 06:25
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1608
Location: Ukraine
shoorick
Code:
start: 
        invoke  SetDlgItemText,ID_DIALOG,ID_LABEL_DATE,output 
                    ^- dialog window does not exist yet
        invoke  GetModuleHandle,0     
Post 06 May 2005, 06:29
View user's profile Send private message Visit poster's website Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith
now i understand, thank you.Wink
i changed to that code

Code:
        invoke  GetSystemTime,lpSystemTime
        mov     eax, lpSystemTime.wDay
        mov     ebx, lpSystemTime.wMonth
        mov     edi, lpSystemTime.wYear
        invoke  wsprintf,output,buffer_format,eax,ebx,edi       ;dday,dmon,dyear
    


i got a strange result, maybe because i must transform eax,ebx & edi into a string format ?

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 06 May 2005, 08:04
View user's profile Send private message Visit poster's website Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
lets see your buffer_format
Post 06 May 2005, 12:32
View user's profile Send private message Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith
i already changed the format to
Code:
  buffer_format    db '%2d/%2d/%4d',0
    

the result is the adress of the variables
i tried with %p (to have the pointer) : it is the adress $0040100E (for ex)
Sad

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 06 May 2005, 16:20
View user's profile Send private message Visit poster's website Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
Should be:
Code:
        invoke  GetSystemTime,lpSystemTime
        mov     eax, [lpSystemTime.wDay]
        mov     ebx, [lpSystemTime.wMonth]
        mov     edi, [lpSystemTime.wYear]
        invoke  wsprintf,output,buffer_format,eax,ebx,edi       ;dday,dmon,dyear     

You are getting data from structure member, not this structure member address. In fasm, when you get data from address, you always put the address in brackets '[' ']'
Post 07 May 2005, 18:10
View user's profile Send private message Visit poster's website Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith
thanks, i already tried that way too but i got an error : operand sizes do not match Sad

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 07 May 2005, 18:37
View user's profile Send private message Visit poster's website Reply with quote
donkey7



Joined: 31 Jan 2005
Posts: 127
Location: Poland, Malopolska
donkey7
You must change:
Code:
        mov     eax, [lpSystemTime.wDay]
        mov     ebx, [lpSystemTime.wMonth]
        mov     edi, [lpSystemTime.wYear]
    

to:
Code:
        movzx   eax, [lpSystemTime.wDay]
        movzx   ebx, [lpSystemTime.wMonth]
        movzx   edi, [lpSystemTime.wYear]
    

because those members of SystemTime record are words.
Post 08 May 2005, 12:35
View user's profile Send private message Visit poster's website Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith
Ok, thx, now no errors in compilation, here is the source

Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

ID_DIALOG          = 10
ID_LABEL_DATE      = 101
ID_EDIT_DATE       = 102
ID_OK              = 103
ID_CANCEL          = 104

section '.data' data readable writeable

  hinstance        dd ?
  IsError          dd ?
  lpSystemTime     SYSTEMTIME                                   ; API struct
  buffer_format    db '%02d/%02d/%4d',0
  output           rb 11                                        ; 11 bytes reserved (xx/xx/xxxx0)

  dday             db '22',0
  dmon             db '09',0
  dyear            db '1967',0

section '.code' code readable executable

  start:
        invoke  GetModuleHandle,0
        mov     [hinstance],eax
        invoke  DialogBoxParam,[hinstance],ID_DIALOG,HWND_DESKTOP,DialogProc,0
        invoke  ExitProcess,0

proc DialogProc,hwnddlg,msg,wparam,lparam
        push    ebx esi edi
        cmp     [msg],WM_INITDIALOG
        je      wminitdialog                                    ; call before dialog box is displayed
        cmp     [msg],WM_COMMAND
        je      wmcommand
        cmp     [msg],WM_CLOSE
        je      wmclose
        xor     eax,eax                                         ; eax = 0
        jmp     finish
  wminitdialog:
        invoke  GetSystemTime,lpSystemTime
        movzx   eax,[lpSystemTime.wDay]
        movzx   ebx,[lpSystemTime.wMonth]
        movzx   edi,[lpSystemTime.wYear]
        invoke  wsprintf,output,buffer_format,eax,ebx,edi
        invoke  SetDlgItemText,[hwnddlg],ID_EDIT_DATE,output
        mov     [IsError],eax
        jmp     processed
  wmcommand:
        cmp     [wparam],BN_CLICKED shl 16 + ID_CANCEL
        je      wmclose                                         ; goto close if click on Cancel
        cmp     [wparam],BN_CLICKED shl 16 + ID_OK
        jne     processed                                       ; <> Ok

        invoke  EndDialog,[hwnddlg],1                           ; click on OK => End
        jmp     processed
  wmclose:
        invoke  EndDialog,[hwnddlg],0
  processed:
        mov     eax,1
  finish:
        pop     edi esi ebx
        return
endp

section '.idata' import data readable writeable

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

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

  import user,\
         DialogBoxParam,'DialogBoxParamA',\
         GetDlgItemText,'GetDlgItemTextA',\
         SetDlgItemText,'SetDlgItemTextA',\
         MessageBox,'MessageBoxA',\
         wsprintf,'wsprintfA',\
         EndDialog,'EndDialog'


section '.rsrc' resource data readable

  directory RT_DIALOG,dialogs

  resource dialogs,\
           ID_DIALOG,LANG_NEUTRAL+SUBLANG_DEFAULT,datesysteme

  dialog datesysteme,"Get System Date", 70, 70, 132, 80,DS_CENTER+DS_MODALFRAME+WS_POPUP+WS_VISIBLE+WS_CAPTION+WS_SYSMENU
    dialogitem 'STATIC','System date :', ID_LABEL_DATE, 8, 15, 50, 14 ,SS_LEFT + SS_CENTERIMAGE + WS_CHILD + WS_VISIBLE + WS_GROUP, 0x00000000
;    dialogitem 'EDIT'  ,'', ID_EDIT_DATE, 69, 15, 50, 14 , ES_LEFT + ES_AUTOHSCROLL + WS_CHILD + WS_VISIBLE + WS_TABSTOP
    dialogitem 'STATIC','__/__/____', ID_EDIT_DATE, 55, 10, 70, 24 ,SS_CENTER + SS_CENTERIMAGE + WS_CHILD + WS_VISIBLE + WS_GROUP, 0x00000204 ; 0x00000204

    dialogitem 'BUTTON','Ok', ID_OK, 10, 52, 50, 18, BS_PUSHBUTTON + WS_CHILD + WS_VISIBLE + WS_TABSTOP
    dialogitem 'BUTTON','Cancel', ID_CANCEL, 73, 52, 50, 18, BS_PUSHBUTTON + WS_CHILD + WS_VISIBLE + WS_TABSTOP
  enddialog
    


but, another pb is when i ran the prog, i got that error :
Image Sad

have you got an error when you run the program ? Thx in advance
NB: i'm under Win2K SP4-AMD Athlon 1,4Ghz 1GoRAM

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 08 May 2005, 13:20
View user's profile Send private message Visit poster's website Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith
ok, i modified, here is the last code
Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

ID_DIALOG          = 10
ID_GROUP_BOX       = 100

ID_LABEL_DATE      = 101
ID_LABEL_TIME      = 102
ID_EDIT_DATE       = 103
ID_EDIT_TIME       = 104
ID_OK              = 105
ID_CANCEL          = 106

section '.data' data readable writeable

  hinstance        dd ?
  IsError          dd ?
  lpSystemTime     SYSTEMTIME                                   ; API struct

  _format_date     db '%02d/%02d/%4d',0
  _buffer_date     rb 11                                        ; 11 bytes reserved (xx/xx/xxxx0)
                   db 0

  _format_time     db '%02d:%02d:%02d',0
  _buffer_time     rb 9                                         ; 9 bytes reserved (xx:xx:xx0)
                   db 0

section '.code' code readable executable

  start:
        invoke  GetModuleHandle,0
        mov     [hinstance],eax
        invoke  DialogBoxParam,[hinstance],ID_DIALOG,HWND_DESKTOP,DialogProc,0
        invoke  ExitProcess,0

proc DialogProc,hwnddlg,msg,wparam,lparam
        push    ebx esi edi
        cmp     [msg],WM_INITDIALOG
        je      wminitdialog                                    ; call before dialog box is displayed
        cmp     [msg],WM_COMMAND
        je      wmcommand
        cmp     [msg],WM_CLOSE
        je      wmclose
        xor     eax,eax                                         ; eax = 0
        jmp     finish
  wminitdialog:

        stdcall time,[hwnddlg]
        stdcall date,[hwnddlg]

        jmp     processed
  wmcommand:
        cmp     [wparam],BN_CLICKED shl 16 + ID_CANCEL
        je      wmclose                                         ; goto close if click on Cancel
        cmp     [wparam],BN_CLICKED shl 16 + ID_OK
        jne     processed                                       ; <> Ok
        stdcall time,[hwnddlg]
        jmp     processed
  wmclose:
        invoke  EndDialog,[hwnddlg],0
  processed:
        mov     eax,1
  finish:
        pop     edi esi ebx
        return
endp

proc time,_hwnddlg
        invoke  GetSystemTime,lpSystemTime
        movsx   eax,[lpSystemTime.wHour]
        movsx   ebx,[lpSystemTime.wMinute]
        movsx   edi,[lpSystemTime.wSecond]
        cinvoke wsprintf,_buffer_time,_format_time,eax,ebx,edi
        invoke  SetDlgItemText,[_hwnddlg],ID_EDIT_TIME,_buffer_time

        return
endp

proc date,_hwnddlg
        movsx   eax,[lpSystemTime.wDay]
        movsx   ebx,[lpSystemTime.wMonth]
        movsx   edi,[lpSystemTime.wYear]
        cinvoke wsprintf,_buffer_date,_format_date,eax,ebx,edi
        invoke  SetDlgItemText,[_hwnddlg],ID_EDIT_DATE,_buffer_date

        return
endp

section '.idata' import data readable writeable

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

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

  import user,\
         DialogBoxParam,'DialogBoxParamA',\
         SetDlgItemText,'SetDlgItemTextA',\
         MessageBox,'MessageBoxA',\
         wsprintf,'wsprintfA',\
         EndDialog,'EndDialog'

section '.rsrc' resource data readable

  directory RT_DIALOG,dialogs

  resource dialogs,\
           ID_DIALOG,LANG_NEUTRAL+SUBLANG_DEFAULT,datesysteme

  dialog datesysteme,"System Date", 70, 70, 150, 90, DS_CENTER+DS_MODALFRAME+WS_POPUP+WS_VISIBLE+WS_CAPTION+WS_SYSMENU
    dialogitem 'STATIC','System date :', ID_LABEL_DATE, 15, 10, 50, 14, SS_LEFT + SS_CENTERIMAGE + WS_CHILD + WS_VISIBLE + WS_GROUP, 0x00000000
    dialogitem 'STATIC','System Time :', ID_LABEL_TIME, 15, 30, 50, 14, SS_LEFT + SS_CENTERIMAGE + WS_CHILD + WS_VISIBLE + WS_GROUP, 0x00000000
    dialogitem 'BUTTON',''             , ID_GROUP_BOX , 60,  0, 85, 49, BS_GROUPBOX + WS_CHILD + WS_VISIBLE, 0x00000000
    dialogitem 'STATIC','__/__/____'   , ID_EDIT_DATE , 70, 10, 65, 14, SS_CENTER + SS_CENTERIMAGE + WS_CHILD + WS_VISIBLE + WS_GROUP, 0x00000204
    dialogitem 'STATIC','__:__:__'     , ID_EDIT_TIME , 70, 30, 65, 14, SS_CENTER + SS_CENTERIMAGE + WS_CHILD + WS_VISIBLE + WS_GROUP, 0x00000204
    dialogitem 'BUTTON','&Time'        , ID_OK        ,  5, 55, 61, 28, BS_PUSHBUTTON + BS_VCENTER + BS_CENTER + WS_CHILD + WS_VISIBLE + WS_TABSTOP
    dialogitem 'BUTTON','&Quit'        , ID_CANCEL    , 80, 55, 61, 28, BS_PUSHBUTTON + BS_VCENTER + BS_CENTER + WS_CHILD + WS_VISIBLE + WS_TABSTOP
  enddialog
    


**********************************************

i modified only that line to make the program run
Code:
        invoke  wsprintf,_buffer,_format,eax,ebx,edi
    

by
Code:
        cinvoke  wsprintf,_buffer,_format,eax,ebx,edi
    


Can you explain why its working now ?

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 08 May 2005, 13:39
View user's profile Send private message Visit poster's website Reply with quote
donkey7



Joined: 31 Jan 2005
Posts: 127
Location: Poland, Malopolska
donkey7
Just see at macro source. cinvoke pushes parameters in reverse orders. You should use "movzx" instead of "movsx" because words are unsigned. You should also use "%ud" instead of "%d".

before giving questions you should read help provided with fasm or see at source of include files and examples. this would help you much more.

_________________
Keep coding!
Post 11 May 2005, 20:11
View user's profile Send private message Visit poster's website Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith
Thank you, understood ! Very Happy

donkey7 wrote:
before giving questions you should read help provided with fasm or see at source of include files and examples. this would help you much more.


I do, still learning Embarassed

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 11 May 2005, 20:25
View user's profile Send private message Visit poster's website Reply with quote
thebofh



Joined: 14 Jun 2005
Posts: 5
thebofh
I am very new to ASM. How would I change this source to reflect U.S. EDT Date and Time? Thanks.
Post 21 Jun 2005, 04:55
View user's profile Send private message Reply with quote
Torrey



Joined: 12 Oct 2003
Posts: 78
Torrey
thebofh wrote:
I am very new to ASM. How would I change this source to reflect U.S. EDT Date and Time? Thanks.


This question answers pretty easy, look below at the code.
Code:
        movsx   eax,[lpSystemTime.wDay]
        movsx   ebx,[lpSystemTime.wMonth]
        movsx   edi,[lpSystemTime.wYear]
        cinvoke wsprintf,_buffer_date,_format_date,ebx,eax,edi
        invoke  SetDlgItemText,[_hwnddlg],ID_EDIT_DATE,_buffer_date      


US dates start with the month, and pretty much every where else in the world it starts with the day. All you have to do (I already did it above) is flip the registers in the wsprintf call.
Post 21 Jun 2005, 09:37
View user's profile Send private message Visit poster's website Reply with quote
thebofh



Joined: 14 Jun 2005
Posts: 5
thebofh
Thank-you very much. But I guess I am missing something. The date comes out correctly but the time is still +4 hours. When it is 16:53 locally, the time prints 20:53. Am I overlooking something. Thanks agian.
Post 21 Jun 2005, 20:50
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
I've got GMT+2:00, but the time shown there is GMT-1:00 so 3 hours behind. I could do:
Code:
        ;...
        movsx   eax,[lpSystemTime.wHour]
        add     eax,3
        cmp     eax,24
        jnc     skip24fix
        sub     eax,24
    skip24fix:
        ;...
    

...but that's just WRONG!
Post 21 Jun 2005, 22:45
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
farrier



Joined: 26 Aug 2004
Posts: 274
Location: North Central Mississippi
farrier
GetLocalTime has always worked for me. You had imported it, but not used it. It should give you the same date and time that you see in your system tray.

farrier

_________________
Some Assembly Required
It's a good day to code!
U.S.Constitution; Bill of Rights; Amendment 1:
... the right of the people peaceably to assemble, ...
The code is dark, and full of errors!
Post 22 Jun 2005, 02:13
View user's profile Send private message Reply with quote
thebofh



Joined: 14 Jun 2005
Posts: 5
thebofh
Thanks farrier, the GetLocalTime did the trick. As your signature says "With every mistake, we must surely be learning!"

thebofh
Post 22 Jun 2005, 18:24
View user's profile Send private message Reply with quote
farrier



Joined: 26 Aug 2004
Posts: 274
Location: North Central Mississippi
farrier
If you would like an example of using a DateTimePicker control, I can supply the code for the second assembly language program I wrote. It is an AlarmClock, Countdown Timer, & Stopwatch.

Let me know.

farrier

Quote:
As your signature says "With every mistake, we must surely be learning!"


If only George W. Bush could learn!

f

_________________
Some Assembly Required
It's a good day to code!
U.S.Constitution; Bill of Rights; Amendment 1:
... the right of the people peaceably to assemble, ...
The code is dark, and full of errors!
Post 22 Jun 2005, 22:51
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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.