Leaked source code of windows server 2003
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.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: strings.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef __strings_h
  11. #define __strings_h
  12. HRESULT LocalAllocString(LPTSTR* ppResult, LPCTSTR pString);
  13. HRESULT LocalAllocStringLen(LPTSTR* ppResult, UINT cLen);
  14. void LocalFreeString(LPTSTR* ppString);
  15. UINT SizeofStringResource(HINSTANCE hInstance, UINT idStr);
  16. int LoadStringAlloc(LPTSTR *ppszResult, HINSTANCE hInstance, UINT idStr);
  17. // String formatting functions - *ppszResult must be LocalFree'd
  18. DWORD FormatStringID(LPTSTR *ppszResult, HINSTANCE hInstance, UINT idStr, ...);
  19. DWORD FormatString(LPTSTR *ppszResult, LPCTSTR pszFormat, ...);
  20. DWORD vFormatStringID(LPTSTR *ppszResult, HINSTANCE hInstance, UINT idStr, va_list *pargs);
  21. DWORD vFormatString(LPTSTR *ppszResult, LPCTSTR pszFormat, va_list *pargs);
  22. DWORD GetSystemErrorText(LPTSTR *ppszResult, DWORD dwErr);
  23. // A BSTR wrapper that frees itself upon destruction.
  24. // Taken from sburns burnslib
  25. //
  26. // From Box, D. Essential COM. pp 80-81. Addison-Wesley. ISBN 0-201-63446-5
  27. class AutoBstr
  28. {
  29. public:
  30. explicit
  31. AutoBstr(const wchar_t* s)
  32. :
  33. bstr(::SysAllocString(s))
  34. {
  35. TraceAssert(s);
  36. }
  37. ~AutoBstr()
  38. {
  39. ::SysFreeString(bstr);
  40. bstr = 0;
  41. }
  42. operator BSTR () const
  43. {
  44. return bstr;
  45. }
  46. private:
  47. BSTR bstr;
  48. };
  49. #endif