MinnisotaFreezing
Programmer
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
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