Click here to Skip to main content
15,886,873 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
AnswerRe: Cocoa or Qt4? Pin
Steve Maier19-Jan-11 5:38
professionalSteve Maier19-Jan-11 5:38 
QuestionHow to identify the change in SQL database using MFC Pin
ganesh_IT18-Jan-11 19:53
ganesh_IT18-Jan-11 19:53 
Questioninterthread messaging in VS/c/c++ Pin
Alan Kurlansky12-Jan-11 11:33
Alan Kurlansky12-Jan-11 11:33 
AnswerRe: interthread messaging in VS/c/c++ Pin
User 742933812-Jan-11 12:29
professionalUser 742933812-Jan-11 12:29 
GeneralRe: interthread messaging in VS/c/c++ Pin
Alan Kurlansky13-Jan-11 3:00
Alan Kurlansky13-Jan-11 3:00 
AnswerRe: interthread messaging in VS/c/c++ Pin
User 742933813-Jan-11 5:00
professionalUser 742933813-Jan-11 5:00 
QuestionBest way to convert from std::wstring to std::string? Pin
David O'Neil8-Jan-11 8:10
professionalDavid O'Neil8-Jan-11 8:10 
AnswerRe: Best way to convert from std::wstring to std::string? [modified] Pin
David O'Neil8-Jan-11 17:32
professionalDavid O'Neil8-Jan-11 17:32 
After more searching, I went with the following. CStrWrap is just a thin wrapper around a char array, with a destructor that frees the memory.
std::string dwl::convertWstrToStdString(const std::wstring & wStr) {
   //The following code is modified from the examples at http://msmvps.com/blogs/gdicanio/
   //archive/2010/01/04/conversion-between-unicode-utf-16-and-utf-8-in-c-win32.aspx

   if (wStr == L"" || wStr.size()==0) return "";
   //Now, get the size of the required string:
   int origSize = wStr.size();
   origSize++; //For a NULL terminator
   DWORD conversionFlags = 0;
   //First, get the required size:
   int requiredSize = WideCharToMultiByte(CP_ACP, conversionFlags, wStr.c_str(),
               origSize, NULL, 0, NULL, NULL);
   if (requiredSize == 0)
               throw DwlException(_T("Bad Wide String to String conversion"));
   CStrWrap cStr(requiredSize+1);
   int result = WideCharToMultiByte(CP_ACP, conversionFlags, wStr.c_str(),
               origSize, cStr[0], requiredSize, NULL, NULL);
   if (result==0) throw DwlException(_T("Error converting string"));
   *cStr[result] = '\0';
   return std::string(cStr[0]);
   }


If anyone sees any issues with it, please let me know. Thanks!

EDIT - And for std::string to std::wstring:
std::wstring dwl::convertStdStringToWString(const std::string & str) {
   //This converts a string to a UNICODE string by the method taken on
   //http://www.codeguru.com/forum/archive/index.php/t-231165.html.
   if (str.length() == 0) return L"";
   //Get the required length:
   int unicodeLength = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), 0, 0);
   ++unicodeLength;  //Add space for a NULL terminator.
   if (unicodeLength == 0) throw DwlException(_T("Empty conversion"));
   MbStrWrap wStr(unicodeLength);
   int result = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), wStr[0],
               unicodeLength);
   if (result==0) throw DwlException(_T("Error converting string"));
   *wStr[result] = L'\0';
   return std::wstring(wStr[0]);
   }

My website :: The astronomy of our ancestors: Book :: Videos

modified on Sunday, January 9, 2011 1:28 AM

AnswerRe: Best way to convert from std::wstring to std::string? Pin
«_Superman_»10-Jan-11 7:42
professional«_Superman_»10-Jan-11 7:42 
GeneralRe: Best way to convert from std::wstring to std::string? Pin
David O'Neil10-Jan-11 11:20
professionalDavid O'Neil10-Jan-11 11:20 
GeneralRe: Best way to convert from std::wstring to std::string? Pin
jk chan14-Jan-11 4:46
jk chan14-Jan-11 4:46 
GeneralRe: Best way to convert from std::wstring to std::string? Pin
«_Superman_»14-Jan-11 7:05
professional«_Superman_»14-Jan-11 7:05 
QuestionWhat is meant by "STL Relational Database" programming? Pin
Xpnctoc7-Jan-11 5:04
Xpnctoc7-Jan-11 5:04 
AnswerRe: What is meant by "STL Relational Database" programming? Pin
Richard MacCutchan7-Jan-11 5:33
mveRichard MacCutchan7-Jan-11 5:33 
GeneralRe: What is meant by "STL Relational Database" programming? Pin
Xpnctoc7-Jan-11 5:40
Xpnctoc7-Jan-11 5:40 
Questiondialog not modal Pin
MrKBA6-Jan-11 0:19
MrKBA6-Jan-11 0:19 
AnswerRe: dialog not modal Pin
Cool_Dev6-Jan-11 3:58
Cool_Dev6-Jan-11 3:58 
GeneralRe: dialog not modal Pin
MrKBA6-Jan-11 21:49
MrKBA6-Jan-11 21:49 
QuestionChanging the style of a DateTimePicker Pin
Jim Crafton5-Jan-11 4:35
Jim Crafton5-Jan-11 4:35 
AnswerRe: Changing the style of a DateTimePicker Pin
User 74293387-Jan-11 12:17
professionalUser 74293387-Jan-11 12:17 
GeneralRe: Changing the style of a DateTimePicker Pin
Jim Crafton7-Jan-11 14:36
Jim Crafton7-Jan-11 14:36 
QuestionNeed to pass private member of a Class as a argument to function of another class and get modified there Pin
ptr_Electron4-Jan-11 21:38
ptr_Electron4-Jan-11 21:38 
AnswerRe: Need to pass private member of a Class as a argument to function of another class and get modified there Pin
Nuri Ismail4-Jan-11 21:49
Nuri Ismail4-Jan-11 21:49 
QuestionHow to get the delagate value via property Pin
ptr_Electron4-Jan-11 1:09
ptr_Electron4-Jan-11 1:09 
AnswerRe: How to get the delagate value via property Pin
Espen Harlinn4-Jan-11 11:01
professionalEspen Harlinn4-Jan-11 11:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.