argh Im having tons of trouble with this proggie! here is the code I have to find a window so I can list the names of the ppl currently on/using the program. But for some reason it always gives me the error message I set it up to give even if the window its looking for is up. Can anyone help?

invoke GetModuleHandle,NULL
mov hInstance,eax
invoke FindWindow,NULL,ADDR nameofwindow
.if eax == 0
jz norun
.else
mov windhand,eax
.endif
xor eax,eax
ret
invoke GetWindowThreadProcessId,eax,offset dwprocessid
invoke OpenProcess,PROCESS_VM_WRITE OR PROCESS_VM_OPERATION,NULL,dwprocessid
mov gameprocess, eax
invoke GetCommandLine
invoke InitCommonControls
invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
invoke ExitProcess,eax


then at the bottom of the code I have this. This is where it jumps if the program isnt running. Its at the very bottom of my code.


norun:
Invoke MessageBox,hInstance,offset ErrorMessage,offset ErrorCaption,MB_OK
ret
end norun

end start

And thats the end. But for some reason it always displays the message box with the error message even when the program its looking for is running. someone help please!! lol I really need help on this one.
Posted on 2002-06-25 01:36:24 by resistance_is_futile
haha nevermind found my mistake ( i was missing the class name of my window because im using radasm for this so it has a class and i didnt tell findwindow that there was a class). It kinda works now lol.
Posted on 2002-06-25 02:18:26 by resistance_is_futile
wait ti didnt work :mad: :mad: :mad: . Someone help please.
Posted on 2002-06-25 02:31:32 by resistance_is_futile
Can you please repost your code including your .data section ?

BTW, you code can't run anyway:



invoke GetModuleHandle,NULL
mov hInstance,eax

invoke FindWindow,NULL,ADDR nameofwindow

.if eax == 0
jz norun [color=green]; better change this to a "jmp norun"[/color]
.else
mov windhand,eax
.endif

[color=green]
; or replace the above .if block with that:
; invoke FindWindow ....
; or eax, eax
; jz norun ; btw, where is the norun label?
; mov windhand, eax
[/color]

xor eax,eax
[color=red][b]ret [/b][/color][color=green]; <---- oops, what's that? :)[/color]

invoke GetWindowThreadProcessId,eax,offset dwprocessid
invoke OpenProcess,PROCESS_VM_WRITE OR PROCESS_VM_OPERATION,NULL,dwprocessid

mov gameprocess, eax

invoke GetCommandLine
invoke InitCommonControls
invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
invoke ExitProcess,eax




Regards,
bAZiK
Posted on 2002-06-25 02:54:28 by bazik
okay heres data section..
.data

nameofwindow db "program names (edited out)",0
ClassName db 'DLGCLASS',0
MenuName db 'MyMenu',0
DlgName db 'MyDialog',0
AppName db 'Dialog as main',0
I know I dont need it but im too lazy to delete it>AboutMsg db 'MASM32 RadASM Dialog as main',13,10,'Copyright ? MASM32 2001',0
helptext db 'To use this you must first get into <programs name>then start this',0ah
db 'bad boy up. Once it starts, click the Start button and you will be able to see the names of ppl online..',0
helpcap db 'Help/About. Devil*TCB*',0
urnameaddy equ 0000c72bf6h
ErrorMessage db 'Run <programs name> first before you start this program.',0
ErrorCaption db 'Run <programs name>',0


.data?

windhand dd ?
buffer1 dd ?
hInstance dd ?
CommandLine dd ?
hWnd dd ?
gameprocess dd ?
phandle dd ?
dwprocessid dd ?
Posted on 2002-06-25 03:13:26 by resistance_is_futile
Hi!

Did you try your code after removing that "ret" instruction? ;)

Regards,
bAZiK
Posted on 2002-06-25 03:22:44 by bazik
yea i tried this like u typed but it didnt work. It still gave me the error message even though the proggie was running:

Invoke FindWindow,NULL,addr nameofwindow

.if eax == 0
jmp norun
.else
mov windhand,eax
.endif
xor eax,eax
ret
invoke GetWindowThreadProcessId,windhand,offset dwprocessid
invoke OpenProcess,PROCESS_VM_WRITE OR PROCESS_VM_OPERATION,NULL,dwprocessid
mov gameprocess,eax


invoke GetModuleHandle,NULL
mov hInstance,eax
invoke GetCommandLine
invoke InitCommonControls
invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
invoke ExitProcess,eax
Posted on 2002-06-25 03:28:49 by resistance_is_futile
oh lol thought u meant to PUT the ret function in lol ill remove it right quick..
Posted on 2002-06-25 03:29:56 by resistance_is_futile
nope didnt work.
Posted on 2002-06-25 03:31:31 by resistance_is_futile
BTW, just saw another bug:



