Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fairly simple pointer problem 1

Status
Not open for further replies.

MinnisotaFreezing

Programmer
Jun 21, 2001
120
KR
Hey all,

I'm trying to pass a pointer to a class through the SendMessage function, and I am running into some problems, probably because I don't fully understand pointers. Here is what I am trying to do.

Declare a pointer to my class
PurchaseOrderSet * pPOSet;
Set that pointer to a valid instance of the class
pPOSet = &MyOrder;
Now the pointer should have the address in memory of where that class MyOrder resides.
Now I cast the pointer to a WPARAM so I can send it with SendMessage
Param = (WPARAM)pPOSet;
pShipTo->SendMessage(WM_LOAD, wParam, lParam);

On the other side I declare a pointer to my class, and set it to a new instance of my class
PurchaseOrderSet * NewpPOSet;
NewpPOSet = new PurchaseOrderSet();

For a test, I cast the wParam to LPTSTR to check the value
LPTSTR buff;
buff = (LPTSTR)wParam;

At this point, through the debugger, I see my buff is pointing to the same location in memory as my original pPOSet. According to my thinking, I should be able to tell my NewpPOSet not to point at the new address, but at the original that was passed in wParam, like so:
NewpPOSet = buff;
As I'm sure you all know, that does not work. Nor does
NewpPOSet = (PurchaseOrderSet)buff;
My variable NewpPOSet is pointing to a class PurchaseOrderSet, and I want it to point to a different one, one which I have the address to, and I feel I should be able to do this, but I cannot. I should be able to just swap the values. Can anyone tell me where I am going wrong?

I'm pretty sure my problem lies in the casting, in that the compiler doesn't know how to go from a LPTSTR to a PurchaseOrderSet, but I don't quite see how that matters. An address in memory doesn't have a type, it is just a 32 bit address.

Anyway, I hope this makes sense.

CJB
 
Param = (WPARAM)pPOSet;
pShipTo->SendMessage(WM_LOAD, wParam, lParam);

should be written:

pShipTo->SendMessage(WM_LOAD, (WPARAM)pPOSet, lParam);

AND

PurchaseOrderSet * NewpPOSet;
NewpPOSet = new PurchaseOrderSet();
should be followed by

NewpPOSet=(PurchaseOrderSet *)wParam;


Now NewpPOSet holds the pointer transmited through send message. Anyway I remind you that is not advisable to send pointers to MFC objects to anothwer aplication/module that does not implement MFC.

HTH,


s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top