Advertisement
obernardovieira

Convert LPCTSTR to char*

Sep 16th, 2013
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdio.h>
  3.  
  4. #pragma warning (disable : 4996)
  5.  
  6. char* conversion(LPCTSTR val)
  7. {
  8.     LPCWSTR wstr = val;
  9.     int count = wcslen(wstr);
  10.     char* c = new char[count + 1];
  11.     wchar_t* pwchr = const_cast<wchar_t*> (&wstr[0]);
  12.     for(int j = 0; j < count; ++j)
  13.     {
  14.         c[j] = static_cast<char> (*pwchr);  
  15.         pwchr++;
  16.     }    
  17.     c[count] = '\0';
  18.     wcstombs(c,val,count);
  19.     return c;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement