[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-04-30
8
Medium Priority
?
810 Views
Last Modified: 2010-05-18
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.
0
Comment
Question by:lapucca
  • 2
  • 2
  • 2
6 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 16575389
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.
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 16575842
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.
0
 

Author Comment

by:lapucca
ID: 16578695
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);
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:lapucca
ID: 16578702
Do I applied  reinterpret_cast<>  to the lResult?  Can you give me a code example?  Thank you.
0
 
LVL 17

Accepted Solution

by:
rstaveley earned 1000 total points
ID: 16579640
You have an LRESULT on the left hand side. You need a wstring*, or to dereference the wstring to get a copy of the value or a reference to the string.

Here's how to get references:

(1) Using C-style cast:

    const wstring& yourstring = *(wstring*)SendMessage(hwndPrimGroup,CB_GETITEMDATA, userDataIter->groupIndex,0);

(2) Using C++ reinterpret cast:

    const wstring& yourstring = *reinterpret_cast<wstring*>(SendMessage(hwndPrimGroup,CB_GETITEMDATA, userDataIter->groupIndex,0));

The C-style cast is really a reinterpret_cast<> in disguise. Windows programmers do a lot of reinterpret casting, and often favour the C-style cast because of its brevity. I'm not really a Windows programmer.

However, my point was that you should avoid reinterpret casts altogether, if you can, and index into your vector, since you have a vector with the strings anyhow. ItemDataPtr is the ugliest void* (i.e. typeless) raw pointer and is therefore a recipe for disaster.
0
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 1000 total points
ID: 16579692
LRESULT lResult;
lResult = (wstring*)SendMessage(hwndPrimGroup,CB_GETITEMDATA, userDataIter->groupIndex,0);

Should be:

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

834 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