[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Passing Pointer to Pointer in SendMessage

Posted on 2007-11-27
10
Medium Priority
?
938 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 1500 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
Industry Leaders: 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

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!

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

656 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