News:

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

SendMessage problem

Started by minor28, August 18, 2009, 10:31:50 AM

Previous topic - Next topic

minor28

I have an exe and a dll. I want to send a message from the dll to the exe to get a pointer to an exe structure.

Exe code

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

.elseif eax==WM_COMMAND

.elseif eax==WM_MYCOMMAND
mov eax,offset Mystruct
ret
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgProc endp


Dll code. hWin is the handle to exe dialog window.

invoke SendMessage,hWin,WM_MYCOMMAND,0,0;
mov pMystruct,eax


Debugging this I can see the pointer loaded into eax in the DlgProc but the return value in the dll is 0. What am I doing wrong. How can I get the pointer?

Best regards

dedndave

i might try this approach...
make it a public symbol
then use GetProcAddress (may also be used for variables)
http://msdn.microsoft.com/en-us/library/ms683212(VS.85).aspx

Tedd

When a DLL is loaded into your process, it becomes part of the process space - it's not a separate entity, so you can't send it a message.
The only active entity is your window, so it must trigger any kind of action. Usually you want the DLL to do something with that struct, so at that point you call a function in the DLL and pass it the offset of the struct.
Alternatively, you could set up a callback function that returns whatever you like..

More information on what you're trying to achieve would be helpful.
No snowflake in an avalanche feels responsible.

japheth


I also want to make a wild guess:  :bg

Usage of WM_INITDIALOG tells me that it's not a window but a dialog proc.

The value returned by a dialog proc is used to tell the Window proc of the dialog box whether the message has been handled or not. To return a value to the SendMessage caller one has to use SetWindowLong( hwnd, DWL_MSGRESULT, <value> ).

minor28

Thanks for your help. japheth's wild guess is correct. It is a dialog application and the SetWindowLong did it. One learn something new every day.

Best regards :bg