Hi,
I am trying to create a DLL that will display a window with a Progress bar. I am able to call the DLL and display the window but when I close that window it close the entire APP. Here is the code.


include windows.inc

include kernel32.inc
include user32.inc
include comctl32.inc

includelib kernel32.lib
includelib user32.lib
includelib comctl32.lib

IDC_PROGRESS equ 1 ; control ID




.DATA
ClassName db "ProgressDialog",0
AppName db "Progress Dialog",0
ProgressClass db "msctls_progress32",0 ;


.data?
hInstance HINSTANCE ?
hwndProgress dd ?
CurrentStep dd ?


.code

DllEntry PROC hInst:HINSTANCE, reason:DWORD, lreserved:DWORD
.if reason==DLL_PROCESS_ATTACH
push hInst
pop hInstance
call ShowWin
.endif

mov eax,TRUE
ret
DllEntry ENDP

ShowWin proc
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND

invoke InitCommonControls

mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground,1
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,OFFSET ClassName

invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,eax

invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax

invoke RegisterClassEx, addr wc


invoke CreateWindowEx,\
NULL,\
ADDR ClassName,\
ADDR AppName,\
WS_SYSMENU,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
250,\
70,\
NULL,\
NULL,\
hInstance,\
NULL

mov hwnd,eax


invoke ShowWindow, hwnd,SW_SHOWDEFAULT


invoke UpdateWindow, hwnd

invoke CreateWindowEx,\
NULL,\
ADDR ProgressClass,\
NULL,\
WS_CHILD+WS_VISIBLE,\
23,\
13,\
200,\
15,\
hwnd,\
IDC_PROGRESS,\
hInstance,\
NULL

mov hwndProgress,eax

mov eax,10000 ;set up the
shl eax,16 ;max range

invoke SendMessage,hwndProgress,PBM_SETRANGE,0,eax
invoke SendMessage,hwndProgress,PBM_SETSTEP,1,0

.while (CurrentStep < 10000)
invoke SendMessage,hwndProgress,PBM_STEPIT,0,0
inc CurrentStep
.endw

.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam ; return exit code in eax

invoke ExitProcess,eax

ShowWin endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp


End DllEntry


;-------------------------------------------------------------------------------------
; DLLWindow.def
;-------------------------------------------------------------------------------------
;LIBRARY DLLWindow
;EXPORTS ShowWin
;
;this is what my def file looks like
;---------------------------------------------------------------------------------------

Thanks,
Barry
Posted on 2002-11-23 14:00:06 by bgong68
At the first glance It looks like invoke ExitProcess, eax.
That is killing your app. Comment it out and try again.

I didn't give much thought to this however so that may not be the solution but it's possible.
Posted on 2002-11-23 14:34:39 by Milos
Hi Milos,
I commentted out that line but now I get that message from windows that THIS PROGRAM HAS PERFORMED AN ILLEGAL OPERATION AND WILL BE SHUT DOWN message. Any more ideas? Thanks for your time and effort.
Barry
Posted on 2002-11-23 16:42:27 by bgong68
Try commenting out the "invoke ExitProcess, eax" and replacing it with "ret"

Just removing, the processor will carry on executing, which happens in this case to be your WndProc function (although you won't have called it, so the parameters it will try to reference will be bad).

"ExitProcess" is definitely the culprit here, it makes the process (i.e. the app) exit.

Mirno
Posted on 2002-11-23 19:37:31 by Mirno
Hi Mirno,
Thank you VERY much. I replaced the ExitProcess with ret and it worked fine. Thanks for taking the time to help me.
Thanks,
Barry ^_^
Posted on 2002-11-23 21:28:07 by bgong68