chaoscode
Joined: 21 Nov 2006
Posts: 64
|
edit no 3:
I found my fault self,
.defwndproc:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
jmp .finish
.finish sets eax to 0, and returns...
so windows thougth that my apps gives a error back...
*[so ein kleiner scheiß fehler, der stunden kostet.]*
edit :
the code down there was in a own file,
and had a own ".code" section.
(an other section than the entry)
after put the sections together, i don't have a "invalid handel" error,
but creatwindow ex returns 0, and the wndproc gets as message the first time nccreate, and as the 2nd NCDestroy.
but why?
mfg Dennis
hi,
i want to use OpenGL in fullscreen, and i used a working example.
(masm syntax?)
but every time i will start the application, i will get a error.
I copied and compared.
there is everyting the same.
(except, that my strings and windowsproc is on an other Address.)
The other app works, but my app doesent.
the problem (i belive it is there) is in the CreateWindowEX funktion.
the params are both euqal, (except the strings and so on..)
the Create windowex funktion calls wndproc,
in the other (working) application, it get fist some messages, calls defwndproc and returns, till it get a WM_resize message.
my app gets a message, calls defwndproc, and returns.
the next message is a WM_NCDESTROY Message, it callls defwndproc and then returns to createwindowex.
but before createwindowex calls my code,
ollydbg says, that a invalid handel error coours.
but i belive, that every handel is ok,
or I'm wrong?
the other app get's a window handle
my app get's nothing
I get despaired.
i search for hours, (it's now have 4:42 am)
but cant find anything.
section ".code" readable executable
proc CreateWnd,_width,_heigth,_bits
mov eax,[_width]
mov ebx,[_heigth]
mov ecx,[_bits]
mov [width],eax
mov [height],ebx
mov [bits],ecx
invoke GetModuleHandle,0
mov [handel],eax
mov [wc.lpfnWndProc],Wndproc
mov [wc.hInstance],eax
mov [wc.cbWndExtra],0
mov [wc.cbWndExtra],0
mov [wc.style], 0x23 ;HREDRAW | VREDRAW | OWNDC
mov [wc.lpszClassName],_class
invoke LoadIcon,0,IDI_WINLOGO
mov [wc.hIcon],eax
invoke LoadCursor,0,IDC_ARROW
mov [wc.hCursor],eax
mov [wc.hbrBackground],0
mov [wc.lpszMenuName],0
invoke RegisterClass,wc
;invoke CreateWindowEx,0,[name],[name],WS_VISIBLE+WS_OVERLAPPEDWINDOW+WS_CLIPCHILDREN+WS_CLIPSIBLINGS,16,16,432,432,NULL,NULL,[wc.hInstance],NULL
;mov [hwnd],eax
call create_gl_window
msgloop:
invoke GetMessage,msg,0,0,0
or eax,eax
jz _loopend
invoke TranslateMessage,msg
invoke DispatchMessage,msg
jmp msgloop
_loopend:
invoke ExitProcess,[msg.wParam]
ret
endp
create_gl_window:
mov ecx,148 ;size.dmScreenSettings
mov edi,dmScreenSettings
xor eax,eax
rep stosb
mov ax,0x94
mov [dmScreenSettings.dmSize],ax
mov ebx,[width]
mov [dmScreenSettings.dmPelsWidth],ebx
mov ecx,[height]
mov [dmScreenSettings.dmPelsHeight],ecx
mov eax,[bits]
mov [dmScreenSettings.dmBitsPerPel],eax
mov [dmScreenSettings.dmFields],0x001C0000
invoke ChangeDisplaySettings,dmScreenSettings,0x00000004;CDS_FULLSCREEN
invoke ShowCursor,0
mov eax,WS_EX_APPWINDOW
mov ebx,WS_POPUP or WS_CLIPSIBLINGS or WS_CLIPCHILDREN
invoke CreateWindowEx,eax,_class,_title,ebx,0,0,[height],[width],0,0,[wc.hInstance],0
mov [hwnd],eax
invoke GetDC,[hwnd]
mov [hdc],eax
mov edi,pfd
mov ecx,sizeof.PIXELFORMATDESCRIPTOR shr 2
xor eax,eax
rep stosd
mov [pfd.nSize],sizeof.PIXELFORMATDESCRIPTOR
mov [pfd.nVersion],1
mov [pfd.dwFlags],PFD_SUPPORT_OPENGL+PFD_DOUBLEBUFFER+PFD_DRAW_TO_WINDOW
mov [pfd.dwLayerMask],PFD_MAIN_PLANE
mov [pfd.iPixelType],PFD_TYPE_RGBA
mov eax,[bits]
mov [pfd.cColorBits],al
mov [pfd.cDepthBits],16
mov [pfd.cAccumBits],0
mov [pfd.cStencilBits],0
invoke ChoosePixelFormat,[hdc],pfd
invoke SetPixelFormat,[hdc],eax,pfd
invoke wglCreateContext,[hdc]
mov [hrc],eax
invoke wglMakeCurrent,[hdc],[hrc]
invoke ShowWindow,[hwnd],5 ;SW_SHOW
invoke SetForegroundWindow,[hwnd]
invoke SetFocus,[hwnd]
ret
proc Wndproc,hwnd,wmsg,wparam,lparam
push ebx esi edi
;cmp [wmsg],WM_TIMER
;je .timer
;cmp [wmsg],WM_CREATE
;je .wmcreate
cmp [wmsg],WM_SIZE
je .wmsize
;cmp [wmsg],WM_ACTIVATEAPP
;je .wmactivateapp
cmp [wmsg],WM_PAINT
je .wmpaint
cmp [wmsg],WM_KEYDOWN
je .wmkeydown
cmp [wmsg],WM_KEYUP
je .wmkeyup
;cmp [wmsg],WM_DESTROY
;je .wmdestroy
.defwndproc:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
jmp .finish
.wmpaint:
invoke glClear,GL_COLOR_BUFFER_BIT
invoke glRotatef,[theta],0.0,0.0,1.0
invoke glBegin,GL_QUADS
invoke glColor3f,1.0,0.1,0.1
invoke glVertex3f,-0.6,-0.6,0.0
invoke glColor3f,0.1,0.1,0.1
invoke glVertex3f,0.6,-0.6,0.0
invoke glColor3f,0.1,0.1,1.0
invoke glVertex3f,0.6,0.6,0.0
invoke glColor3f,1.0,0.1,1.0
invoke glVertex3f,-0.6,0.6,0.0
invoke glEnd
invoke SwapBuffers,[hdc]
xor eax,eax
jmp .finish
.wmsize:
mov eax,[lparam]
mov ebx,eax
and eax,0ffffh
shr ebx,16
mov [width],eax
mov [height],ebx
call ReSizeGLScene
xor eax,eax
jmp .finish
.wmkeyup:
jmp .finish
.wmkeydown:
mov eax,[msg.wParam]
invoke write,1,msg.wParam,1
;cmp [wparam],VK_NUMPAD0
;je .VK_NUMPAD0
;cmp [wparam],VK_NUMPAD1
;je .VK_NUMPAD1
cmp eax,VK_ESCAPE
jne .defwndproc
invoke PostQuitMessage
.finish:
xor eax,eax
pop edi esi ebx
ret
endp
ReSizeGLScene:
cmp [height],0
jne ReSizeGLScene1
inc [height]
ReSizeGLScene1:
invoke glViewport,0,0,[width],[height]
invoke glMatrixMode,GL_PROJECTION
invoke glLoadIdentity
fild dword[width]
fild dword[height]
fdivp st1,st0
fstp qword[_aspd]
;push _100d0
;push _100d1
;push _01d0
;push _01d1
push dword [_aspd+4]
push dword [_aspd]
;push _45d0
;push _45d1
invoke gluPerspective,[f_vars],[f_vars+4],[_aspd],[_aspd+4],[f_vars+8],[f_vars+12],[f_vars+16],[f_vars+20]
invoke glMatrixMode,GL_MODELVIEW
invoke glLoadIdentity
ret
proc Redraw
[will comming soon]
endp
proc noop
nop
ret
endp
section ".data" readable writeable
_aspd:
dq 0
f_vars:
dq 100.0,0.1,45.0
theta GLfloat 0.6
hinst dd 0
width dd 0
height dd 0
bits dd 0
dmScreenSettings Devmode
hwnd dd 0
handel dd 0
wc WNDCLASS 0,Wndproc,0,0,0,0,0,0,0,0
hdc dd 0
hrc dd 0
msg MSG
rc RECT
pfd PIXELFORMATDESCRIPTOR
_title db 'OpenGL Chaoscode',0
_class db 'Chaoscode_opengl',0
section '.idata' import data readable writeable
[imports everything is need]
and here's the working app
; Assembly conversion of NeHe's openGL tutorial done by FooLman
;
.386
.model flat,STDCALL
locals
include win32.inc
include addwin32.inc
include gl.inc
include glu.inc
L equ <LARGE>
extrn MessageBoxA:PROC
MessageBox equ <MessageBoxA>
extrn ChangeDisplaySettingsA:PROC
ChangeDisplaySettings equ <ChangeDisplaySettingsA>
extrn ShowCursor:PROC
extrn wglMakeCurrent:PROC
extrn wglDeleteContext:PROC
extrn ReleaseDC:PROC
extrn DestroyWindow:PROC
extrn LoadIconA:PROC
LoadIcon equ <LoadIconA>
extrn LoadCursorA:PROC
LoadCursor equ <LoadCursorA>
extrn GetModuleHandleA:PROC
GetModuleHandle equ <GetModuleHandleA>
extrn RegisterClassA:PROC
RegisterClass equ <RegisterClassA>
extrn CreateWindowExA:PROC
CreateWindowEx equ <CreateWindowExA>
extrn GetDC:PROC
extrn ChoosePixelFormat:PROC
extrn SetPixelFormat:PROC
extrn wglCreateContext:PROC
extrn ShowWindow:PROC
extrn SetForegroundWindow:PROC
extrn SetFocus:PROC
extrn DefWindowProcA:PROC
extrn PostQuitMessage:PROC
extrn TranslateMessage:PROC
extrn DispatchMessageA:PROC
DispatchMessage equ <DispatchMessageA>
extrn SwapBuffers:PROC
extrn PeekMessageA:PROC
PeekMessage equ <PeekMessageA>
DefWindowProc equ <DefWindowProcA>
; Numeric Data constants
_100d0 equ 1079574528
_100d1 equ 0 ;100.0
_01d0 equ 1069128089
_01d1 equ -1717986918 ;0.1
_45d0 equ 40468000h ;45.0
_45d1 equ 0
_1d0 equ 1072693248
_1d1 equ 0 ;1.0
_05 equ 1056964608 ; 0.5
.data
RCF db 'Release Of DC And RC Failed.',0
RRC db 'Release Rendering Context Failed.',0
RDC db 'Release Device Context Failed.',0
CNR db 'Could Not Release hWnd.',0
FTR db 'Failed To Register The Window Class.',0
FSNS db 'The Requested Fullscreen Mode Is Not Supported By',010,'Your Video Card. Use Windowed Mode Instead?',0
PWC db 'Program Will Now Close.',0
CGLC db 'Can''t Create a GL Device Context',0
CFPF db 'Can''t Find A Suitable PixelFormat.',0
CSPF db 'Can''t Set The PixelFormat',0
CCRC db 'Can''t Create A GL Rendering Context.',0
CARC db 'Can''t Activate The GL Rendering Context.',0
INF db 'Initalization Failed.',0
RIF db 'Would You Like To Run In FullScreen Mode?',0
WT db 'NeHE''s OpenGL Framework',0
SFS db 'Start FullScreen?',0
NGL db 'NeHe GL',0
WCE db 'Window Creation Error.',0
SDE db 'SHUTDOWN '
ER db 'ERROR',0
ClassName db 'OpenGL',0;
_aspd dq ?
active db ?
fullscreen dw ?
hDC dd ?
hRC dd ?
hWnd dd ?
PixelFormat dd ?
done db ?
keys db 256 dup (?)
wc WNDCLASS <?>
dmScreenSettings DEVMODE <?>
pfd PIXELFORMATDESCRIPTOR <?>
msg MSGSTRUCT <?>
wTitle dd ?
width dd ?
height dd ?
bits dd ?
fullscreenflag dd ?
hInstance dd ?
.code
ReSizeGLScene proc
cmp [height],0
jne @@1
inc [height]
@@1:
push height
push width
push L 0
push L 0
call glViewport
push L GL_PROJECTION
call glMatrixMode
call glLoadIdentity
fild width
fild height
fdivp st(1),st
fstp _aspd
push _100d0
push _100d1
push _01d0
push _01d1
push dword ptr [_aspd+4]
push dword ptr [_aspd]
push _45d0
push _45d1
call gluPerspective
push L GL_MODELVIEW
call glMatrixMode
call glLoadIdentity
ret
ReSizeGLScene endp
InitGL proc
push L GL_SMOOTH
call glShadeModel
push _05
push L 0
push L 0
push L 0
call glClearColor
push _1d0
push _1d1
call glClearDepth
push GL_DEPTH_TEST
call glEnable
push GL_LEQUAL
call glDepthFunc
push GL_NICEST
push GL_PERSPECTIVE_CORRECTION_HINT
call glHint
xor eax,eax
ret
InitGL endp
DrawGLScene proc
push L (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
call glClear
call glLoadIdentity
xor eax,eax
ret
DrawGLScene endp
KillGLWindow proc
mov ax,[fullscreen]
or ax,ax
jz @@1
push 0
push L 0
call ChangeDisplaySettings
push 1
call ShowCursor
@@1:
mov eax, hRC
or eax,eax
jz @@2
push L 0
push L 0
call wglMakeCurrent
or eax,eax
jnz @@3
push MB_OK or MB_ICONINFORMATION
push offset SDE
push offset RCF
push L 0
call MessageBox
@@3:
push hRC
call wglDeleteContext
or ax,ax
jnz @@4
push MB_OK or MB_ICONINFORMATION
push offset SDE
push offset RRC
push L 0
call MessageBox
@@4:
xor eax,eax
mov [hRC],eax
@@2:
mov eax,[hDC]
or eax,eax
jz @@5
push hDC
push hWnd
call ReleaseDC
or eax,eax
jnz @@5
push MB_OK or MB_ICONINFORMATION
push offset SDE
push offset RDC
push L 0
call MessageBox
xor eax,eax
mov [hDC],eax
@@5:
mov eax,hWnd
or eax,eax
jz @@6
push hWnd
call DestroyWindow
or eax,eax
jnz @@6
push MB_OK or MB_ICONINFORMATION
push offset SDE
push offset CNR
push L 0
call MessageBox
xor eax,eax
mov [hWnd],eax
@@6:
ret
KillGLWindow endp
CreateGLWindow proc
mov eax,[fullscreenflag]
mov [fullscreen],ax
push L 0
call GetModuleHandle
mov hInstance,eax
mov [wc.clsStyle], CS_HREDRAW or CS_VREDRAW or CS_OWNDC
mov [wc.clsLpfnWndProc], offset WndProc
mov [wc.clsCbClsExtra],0
mov [wc.clsCbWndExtra],0
mov [wc.clsHInstance],eax
push IDI_WINLOGO
push L 0
call LoadIcon
mov [wc.clsHIcon],eax
push IDC_ARROW
push L 0
call LoadCursor
mov [wc.clsHCursor],eax
mov [wc.clsHbrBackground],0
mov [wc.clsLpszMenuName],0
mov [wc.clsLpszClassName],offset ClassName
push offset wc
call RegisterClass
or ax,ax
jnz @@1
push MB_OK or MB_ICONEXCLAMATION
push offset ER
push offset FTR
push L 0
call MessageBox
mov ax,1
ret
@@1:
mov ax,fullscreen
or ax,ax
jz @@2
mov ecx,size dmScreenSettings
lea edi,dmScreenSettings
xor ax,ax
rep stosb
mov ax,size dmScreenSettings
mov [dmScreenSettings.dmSize],ax
mov ebx,width
mov [dmScreenSettings.dmPelsWidth],ebx
mov ecx,height
mov [dmScreenSettings.dmPelsHeight],ecx
mov eax,bits
mov [dmScreenSettings.dmBitsPerPel],eax
mov [dmScreenSettings.dmFields],DM_BITSPERPEL or DM_PELSWIDTH or DM_PELSHEIGHT;
push L CDS_FULLSCREEN
push offset dmScreenSettings
call ChangeDisplaySettings
or ax,ax
jz @@2
push L MB_YESNO or MB_ICONEXCLAMATION
push offset NGL
push offset FSNS
push L 0
call MessageBox
cmp ax,IDYES
jne @@3
xor ax,ax
mov fullscreen,ax
jmp @@2
@@3:
push L MB_OK or MB_ICONSTOP
push offset ER
push offset PWC
push L 0
call MessageBox
mov ax,1
ret
@@2:
mov ax,fullscreen
or ax,ax
jz @@4
push L 0
call ShowCursor
mov eax,WS_EX_APPWINDOW
mov ebx,WS_POPUP
jmp @@5
@@4:
mov eax,WS_EX_APPWINDOW or WS_EX_WINDOWEDGE
mov ebx,WS_OVERLAPPEDWINDOW
@@5:
or ebx, WS_CLIPSIBLINGS or WS_CLIPCHILDREN
push L 0
push [hInstance]
push L 0
push L 0
push height
push width
push L 0
push L 0
push ebx
push wTitle
push offset ClassName
push eax
call CreateWindowEx
or eax,eax
jnz @@6
call KillGLWindow
push MB_OK or MB_ICONEXCLAMATION
push offset ER
push offset WCE
push L 0
call MessageBox
mov ax, -1
ret
@@6:
mov [hWnd],eax
mov ebx, size PIXELFORMATDESCRIPTOR
mov ecx,ebx
xor ax,ax
mov edi,offset pfd
rep stosb
mov [pfd.nSize],bx
mov [pfd.nVersion],1
mov [pfd.dwFlags],PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER
mov [pfd.iPixelType],PFD_TYPE_RGBA
mov eax,bits
mov [pfd.cColorBits],al
mov [pfd.cDepthBits],16
mov [pfd.iLayerType],PFD_MAIN_PLANE
push hWnd
call GetDC
or eax,eax
jnz @@7
call KillGLWindow
push MB_OK or MB_ICONEXCLAMATION
push offset ER
push offset CGLC
push L 0
call MessageBox
mov ax,-1
ret
@@7:
mov hDC,eax
push offset pfd
push eax
call ChoosePixelFormat
or eax,eax
jnz @@8
push MB_OK or MB_ICONEXCLAMATION
push offset ER
push offset CFPF
push L 0
call MessageBox
mov ax,-1
ret
@@8:
mov PixelFormat,eax
push offset pfd
push eax
push [hDC]
call SetPixelFormat
or eax,eax
jnz @@9
call KillGLWindow
push MB_ICONEXCLAMATION or MB_OK
push offset ER
push offset CSPF
push L 0
call MessageBox
mov ax,-1
ret
@@9:
push [hDC]
call wglCreateContext
or eax,eax
jnz @@10
call KillGLWindow
push MB_OK or MB_ICONEXCLAMATION
push offset ER
push offset CCRC
push L 0
call MessageBox
mov ax,-1
ret
@@10:
mov hRC,eax
push eax
push [hDC]
call wglMakeCurrent
or eax,eax
jnz @@11
call KillGLWindow
push MB_ICONEXCLAMATION or MB_OK
push offset ER
push offset CARC
push L 0
call MessageBox
mov eax,-1
ret
@@11:
push L SW_SHOW
push [hWnd]
call ShowWindow
push [hWnd]
call SetForegroundWindow
push [hWnd]
call SetFocus
call ReSizeGLScene
call InitGL
or eax,eax
jz @@12
call KillGLWindow
push MB_ICONEXCLAMATION or MB_OK
push offset ER
push offset INF
push L 0
call MessageBox
mov eax,-1
ret
@@12:
xor eax,eax
ret
CreateGLWindow endp
WndProc proc uses ebx edi esi, hwnd : DWORD, wmsg : DWORD, wparam: DWORD, lparam:DWORD
mov eax,[wmsg]
cmp eax,WM_ACTIVATE
je _wmactivate
cmp eax,WM_SYSCOMMAND
je _wmsyscommand
cmp eax,WM_CLOSE
je _wmclose
cmp eax,WM_KEYDOWN
je _wmkeydown
cmp eax,WM_KEYUP
je _wmkeyup
cmp eax,WM_SIZE
je _wmsize
@@3:
push lparam
push wparam
push wmsg
push hwnd
call DefWindowProc
ret
_wmactivate:
mov eax,[wparam]
or ah,ah
jz @@1
mov ah,0
mov active,ah
xor eax,eax
ret
@@1:
mov ah,1
mov active,ah
xor eax,eax
ret
_wmsyscommand:
mov ebx,wparam
cmp ebx,SC_SCREENSAVE
je @@2
cmp ebx,SC_MONITORPOWER
je @@2
jmp @@3
@@2:
xor eax,eax
ret
_wmclose:
push L 0
call PostQuitMessage
xor eax,eax
ret
_wmkeydown:
mov ebx,wparam
mov byte ptr [keys+ebx],1
xor eax,eax
ret
_wmkeyup:
mov ebx,wparam
mov byte ptr [keys+ebx],0
xor eax,eax
ret
_wmsize:
mov eax,lparam
mov ebx,eax
and eax,0ffffh
shr ebx,16
mov [width],eax
mov [height],ebx
call ReSizeGLScene
xor eax,eax
ret
WndProc endp
start:
xor eax,eax
mov [fullscreen],ax
inc ax
mov [active],al
mov [done],al
push MB_YESNO or MB_ICONQUESTION
push offset SFS
push offset RIF
push L 0
call MessageBox
cmp eax,IDNO
je @@1
mov eax,1
mov [fullscreen],ax
@@1:
mov ax,[fullscreen]
mov [fullscreenflag],eax
mov eax,16
mov bits,eax
mov eax,480
mov height,eax
mov eax,640
mov width,640
lea eax,WT
mov wTitle,eax
call CreateGLWindow
or eax,eax
jz @@2a
ret
@@2a:
@@2:
mov al,done
or al,al
jz @@3
push PM_REMOVE
push L 0
push L 0
push L 0
push offset msg
call PeekMessage
or eax,eax
jz @@4
mov eax,[msg.msMESSAGE]
cmp eax,WM_QUIT
jne @@5
@@7:
mov al,0
mov done,al
jmp @@2
@@5:
push offset msg
call TranslateMessage
push offset msg
call DispatchMessage
jmp @@2
@@4:
mov al,[keys+27]
or al,al
jnz @@7
mov al,active
or al,al
jz @@6
call DrawGLScene
or al,al
jnz @@7
@@6:
push hDC
call SwapBuffers
jmp @@2
@@3:
call KillGLWindow
ret
ends
public WndProc
end start
|