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.

46 lines
1.6 KiB

  1. // Include File for ihtest.cpp
  2. #define TRACKMENU 101
  3. #define ID_EXIT 40001
  4. #define ID_REFRESH 40002
  5. #define IDC_STATIC -1
  6. #define MY_CACHE_ENTRY_INFO_SIZE 2048
  7. #define MY_MAX_STRING_LEN 512
  8. class TempBuffer {
  9. public:
  10. TempBuffer(ULONG cBytes) {
  11. m_pBuf = (cBytes <= 120) ? &m_szTmpBuf : GlobalAlloc(GPTR, cBytes);
  12. m_fGlobalAlloc = (cBytes > 120);
  13. }
  14. ~TempBuffer() {
  15. if (m_pBuf && m_fGlobalAlloc) GlobalFree(m_pBuf);
  16. }
  17. void *GetBuffer() {
  18. return m_pBuf;
  19. }
  20. private:
  21. void *m_pBuf;
  22. // we'll use this temp buffer for small cases.
  23. //
  24. char m_szTmpBuf[120];
  25. unsigned m_fGlobalAlloc:1;
  26. };
  27. #define MAKE_WIDEPTR_FROMANSI(ptrname, ansistr) \
  28. long __l##ptrname = (lstrlen(ansistr) + 1) * sizeof(WCHAR); \
  29. TempBuffer __TempBuffer##ptrname(__l##ptrname); \
  30. MultiByteToWideChar(CP_ACP, 0, ansistr, -1, (LPWSTR)__TempBuffer##ptrname.GetBuffer(), __l##ptrname); \
  31. LPWSTR ptrname = (LPWSTR)__TempBuffer##ptrname.GetBuffer()
  32. //
  33. // Note: allocate lstrlenW(widestr) * 2 because its possible for a UNICODE
  34. // character to map to 2 ansi characters this is a quick guarantee that enough
  35. // space will be allocated.
  36. //
  37. #define MAKE_ANSIPTR_FROMWIDE(ptrname, widestr) \
  38. long __l##ptrname = (lstrlenW(widestr) + 1) * 2 * sizeof(char); \
  39. TempBuffer __TempBuffer##ptrname(__l##ptrname); \
  40. WideCharToMultiByte(CP_ACP, 0, widestr, -1, (LPSTR)__TempBuffer##ptrname.GetBuffer(), __l##ptrname, NULL, NULL); \
  41. LPSTR ptrname = (LPSTR)__TempBuffer##ptrname.GetBuffer()