invoke GetModuleHandle,NULL
mov hInstance,eax
[color=royalblue][b]invoke GetCommandLine[/b][/color]
[color=green]; you should add a "mov Commandline, eax" after this line :)[/color]
invoke InitCommonControls
invoke WinMain,hInstance,NULL,[color=royalblue][b]CommandLine[/b][/color],SW_SHOWDEFAULT
invoke ExitProcess,eax
Posted on 2002-06-25 03:36:28 by bazik

nope didnt work.



Than the problem might be in the caption you use:



nameofwindow db "program names (edited out)",0


Well, you fear to tell us the name, we can't see if you made something wrong there.
Posted on 2002-06-25 03:44:01 by bazik
(26) : error A2006: undefined symbol : Commandline

Make error(s) occured.
thats the error i get when i did wut u said to the command line thing. Also I want this error message (the no run thing) to only apper when the program ISNT running. When its running i want to be able to start my proggy and this error message wont come up.
Posted on 2002-06-25 03:48:58 by resistance_is_futile
lol no it isnt that i made sure the caption is perfect. ITs not that i fear to tell u it its just that if i DO tell you, you might not help me...
Posted on 2002-06-25 03:50:27 by resistance_is_futile

(26) : error A2006: undefined symbol : Commandline

Make error(s) occured.
thats the error i get when i did wut u said to the command line thing. Also I want this error message (the no run thing) to only apper when the program ISNT running. When its running i want to be able to start my proggy and this error message wont come up.


Write it with a upper case "L", like your declared it in your .data?section:



CommandLine dd ?


Sorry for saying this, but you should read some tutorials first :grin:
Posted on 2002-06-25 04:00:49 by bazik
Ahm, I don't want to disturb you two, but I have a question. Will "FindWindow" work at all with first parameter being NULL?

japheth
Posted on 2002-06-25 06:04:00 by japheth
Hehe, yes. At least the second can be, why shouldn't the first one:
http://www.asmcommunity.net/board/index.php?topic=510&highlight=findwindow
Posted on 2002-06-25 06:31:07 by bazik
I know :D I fixed that by putting it in my .data? section and also fixed the findwindow part a while back (the class part). Im trying some other stuff now.
Posted on 2002-06-25 12:58:49 by resistance_is_futile
Okay, this is my finished result. But its still not quite fixed. When it runs, the box still comes up regardless if the program is running or not BUT the main program comes up after that. See if you guys can fix it because I am totally stumped:



.386
.model flat,stdcall
option casemap:none

include masskill.inc


.code

start:
Invoke FindWindow,addr ClassName,addr nameofwindow

.if eax == 0
Invoke MessageBox,hInstance,offset ErrorMessage,offset ErrorCaption,MB_OK
.elseif
mov windhand,eax
.endif
invoke GetWindowThreadProcessId,windhand,offset dwprocessid
invoke OpenProcess,PROCESS_VM_WRITE OR PROCESS_VM_OPERATION,NULL,dwprocessid
mov gameprocess,eax


invoke GetModuleHandle,NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine, eax
invoke InitCommonControls
invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
invoke ExitProcess,eax


If you find any more errors then there already is please tell me so I can fix them and maybe get this to work.
Posted on 2002-06-25 13:13:25 by resistance_is_futile
please guys dont give up!!! I know it may seem a waste of your time but think about it your helping someone learn something new!! comeon please dont give up on me..
Posted on 2002-06-25 22:07:56 by resistance_is_futile
okay argh!! after hours of stress and hardcore typing lol I found out how to make this work perfect. It works awesome now thanks alot guys for your help. here is the code so future ppl looking for it can refer to it:
.code


start:
Invoke FindWindowEx,NULL,NULL,NULL,addr nameofwindow

invoke GetWindowThreadProcessId,eax,offset dwprocessid
invoke OpenProcess,PROCESS_VM_WRITE OR PROCESS_VM_OPERATION,NULL,dwprocessid
mov gameprocess,eax
.if eax==FALSE
Invoke MessageBox,hInstance,offset ErrorMessage,offset ErrorCaption,MB_OK
ret
.endif

where "nameofwindow" is the name of the processes window and "errormessage" is the address of message that is displayed in the box and "errorcaption" is the address of the Caption of the error box. Thanks again.
RIF
Posted on 2002-06-25 23:59:15 by resistance_is_futile