flat assembler
Message board for the users of flat assembler.
Index
> Windows > [The newbie (again)] : API |
Author |
|
shoorick 06 May 2005, 06:25
Code: invoke SetDlgItemText,[hwnddlg],ID_LABEL_DATE,output |
|||
06 May 2005, 06:25 |
|
shoorick 06 May 2005, 06:29
Code: start: invoke SetDlgItemText,ID_DIALOG,ID_LABEL_DATE,output ^- dialog window does not exist yet invoke GetModuleHandle,0 |
|||
06 May 2005, 06:29 |
|
flaith 06 May 2005, 08:04
now i understand, thank you.
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'. |
|||
06 May 2005, 08:04 |
|
coconut 06 May 2005, 12:32
lets see your buffer_format
|
|||
06 May 2005, 12:32 |
|
flaith 06 May 2005, 16:20
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) _________________ Je suis sur de 'rien', mais je ne suis pas sur du 'tout'. |
|||
06 May 2005, 16:20 |
|
Reverend 07 May 2005, 18:10
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 '[' ']' |
|||
07 May 2005, 18:10 |
|
flaith 07 May 2005, 18:37
thanks, i already tried that way too but i got an error : operand sizes do not match
_________________ Je suis sur de 'rien', mais je ne suis pas sur du 'tout'. |
|||
07 May 2005, 18:37 |
|
donkey7 08 May 2005, 12:35
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. |
|||
08 May 2005, 12:35 |
|
flaith 08 May 2005, 13:20
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 : 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'. |
|||
08 May 2005, 13:20 |
|
flaith 08 May 2005, 13:39
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'. |
|||
08 May 2005, 13:39 |
|
donkey7 11 May 2005, 20:11
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! |
|||
11 May 2005, 20:11 |
|
flaith 11 May 2005, 20:25
Thank you, understood !
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 _________________ Je suis sur de 'rien', mais je ne suis pas sur du 'tout'. |
|||
11 May 2005, 20:25 |
|
thebofh 21 Jun 2005, 04:55
I am very new to ASM. How would I change this source to reflect U.S. EDT Date and Time? Thanks.
|
|||
21 Jun 2005, 04:55 |
|
Torrey 21 Jun 2005, 09:37
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. |
|||
21 Jun 2005, 09:37 |
|
thebofh 21 Jun 2005, 20:50
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.
|
|||
21 Jun 2005, 20:50 |
|
Madis731 21 Jun 2005, 22:45
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! |
|||
21 Jun 2005, 22:45 |
|
farrier 22 Jun 2005, 02:13
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! |
|||
22 Jun 2005, 02:13 |
|
thebofh 22 Jun 2005, 18:24
Thanks farrier, the GetLocalTime did the trick. As your signature says "With every mistake, we must surely be learning!"
thebofh |
|||
22 Jun 2005, 18:24 |
|
farrier 22 Jun 2005, 22:51
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! |
|||
22 Jun 2005, 22:51 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.