How do I add CB_SETITEMDATA to a comboBox with wstring variable as the LPARAM?

Also, is it correct and OK to put the declaration of the wstring in side of this loop?  Currently, with this code I'm getting the following error message from the compiler.
Error      1      error C2440: 'initializing' : cannot convert from 'std::wstring *' to 'std::basic_string<_Elem,_Traits,_Ax>'      c:\Projects\UnityExtProperty\CUserPage.Cpp      884

//while (loop condition is true)

                                    // Add the context cn attribute
                                    std::wstring wsGroup = new wstring;
                                    wsGroup = (colSearchColumnDN.pADsValues->CaseIgnoreString);
                                    SendMessage(hwndPrimGroup,CB_SETITEMDATA, index, (LPARAM)T2CW(wsGroup.c_str()));
                                    padsSearchContainer->FreeColumn( &colSearchColumnDN );

//end while loop
Who is Participating?
Allocate strung dynamically.

                              std::wstring* wsGroup = new wstring(colSearchColumnDN.pADsValues->CaseIgnoreString);
                              SendMessage(hwndPrimGroup,CB_SETITEMDATA, index, (LPARAM)wsGroup);

When you read string using CB_GETITEMDATA, cast result to wstring*. Don't forget to release all strings associated with items.

If you want to keep plain string and not wstring*, don't use T2CW macro, all these macros create pointers which are destroyed when function exits. In this case you need allocate memory block dynamically using new wchar and copy data to it.
lapuccaAuthor Commented:
The problem is that the vector doesn't like stroing pointers.  I had code before to store pointers to object of my class and the program would crash randomly.  And I also get memory uninitilize in Rational Purfiy.  Are you sure that it would store wstring*?  Isn't wstring already a pointer of wchar_t*?
This questions needs to be cross-referenced with your other question at http:/Q_21833678.html

I recommend that you close one of these questions, lapucca, and invite the experts from it to the other question.

We need to see what code you currently have that's causing you grief in the vector. It is hard to see what the state of play is. Please can you show us you current code with current error messages.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.