Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 19th, 2013  |  syntax: None  |  size: 0.89 KB  |  views: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. wlength = GetShortPathNameW(cpy,0,0);
  2. LPWSTR shortp = (LPWSTR)calloc(wlength,sizeof(WCHAR));
  3. GetShortPathNameW(cpy,shortp,wlength);
  4. clength = WideCharToMultiByte(CP_OEMCP, WC_NO_BEST_FIT_CHARS, shortp, wlength, 0, 0, 0, 0);
  5. LPSTR cpath = (LPSTR)calloc(clength,sizeof(CHAR));
  6. WideCharToMultiByte(CP_OEMCP, WC_NO_BEST_FIT_CHARS, shortp, wlength, cpath, clength, 0, 0);
  7.        
  8. char *
  9.        
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <assert.h>
  13. #include <wchar.h>
  14.  
  15. wchar_t *p = L"ABCDEFuA010"; // ascii only but last which won't be
  16.                               // converted properly...
  17.  
  18. char *wchar2char(wchar_t *s)
  19. {
  20.   int i;
  21.   size_t l = wcslen(s);
  22.   char *d = malloc(l+1); assert(d != NULL);
  23.   for(i = 0; i < l; i++) {
  24.     if ( s[i] > 127 ) d[i] = '?'; // no ascii
  25.     else d[i] = s[i] & 0xff;
  26.   }
  27.   d[l] = 0;
  28.   return d;
  29. }
  30.  
  31. int main()
  32. {
  33.   //wprintf(p);
  34.   char *t = wchar2char(p);
  35.   printf(t);
  36.   free(t);
  37. }
clone this paste RAW Paste Data