Link to home
Start Free TrialLog in
Avatar of lapucca
lapucca

asked on

How do I get my previously stored itemdata back after I call using CB_GETITEMDATA?

lResult = SendMessage(hwndPrimGroup,CB_GETITEMDATA, userDataIter->groupIndex,0);

Complier complained if I use a wstring instead of lResult;  Now, after this how do I get my data previously stored using CB_SETITEMDATA?  I thought this is supposed to return the pointer to a string that I previously stored?

Thanks.
Avatar of AlexFM
AlexFM

Use casting:

lResult = (wstring*)SendMessage(hwndPrimGroup,CB_GETITEMDATA, userDataIter->groupIndex,0);

Item data is your responsibility. You can keep number or pointer there. In the case you keep pointer, you make casting using both CB_SETITEMDATA and CB_GETITEMDATA.
ItemData pointers in ComboBoxes are the rawest of raw pointers, they doing even have their correct static type. As pointed out by AlexFM you need to reinterpret_cast<> (that's what the C-style cast is doing) to tell the compiler what static type is being pointed to. Bearing in mind that you also need to deal with the memory management for this data, I'd elect to keep these strings in (say) a vector which is part of the dialog class composition. If you take the vector approach, there is no point in using ItemData pointers, because you can get the string by reading it from the appropriate index in the vector. Stylistically, I'd say the class composition approach was better, because you are doing away with reinterpret casting, which is a nasty error-prone kind of thing that C-programmers do.
Avatar of lapucca

ASKER

I tried it but it didn't work.  I got error from the compiler:

Error      1      error C2440: '=' : cannot convert from 'std::wstring *' to 'LRESULT'      c:\Projects\UnityExtProperty\CUserPage.Cpp      1832


LRESULT lResult;
lResult = (wstring*)SendMessage(hwndPrimGroup,CB_GETITEMDATA, userDataIter->groupIndex,0);
Avatar of lapucca

ASKER

Do I applied  reinterpret_cast<>  to the lResult?  Can you give me a code example?  Thank you.
ASKER CERTIFIED SOLUTION
Avatar of rstaveley
rstaveley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial