This program runs but the window wont show up. Yes i did call ShowWindow.
(Compiled with nasm, linked with alink)
Posted on 2003-12-10 14:58:53 by bnice2137
Hi. :)
I found this a bit strange, it does not solve the problem though:

enter 0,0

cmp dword PARAM2, WM_DESTROY
je GotWmDestroy
jne DisreguardMessageA

[COLOR=red]; This never gets executed![/COLOR]
xor eax, eax

Maybe you could also remove the enter/leave instructions and use push ebp/mov ebp,esp/pop ebp, as I think it's faster (please correct me if I'm wrong).
Posted on 2003-12-10 15:17:27 by QvasiModo
Another (useless :grin: ) suggestion:

or eax, eax
jz ProgramQuit

Replace with:

inc eax
jz ProgramQuit
dec eax
jz ProgramQuit

That should also handle a return value of -1 from GetMessage. :)
Posted on 2003-12-10 15:22:59 by QvasiModo
It also doesn't do anything with WM_PAINT?
Posted on 2003-12-10 15:27:43 by S/390

It also doesn't do anything with WM_PAINT?

Think it's handled at DisreguardMessageA. The app should still draw the nonclient area without a problem, and the client area using the class brush (if any).
Posted on 2003-12-10 15:29:40 by QvasiModo
uhm... nobody answered the question!!! lol.
Posted on 2003-12-10 15:32:13 by bnice2137

uhm... nobody answered the question!!! lol.

:grin: Sorry, couldn't figure it out.
Can you upload the assembled version? I don't have NASM.
Posted on 2003-12-10 15:35:36 by QvasiModo
Here it is.

my command line:

nasm myfirstwin.asm -fobj -o myfirstwin.o
alink -subsys gui -oPE -entry start myfirstwin.o
Posted on 2003-12-10 15:40:29 by bnice2137

Perhaps it also needs WS_POPUP or WS_OVERLAPPED? :confused:
Posted on 2003-12-10 15:43:24 by QvasiModo
CreateWindowEx is returning 0, LastError is ERROR_ALREADY_EXISTS.
I'm even more puzzled than before. :grin:

Also note that failure at creating the main window causes an infinite loop at the message handler (see my second post).
Posted on 2003-12-10 15:45:50 by QvasiModo
well... does anyone know what i should do!!! should i just switch to masm and call it a day.
Posted on 2003-12-10 16:11:18 by bnice2137
I don't want to downtalk Nasm, I am sure it is a very capable assembler - but it seems to me masm is the more popular choice.. if it was me I would download and install masm and radasm, together they kickbuttocks, but that is just my opinion.
Posted on 2003-12-10 16:18:42 by drarem
Hi bnice2137,

Though MASM is definitely the assembler of choice for most of the programmers here, NASM is also a very good assembler in it's own right. There are a few dedicated NASM users who will see this thread and help you out, nguga and Odyssey both use NASM (nguga for sure). Find him on the board and PM him with the URL of the thread, he will definitely help get it straightened out.
Posted on 2003-12-10 16:27:06 by donkey
Your stack pointers seem to be off by 4 bytes:

%define PARAM1 [ebp + 4]
%define PARAM2 [ebp + 8]
%define PARAM3 [ebp + 12]
%define PARAM4 [ebp + 16]

Consider your WndProc. When called by Windows, the procedure's stack looks like this:

[DWORD lParam] ; = ESP + 4*4
[DWORD wParam] ; = ESP + 3*4
[DWORD Msg] ; = ESP + 2*4
[DWORD hWnd] ; = ESP + 1*4
[DWORD return address] ; = ESP + 0*4

The first instruction inside your WndProc is "enter 0,0", which amounts to "push ebp / mov ebp, esp". Now, everything is 4 bytes "higher" on the stack than before:

[DWORD lParam] ; = ESP + 5*4, or EBP + 5*4
[DWORD wParam] ; = ESP + 4*4, or EBP + 4*4
[DWORD Msg] ; = ESP + 3*4, or EBP + 3*4
[DWORD hWnd] ; = ESP + 2*4, or EBP + 2*4
[DWORD return address] ; = ESP + 1*4, or EBP + 1*4
[DWORD old_EBP] ; = ESP + 0*4, or EBP + 0*4

Later, in your "DisreguardMessageA", you push ", PARAM2, PARAM3, PARAM4" (in reverse order) onto the stack, intending to pass ", Msg, wParam, lParam" to the default window procedure. What you actually pass, however, is ", hWnd, Msg, wParam", because your EBP-based stack frame pointer is off by 4 bytes after the "enter 0,0".

I don't have NASM installed -- there may be additional issues.

Regards, Frank
Posted on 2003-12-10 16:27:28 by Frank
thanks frank and donkey. ill be sure to fix up my stack and PM one of those nasm users.
Posted on 2003-12-10 16:32:08 by bnice2137

nguga and Odyssey both use NASM

You must have meant fasm :grin:. nguga uses nasm. He's the author of the nasm ide right? My assemblers of choice are HLA and Fasm. :)
Posted on 2003-12-10 16:59:21 by Odyssey
Hi Odyssey,

Yeah, I don't know why you popped into my head, it was hgb I was thinking of, can't really claim it was a typo can I ? :grin:
Posted on 2003-12-10 17:16:15 by donkey
I call that a thinko... :cool:
Posted on 2003-12-10 22:11:56 by S/390
:( i guess its off to masm world...
Posted on 2003-12-10 22:32:34 by bnice2137
The problem is in CreateWindowEx. Somehow the return value is 0 and the error code is ERROR_INVALID_WINDOW_HANDLE but I could not figure out why.
Posted on 2003-12-10 22:50:15 by roticv