Advertisement
Guest User

Untitled

a guest
Sep 19th, 2013
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement