Is it wrong if I try to create a window with code executed from VirtualAlloced memory (with proper PAGE_EXECUTE_READWRITE flag set). In a "normal" environement (ie not in allocated memory), the window creates ok and all that. The problem is that the *same* code executed from VirtualAlloced memory creates the window, but it refuses to create any controls like buttons (the WM_CREATE message is dispatched, but CreateWindowExA returns 0 even if all the arguments are pushed properly). This happens on Windows XP, don't know about Win9x.
I am hunting for this bug 2 days now and it's really annoyng..any idea?

thank you
Posted on 2003-12-02 03:02:26 by DZA
I can see no problem with code in allocated memory, as long as your using a delta offset.
Posted on 2003-12-02 09:20:48 by ENF
no controls created? Guessing, but could it be you're not using the right hWnd and hInstance (of your code-generated window)?
Posted on 2003-12-02 10:37:06 by drarem
Is the stack aligned?
Posted on 2003-12-02 10:47:51 by roticv
yup, im using a delta offset & the right image base+parent window handle.
roticv, what do you mean by aligned stack? shouldn't be the stack dword aligned by default? is there a way to check if the stack is aligned? this might be the problem as i never understood MS's requirements regarding alignement.
Posted on 2003-12-02 18:13:24 by DZA
Since your window is being created dynamically, I am thinking you want to call GetModuleHandle(NULL) to get your hwnd to pass to CreateWindow() for the buttons - as well as that other API call to get the hInstance of your dynamic window. Make those calls in the WM_CREATE, just before creating any other controls.
Posted on 2003-12-02 22:41:55 by drarem
uh? how im supposed to get the hwnd using GetModuleHandle? u can get only the image base ( hInstance ) with that api...in fact the image base remains the same for the same module all the time, so no need to call it 100 times...prolly my problem is not in handles etc. since my code works well in normal environement.
Posted on 2003-12-03 03:56:37 by DZA
each control can have its own hwnd - you have to know them in order to work with them by keeping track of them when created. I'm surprised since you are creating the controls at runtime that you don't.

Therefore each window/thread has its own hwnd. you have to know the handle of which window you are working with.

I was confused with the API call, getmodulehandle when createwindow()'ing the runtime window - if this is a child window, make sure the runtime window is using that specific value when creating the buttons and controls in the WM_CREATE section. That means you have to build this stuff dynamically too.

And make sure you are returning using DefFrameProc() or DefWindowsProc appropriately with the correct hWnd, you know at the bottom of the WndProc (your dynamic one). I don't know how you would determine that, it being a code-generated thread.. does that include a window as well? Can't really help much without some code though.
Posted on 2003-12-03 04:34:41 by drarem
Try calling GetLastError after CreateWindowEx fails.
Posted on 2003-12-03 04:55:29 by ENF
As it's name imply the GetModuleHandle function will not return a HWND, it will return the HINSTANCE that you must pass to the CreateWindow function who is the one who will return you the HWND handle of the window created.

:alright:
Posted on 2003-12-03 05:22:13 by Eternal Idol Birmingham