News:

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

Dialog in Dll

Started by LechooY, November 27, 2006, 09:30:08 PM

Previous topic - Next topic

LechooY

Hello all!

I have problem again :(

My dll
DllEntry proc hInst:HINSTANCE, reason:DWORD, reserved1:DWORD

mov eax, hInst
mov hDllInstance, eax
.if reason==DLL_PROCESS_ATTACH
invoke InitCommonControls
.elseif reason==DLL_PROCESS_DETACH

.endif
ret
DllEntry Endp

DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
.if uMsg==WM_INITDIALOG

.elseif uMsg==WM_COMMAND

.elseif uMsg==WM_CLOSE
invoke EndDialog, hWin, 0
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgProc endp

Aboutproc proc
invoke DialogBoxParam, hDllInstance, 1000, NULL, addr DlgProc, NULL
ret
Aboutproc endp



1000 DIALOGEX 6,6,229,115
FONT 8,"MS Sans Serif",400,0
STYLE 0x10CA0800
EXSTYLE 0x00000000
BEGIN
  CONTROL "Exit",1001,"Button",0x50010000,20,12,42,15,0x00000000
END



In DLL resource is dialog but when I call to Aboutproc then nothing show. Why Dialog is not show? I have no idea...

PBrennick

One thing I noticed at first glance is that your DLL is missing something that is a necessary requirement for all DLLs. It is the value in EAX You need to do something similar to the following:


DllEntry proc hInst:HINSTANCE, dReason:DWORD, reserved1:DWORD
    mov eax, dReason
    .if eax == DLL_PROCESS_ATTACH
      xor eax, eax
      inc eax
    .elseif eax == DLL_PROCESS_DETACH
      xor eax, eax
      inc eax
    .endif
    ret
DllEntry Endp

DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
.if uMsg==WM_INITDIALOG

.elseif uMsg==WM_COMMAND

.elseif uMsg==WM_CLOSE
invoke EndDialog, hWin, 0
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgProc endp

Aboutproc proc
invoke DialogBoxParam, hDllInstance, 1000, NULL, addr DlgProc, NULL
ret
Aboutproc endp

End DllEntry



Pay close attention to the values of eax on exit, they are VERY important.

Finally you need to declare the Aboutproc procedure in a def file or it will never be exported

If you do not know how to do these things we can help.

EDIT: There is no need to initialize the common controls in the DLL. They are not being used and it would be better to call that in the main program instead of the DLL. Having said that, you can use my example exactly as written. If you really want to initialize the common controls move that invoke to Aboutproc.

Your def file should look like the following:
Quote
LIBRARY MyDLL
EXPORTS DlgProc
EXPORTS Aboutproc

Change the LIBRARY name to whatever is the name of the DLL file.

EDIT: (Again) Make sure you add the def file to your link command in the batch file.

Quote
/DEF:MyDLL.def

Again, change the name of the def file in the link command to whatever the name actually is. I am using MyDLL just as an example, but you could use that.

Hope this helps,
Paul

The GeneSys Project is available from:
The Repository or My crappy website

LechooY

Hello PBrennick but I konw that all. Functions Aboutproc and DlgProc is export. When I add to function Aboutproc MessageBox then its show but Dialog not. Its My problem :)

Aboutproc proc
invoke MessageBox,0,addr szTest,addr szTest,MB_OK
invoke InitCommonControls
invoke DialogBoxParam, hDllInstance, 1000, NULL, addr DlgProc, NULL
ret
Aboutproc endp

LechooY

Ok I was fund bug  :dazzled:

Thanks everyone!  :U

P1

Quote from: LechooY on November 28, 2006, 09:24:54 AMOk I was fund bugĀ  :dazzled:
Please do tell.   :eek

I was wondering, if it was in the left out code, that did not get posted?

Regards,  P1  :8)

donkey

Hi all,

Paul is correct about InitCommonControls, you could create a very bad lock up by calling it in the DLL entry procedure. You should avoid calling anything but Kernel32 functions in DLLMain and only those that do not load other libraries to avoid cross dependancies. Microsoft has an paper about this...



[attachment deleted by admin]
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable