Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.9 KiB

  1. /*************************************************************************\
  2. *
  3. * thunk.h
  4. *
  5. * These are helper functions to make thunking easier.
  6. *
  7. * 18-Aug-1994 JonPa Created it.
  8. *
  9. \ *************************************************************************/
  10. /*
  11. * Creates a buffer for a unicode string, and then copies the ANSI text
  12. * into it (converting it to unicode in the process)
  13. *
  14. * The returned pointer should be freed with FreeProducedString after use.
  15. */
  16. LPWSTR ProduceWFromA( UINT uiCodePage, LPCSTR pszAnsi );
  17. /*
  18. * Creates a buffer for a ANSI string, and then copies the UNICODE text
  19. * into it (converting it to ANSI in the process)
  20. *
  21. * The returned pointer should be freed with FreeProducedString after use.
  22. */
  23. LPSTR ProduceAFromW( UINT uiCodePage, LPCWSTR pszW );
  24. /*
  25. * FreeProducedString
  26. *
  27. * Takes a pointer returned from Produce?From?() and frees it. No
  28. * validity checking is needed before calling this function. (ie, any
  29. * value returned by Produce?From?() can be safely sent to this function)
  30. */
  31. #define FreeProducedString( psz ) \
  32. if((psz) != NULL && ((LPSTR)psz) != LPSTR_TEXTCALLBACKA) {LocalFree(psz);} else
  33. /*
  34. * Converts a UNICODE string to ANSI
  35. */
  36. #define ConvertWToAN( uiCodePage, pszABuf, cchA, pszW, cchW ) \
  37. WideCharToMultiByte(uiCodePage, 0, pszW, cchW, pszABuf, cchA, NULL, NULL)
  38. #define ConvertWToA( uiCodePage, pszABuf, pszW ) \
  39. ConvertWToAN( uiCodePage, pszABuf, INT_MAX, pszW, -1 )
  40. /*
  41. * Converts an ANSI string to UNICODE
  42. */
  43. #define ConvertAToWN( uiCodePage, pszWBuf, cchW, pszA, cchA ) \
  44. MultiByteToWideChar( uiCodePage, MB_PRECOMPOSED, pszA, cchA, pszWBuf, cchW )
  45. #define ConvertAToW( uiCodePage, pszWBuf, pszAnsi ) \
  46. ConvertAToWN( uiCodePage, pszWBuf, INT_MAX, pszAnsi, -1 )
  47. /*
  48. * IsFlagPtr
  49. * Returns TRUE if the pointer == NULL or -1
  50. */
  51. #define IsFlagPtr( p ) ((p) == NULL || (LPSTR)(p) == LPSTR_TEXTCALLBACKA)