tags:

views:

279

answers:

6

LRESULT result = ::SendMessage(hWnd, s_MaxGetTaskInterface, (WPARAM)&pUnkReturn, 0);

The value of result after the call is 0

I expect it to return with a valid value of pUnkReturn , but it returns with a NULL value .

Necessary Information before this call :

const UINT CMotionUtils::s_MaxGetTaskInterface = RegisterWindowMessage(_T("NI:Max:GetTaskInterface"));

The value of s_MaxGetTaskInterface i get here is 49896 .

The value of hWnd is also proper . I checked that with Spy++ ( Visual Studio tool ) .

Microft Spy++ Messages window shows me the following for this window .

<00001> 009F067C S message:0xC2E8 [Registered:"NI:Max:GetTaskInterface"]wParam:0224C2D0 lParam:00000000 <00002> 009F067C S message:0xC2E8 [Registered:"NI:Max:GetTaskInterface"]lResult:00000000

Please help me to get a valid address stored in pUnkReturn after the call .

A: 

When I Googled for NI:Max:GetTaskInterface I couldn't find anything. In general, how a window will handle a given message depends entirely on the window concerned. Does the window (specified by hWnd) even support the NI:Max:GetTaskInterface message?

Chris Jester-Young
A: 

You're going to have to provide more information - what is "GetTaskInterface" (Google provides no results). SendMessage will return with whatever value is returned from the WndProc that handles the message "s_MaxGetTaskInterface". If it's not handled, you will get zero back and your pointer will still be NULL.

Mark Ingram
A: 

You'll need to tell us what pUnkReturn is and how it's defined.

You'll also need to tell us what the handler for s_MaxGetTaskInterface is expecting.

If you expect the handler to populate whatever is pointed to by pUnkReturn, then you'll need to call SendMessage with (WPARAM)pUnkReturn, however if the handler returns a pointer, then call as you're doing now.

Alan
+1  A: 

I think the & in &pUnkReturn is needed, based on the hungarian prefix. I expect pUnkReturn to have type IUnknown*. The message receiver will provide the IUnknown*. The address where it will store that IUnknown* is an IUnknown**. Hence, this code passes in &pUnkReturn and the message receiver writes to *(IUnknown**)wParam.

MSalters
+1  A: 

Is the destination hWnd in the same process? If not, you won't be able to pass (or return) a pointer through the message. Note that Windows implements marshalling for built-in messages.

Roger Lipscombe
A: 

The problem is not with how you are calling SendMessage(). The problem is in your implementation of the message handler for the "NI:Max:GetTaskInterface" registered message.

The value that SendMessage() returns is the same as the value that is returned from your message handler. If you need pUnkReturn to be an out-val, then your message handler must populate it.

Let's see the code for your message handler.

John Dibling