News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Window manipulation

Started by ThexDarksider, September 26, 2009, 08:32:28 PM

Previous topic - Next topic

ThexDarksider

Hi, I'm trying to get current window's title and return it in a message box but I always get errors when compiling. What am I doing wrong? :red

Here's what I have so far:

.386
.model flat,stdcall
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
.data?
chwnd dd ?
strbuf dd ? dup('512')
.code
start:
invoke GetForegroundWindow,chwnd
invoke GetWindowText,chwnd,strbuf,512
invoke MessageBoxA,NULL,addr strbuf,NULL,MB_OK
end start


Here's the output:

Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1977.  All rights reserved.

Assembling: test.asm
test.asm(9) : error A2009: syntax error in expression
test.asm(12) : error A2136: too many arguments to INVOKE
test.asm(14) : error A2006: undefined symbol : MB_OK
test.asm(14) : error A2114: INVOKE argument type mismatch : argument : 4
test.asm(14) : error A2006: undefined symbol : NULL
test.asm(14) : error A2114: INVOKE argument type mismatch : argument : 3
test.asm(14) : error A2114: INVOKE argument type mismatch : argument : 1


I feel like am an idiot...

EDIT: I guess MB_OK and NULL are defined in windows.inc but when I put include \masm32\include\windows.inc, it makes over 100 errors and exits.

They look like this:

Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: test.asm
\masm32\include\windows.inc(129) : error A2004: symbol type conflict : bool
\masm32\include\windows.inc(7804) : error A2179: structure improperly initialized
\masm32\include\windows.inc(7804) : error A2008: syntax error : in structure
\masm32\include\windows.inc(8711) : error A2179: structure improperly initialized
\masm32\include\windows.inc(8711) : error A2008: syntax error : in structure
\masm32\include\windows.inc(8724) : error A2179: structure improperly initialized
\masm32\include\windows.inc(8724) : error A2008: syntax error : in structure


And the last lines go on until it halts.

Vortex

strbuf dd ? dup('512')

This should be :

strbuf dd 512 dup(?)

GetForegroundWindow does not take any parameters.

This line is missing to define the NULL and MB_OK constants in line 14 :

include \masm32\include\windows.inc

To avoid those error messages concerning windows.inc, your third line should be :

option casemap:none

Your application should terminate with :

invoke  ExitProcess,0

ThexDarksider

Yes, the casemap! :bg I knew I forgot something, thanks m8.

Now it compiles, however when I run it, it shows the message box with title "Error". :(

I have this in main code:

invoke GetForegroundWindow
mov chwnd,eax
invoke GetWindowText,chwnd,strbuf,512
invoke MessageBoxA,NULL,addr strbuf,NULL,MB_OK


Something in my mind keeps telling me that the mov part is wrong...

This also doesn't work:

push eax
invoke GetForegroundWindow
pop eax
mov chwnd,eax
invoke GetWindowText,chwnd,strbuf,512
invoke MessageBoxA,NULL,addr strbuf,NULL,MB_OK

Vortex

invoke GetWindowText,chwnd,strbuf,512

This should be :

invoke GetWindowText,chwnd,ADDR strbuf,512

The second parameter of GetWindowText is the address of buffer for text.

I modified a bit your code :


.386
.model flat,stdcall
option casemap:none

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

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib


BUFFER_SIZE equ 512

.data

capt        db 'Foreground window caption',0

.data?

buffer      db BUFFER_SIZE dup(?)

.code

start:

    invoke  GetForegroundWindow
    invoke  GetWindowText,eax,ADDR buffer,BUFFER_SIZE
    invoke  MessageBox,0,ADDR buffer,ADDR capt,MB_OK
    invoke  ExitProcess,0

END start

qWord

Quote from: ThexDarksider on September 26, 2009, 08:56:43 PM
it shows the message box with title "Error". :(
...
invoke MessageBoxA,NULL,addr strbuf,NULL,MB_OK
pass a pointer to the third parameter - it is the pointer to the message box's title

regards, qWord
FPU in a trice: SmplMath
It's that simple!

ThexDarksider

Thanks guys, it works now. :U

I'm familiar mostly with C# and Java and a bit of C, so I'm used to working with variables, not pointers. :toothy Thanks for clearing it out for me. Btw, I've figured out what is the DUP thing actually, I didn't even know, I just saw it at another code. XD