Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1268
  • Last Modified:

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()));
                                    primaryGroups.push_back(wsGroup);
                                    padsSearchContainer->FreeColumn( &colSearchColumnDN );

//end while loop
0
lapucca
Asked:
lapucca
1 Solution
 
AlexFMCommented:
Allocate strung dynamically.

                              std::wstring* wsGroup = new wstring(colSearchColumnDN.pADsValues->CaseIgnoreString);
                              SendMessage(hwndPrimGroup,CB_SETITEMDATA, index, (LPARAM)wsGroup);
                              primaryGroups.push_back(*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.
0
 
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*?
0
 
rstaveleyCommented:
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.
0

Featured Post

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now