Solved

Passing Pointer to Pointer in SendMessage

Posted on 2007-11-27
10
927 Views
Last Modified: 2013-11-20
Hello all,

I'm attempting to pass the address of a pointer as the LPARAM argument in SendMessage.
I need to have this argument return the (this) pointer of the object receiving the message.
I have the following (doesn't work)

class CClassA
{
     CCommon *pCommon;
}

CClassA::GetObjectPointer()
{
     SendMessage( m_hDlgToSendTo, UM_XXX, xxx, (LPARAM) &pCommon);
}

In the dialog DLL I have:

LRESULT CClassBDlg::OnWorkspaceModelMessage(WPARAM wParam, LPARAM lParam)
{
     . . .
     CCommon * pCommon = *((CCommon **) lParam);
     . . .
     pInterface = (CCommon *) this;
     lParam = (LPARAM) pInterface;
      . . .
}

What is the correct way to do this?

Thank you!
trishm
0
Comment
Question by:trishm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
10 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 20359467
You are passing the address of the pointer. Just use

class CClassA
{
     CCommon *pCommon;
}

CClassA::GetObjectPointer()
{
     SendMessage( m_hDlgToSendTo, UM_XXX, xxx, (LPARAM) pCommon);
}

LRESULT CClassBDlg::OnWorkspaceModelMessage(WPARAM wParam, LPARAM lParam)
{
     . . .
     CCommon * pCommon = ((CCommon **) lParam;
     . . .
     pInterface = (CCommon *) this;
     lParam = (LPARAM) pInterface;
      . . .
}

which should work fine (been there, done that).
0
 

Author Comment

by:trishm
ID: 20359618
jkr:

Sorry, that didn't work. After the call to SendMessage
     pInterface = 0xcdcdcdcd

When I pass:
     pCommon
instead of
     &pCommon
to SendMessage

the receiving function gets a bad lParam value:
     lParam = -89830280

0
 
LVL 86

Expert Comment

by:jkr
ID: 20359664
Sorry, that should be

   CCommon * pCommon = (CCommon *) lParam;

Is 'pCommon' initialized correctly when you call 'SendMessage()'?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:peetm
ID: 20359792
The thing you're sending this to is in the same process right?
0
 

Author Comment

by:trishm
ID: 20359869
jkr:

I initially caught the typo and changed it to your corrected version before I responded.
I did, however, add initialization of pCommon to NULL before SendMessage.

It didn't help. The only different is that the receiving function now receives
     lParam = 0 instead of lParam = -838473984
So, now
     CCommon * pCommon = (CCommon *) lParam;
assigns 0 to pCommon

After SendMessage
     pCommon = 0
I need a valid pointer to call a function in pCommon
     pCommon->DoSomething()





0
 

Author Comment

by:trishm
ID: 20359895
peetm:

No, they are in different DLLs.
0
 
LVL 86

Expert Comment

by:jkr
ID: 20359900
Different DLLs, but same process?
0
 

Author Comment

by:trishm
ID: 20359985
Yes, same process.

In a previous attempt, I  successfully retrieved the pointer I need with:
     pCommon = (CCommon *) SendMessage(m_hDlgToSendTo, xxxx, xxxx, NULL);
and returning the object pointer
     return (LRESULT) this

This gave me what I needed but I was instructed to pass a pointer to the pointer instead:
     SendMessage( ... ... ..., (LPARAM) &pCommon)

0
 

Author Comment

by:trishm
ID: 20360116
The objective is to get the pointer to "this" via an argument to SendMessage()
0
 

Author Comment

by:trishm
ID: 20367091
The following code gave me what I needed:

SendMessage(m_hDlgToSendTo, xxx, xxx, (LPARAM) &m_pCommon);

In the receiving dialog:

CCommon ** ppCommon = (CCommon **) lParam;

*ppCommon = this;
lParam = (LPARAM) ppCommon;

This returns a pointer to "this" in the LPARAM argument.

Thank you for your comments.
trishm


0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ mouse_event mouse look 7 112
Excel file not created as expected 7 94
Need some help with mailto 16 34
Adding items to a C# list incrementally 5 64
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question