Hi,

I?m trying to call FindWindow API. To do this I need to push a null string... Can I use the "NULL" keyword for this?

This APi will then return a hwnd (window handle) which is of type long. This way, how can I define a variable of this kind?

After this I would like to put that hwnd in the text of a messagebox. When I invoke the API, can I use the variable where I stored the hnwd or I need to "converte" that value into a string?

Thank you!
Posted on 2002-05-27 05:08:46 by Neptuno
hi neptuno,

>Can I use the "NULL" keyword for this?
it depends...what are you using? masm, tasm or something else?
with masm you can push NULL. i don't know with others...

>how can I define a variable of this kind?
name_var HANDLE ?

>can I use the variable where I stored the hnwd or I need to "converte" that value into a string?
hmmm...i think you have to "converte" it using, for example, wsprintf function.

hope this helps!
bye
ZaiRoN
Posted on 2002-05-27 05:32:05 by ZaiRoN

hi neptuno,

>Can I use the "NULL" keyword for this?
it depends...what are you using? masm, tasm or something else?
with masm you can push NULL. i don't know with others...

>how can I define a variable of this kind?
name_var HANDLE ?

>can I use the variable where I stored the hnwd or I need to "converte" that value into a string?
hmmm...i think you have to "converte" it using, for example, wsprintf function.

hope this helps!
bye
ZaiRoN




What I?m trying to do, is this:

.386
.model flat, stdcall
option casemap :none

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\windows.inc

.data

hwnd HANDLE ?
ErrorCode dd 0
FWText db "Shell_TrayWnd",13,10,0
;MsgText db "Something",13,10,0
MsgTitle db "This is a messagebox",0

.code

start:

;Find Window
invoke FindWindow, FWText, NULL

MOV hwnd,eax

invoke MessageBox, NULL, MsgTitle, hwnd, MB_OK
invoke ExitProcess, NULL

end start


Your hint to de type of the variable worked fine however I still get erros in the code. I?m trying to learned how to use the mov instruction...

Thank you
Posted on 2002-05-27 06:51:07 by Neptuno

To do this I need to push a null string... Can I use the "NULL" keyword for this?


findwindow needs a classname and/or a window-title...
a null-terminated string is just a bunch of bytes terminated
by 0 (zero) like when you do MyString db "testtest",0 ...
look in your api-ref, it says findwindow don't need a window-
title but you CAN pass one if you want... if you DON'T want
to do this api-ref says: "instead pass NULL" so what does
that mean? NULL = 0, that means if you pass a zero value
findwindow knows that it just have to find a window that
fits to the class-name you gave. BTW, why do you have db
13,10 in your string? thats the ascii codes for linefeed and
cariagereturn (->get to beginning of the next line)... in my
whole life i don't came across a window that uses crlf in it's
title or classname... uhh and what up with... wait there to
much little errors... will post a little example: this will open
the windows calculator and close it after you pressed OK...



.386
.model flat, stdcall
option casemap :none

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\windows.inc

.DATA
FWText DB "SciCalc",0
MsgText DB "Press OK to close calculator",0
MsgTitle DB "This is a messagebox",0
path DB "calc.exe",0

.DATA?
hwnd DD ?

.CODE

START: invoke WinExec, addr path, NULL

invoke MessageBox, NULL, addr MsgText, addr MsgTitle, MB_OK

invoke FindWindow, addr FWText, NULL

invoke SendMessage, eax, WM_CLOSE,0,0

invoke ExitProcess, NULL

END START


at first grab a good asm tutorial that describes the opcodes
(like mov...) and then get over to iczelions tutorials to learn
how to use the api's...
Posted on 2002-05-27 07:22:48 by mob
invoke MessageBox, NULL, MsgTitle, hwnd, MB_OK


First, it is
invoke MessageBox, NULL, ADDR MsgTitle...

After, the problem doesn't come from mov, but from the fact hwnd is a dword... an unsigned long integer... MessageBox wants the address to a string.

As Zairon said, a simple way to convert a dword to a string is to use the wsprintf api... but you can find optimized routines in the MASM32 lib...
Posted on 2002-05-27 07:27:10 by JCP
why should one convert a pointer value that points
to some non-string data to a string? or like in this
case a window handle to a string? Neptuno, if you
want to msgbox out a window-title use GetWindowText
after calling FindWindow (to get a valid handle that
points to your desired window)
Posted on 2002-05-27 07:32:16 by mob
hi Neptuno,

earlier today i was trying to get the handle to the taskbar too.:)

i modified your code and added some comments to help you visualize.
.386 

.model flat, stdcall
option casemap :none

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\windows.inc

;// to use the functions from the masm32 library you must include these 2 lines below
includelib \masm32\lib\masm32.lib
include \masm32\include\masm32.inc

.data
hwnd HANDLE ?
FWText db "Shell_TrayWnd",0
MsgTitle db "This is a messagebox",0

.data?
buffer dd ?

.code
start:
;invoke FindWindow, addr FWText, NULL ;<--these two lines mean the same thing
invoke FindWindow, addr FWText, 0 ;<--just for demonstration purposes
mov hwnd,eax

;// the handle is in a number form but to display it as a string(text) we need to convert it to a string
;// use the dwtoa function from the masm32 library to convert the number to string
;// the windows api function wsprintf can do the same thing but using the masm32 dwtoa function will provide faster results and less work for you
invoke dwtoa,hwnd,addr buffer ;convert hwnd to string and store it into our buffer
invoke MessageBox, NULL, addr MsgTitle, addr buffer, MB_OK ;dispay the handle in the window title bar
invoke ExitProcess, NULL

end start
Posted on 2002-05-27 08:02:17 by smurf