flat assembler
Message board for the users of flat assembler.

Index > Main > cmp

Author
Thread Post new topic Reply to topic
coconut



Joined: 02 Apr 2004
Posts: 326
Location: US
coconut 02 Aug 2004, 21:25
i have a proc in an app, that calls another proc in a dll. the proc sets eax to -1 right when returning to the dll. in the dll, the code right after sending a message to the exe, (eax should contain return value?) looks like so:

Code:
      invoke   postmessage [hwnd],wm_whatever,0,0
      cmp      eax,-1 ;return code from hwnd?
      je         negative_one
      invoke   messagebox, 0, error, error, 0
      jmp       finish
negative_one:
      invoke   messagebox,0,ok,ok,0
finish:
      invoke    exitprocess,0
    


the exe's code:

Code:
wm_whatever:
       ...
       ...
       mov    eax,-1
finish:
       pop edi esi ebx
       return
    


doesnt work, i dont get the "ok" messagebox.. am i missing something here?
Post 02 Aug 2004, 21:25
View user's profile Send private message Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld 02 Aug 2004, 21:35
Try SendMessage Wink
Post 02 Aug 2004, 21:35
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld 02 Aug 2004, 21:41
Win32 Programmer's reference wrote:
The PostMessage function places (posts) a message in the message queue associated with the thread that created the specified window and then returns without waiting for the thread to process the message.
Post 02 Aug 2004, 21:41
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: US
coconut 02 Aug 2004, 21:43
same problem Confused
Post 02 Aug 2004, 21:43
View user's profile Send private message Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: US
coconut 02 Aug 2004, 21:53
in this case i dont care what the return value of sendmessage is. i dont see why the cmp eax,-1 doesnt work.. is it because i set eax to -1 but then post/sendmessage returns and changes it?
Post 02 Aug 2004, 21:53
View user's profile Send private message Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld 02 Aug 2004, 21:57
Hmm... maybe you forgot to create window first

EXE (TEMPLATE.ASM):
Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

section '.data' data readable writeable

  _title db 'Win32 program template',0
  _class db 'FASMWIN32',0

  mainhwnd dd ?
  hinstance dd ?

  msg MSG
  wc WNDCLASS

section '.code' code readable executable

  start:

        invoke  GetModuleHandle,0
        mov     [hinstance],eax
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        mov     [wc.style],0
        mov     [wc.lpfnWndProc],WindowProc
        mov     [wc.cbClsExtra],0
        mov     [wc.cbWndExtra],0
        mov     eax,[hinstance]
        mov     [wc.hInstance],eax
        mov     [wc.hbrBackground],COLOR_BTNFACE+1
        mov     [wc.lpszMenuName],0
        mov     [wc.lpszClassName],_class
        invoke  RegisterClass,wc

        invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,192,192,NULL,NULL,[hinstance],NULL
        mov     [mainhwnd],eax

        invoke  ShowOK,eax

  msg_loop:
        invoke  GetMessage,msg,NULL,0,0
        or      eax,eax
        jz      end_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop

  end_loop:
        invoke  ExitProcess,[msg.wParam]

proc WindowProc, hwnd,wmsg,wparam,lparam
        push    ebx esi edi
        cmp     [wmsg],WM_DESTROY
        je      wmdestroy
        cmp     [wmsg],WM_USER
        je      wmuser
  defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     finish
  wmuser:
        or      eax,-1
        jmp     finish
  wmdestroy:
        invoke  PostQuitMessage,0
        xor     eax,eax
  finish:
        pop     edi esi ebx
        return
endp

section '.idata' import data readable writeable

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

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

  import user,\
         RegisterClass,'RegisterClassA',\
         CreateWindowEx,'CreateWindowExA',\
         DefWindowProc,'DefWindowProcA',\
         GetMessage,'GetMessageA',\
         TranslateMessage,'TranslateMessage',\
         DispatchMessage,'DispatchMessageA',\
         LoadCursor,'LoadCursorA',\
         LoadIcon,'LoadIconA',\
         PostQuitMessage,'PostQuitMessage'

  import errormsg,\
         ShowOK,'ShowOK'    

