lapucca
asked on
How do I get my previously stored itemdata back after I call using CB_GETITEMDATA?
lResult = SendMessage(hwndPrimGroup, CB_GETITEM DATA, 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.
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.
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.
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\UnityExtProper ty\CUserPa ge.Cpp 1832
LRESULT lResult;
lResult = (wstring*)SendMessage(hwnd PrimGroup, CB_GETITEM DATA, userDataIter->groupIndex,0 );
Error 1 error C2440: '=' : cannot convert from 'std::wstring *' to 'LRESULT' c:\Projects\UnityExtProper
LRESULT lResult;
lResult = (wstring*)SendMessage(hwnd
ASKER
Do I applied reinterpret_cast<> to the lResult? Can you give me a code example? Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
lResult = (wstring*)SendMessage(hwnd
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.