DLL (ERRORMSG.ASM):
Code:
format PE GUI 4.0 DLL
entry DllEntryPoint

include '%fasminc%\win32a.inc'

section '.code' code readable executable

proc DllEntryPoint, hinstDLL,fdwReason,lpvReserved
        mov     eax,TRUE
        return
endp

ok db 'ok!',0

proc ShowOK, hWnd
        invoke  SendMessage,[hWnd],WM_USER,0,0
        cmp     eax,-1
        jne     @f
        invoke  MessageBox,[hWnd],ok,0,0
    @@:
        return
endp

section '.idata' import data readable writeable

  library user,'USER32.DLL'

  import user,\
         MessageBox,'MessageBoxA',\
         SendMessage,'SendMessageA'

section '.edata' export data readable

  export 'ERRORMSG.DLL',\
         ShowOK,'ShowOK'

section '.reloc' fixups data discardable    


Last edited by mike.dld on 02 Aug 2004, 22:08; edited 1 time in total
Post 02 Aug 2004, 21:57
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: US
coconut 02 Aug 2004, 22:00
the window and dll run fine, just dont work as expected on the return value


the window i use is the win32 template example by privalov, the only lines i added were the wm_whatever ones. the dll i wrote is similar to yours

im thinking eax is changed by the send/postmessage call sometime after i do the mov eax,-1
Post 02 Aug 2004, 22:00
View user's profile Send private message Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld 02 Aug 2004, 22:14
Win32 Programmer's reference : SendMessage wrote:
The return value specifies the result of the message processing and depends on the message sent.
Post 02 Aug 2004, 22:14
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: US
coconut 02 Aug 2004, 22:17
ok, now i tried using ecx to return the -1 but it doesnt work either ?!
Post 02 Aug 2004, 22:17
View user's profile Send private message Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld 02 Aug 2004, 22:20
My example works for you?

Return value MUST be in EAX, it's the only register which value wouldn't change for sure.
Post 02 Aug 2004, 22:20
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: US
coconut 02 Aug 2004, 22:27
ah, i thought ecx wasnt used by windows? your example works fine, but my app still doesnt have eax equal to -1
Post 02 Aug 2004, 22:27
View user's profile Send private message Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: US
coconut 03 Aug 2004, 22:15
any way for an app to communicate to a dll, sending a message or such?
Post 03 Aug 2004, 22:15
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 04 Aug 2004, 06:35
hey coconut, are you writing your own dll? do you have 'enter' right after the 'proc command,arg1,arg2...'
Post 04 Aug 2004, 06:35
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 04 Aug 2004, 10:57
you don't need 'enter' when there are no locals.
Post 04 Aug 2004, 10:57
View user's profile Send private message Visit poster's website Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: US
coconut 04 Aug 2004, 21:06
enter was the trick Shocked
Post 04 Aug 2004, 21:06
View user's profile Send private message Reply with quote
asmdemon



Joined: 18 Jan 2004
Posts: 97
Location: Virginia Beach, VA
asmdemon 04 Aug 2004, 22:00
the simple way would be to:
push eax
postmessage....
pop eax
cmp eax, -1 ...
...
Post 04 Aug 2004, 22:00
View user's profile Send private message Visit poster's website Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: US
coconut 05 Aug 2004, 04:45
wouldnt work because of my previous pops in the app
Post 05 Aug 2004, 04:45
View user's profile Send private message Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: US
coconut 05 Aug 2004, 22:16
interesting, now im trying to use the carry flag to communicate between the app and dll, doesnt seem to be working. does windows 'seperate' the carry flag between two different processes?
Post 05 Aug 2004, 22:16
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.