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.

67 lines
1.7 KiB

  1. #pragma once
  2. #include <objbase.h>
  3. #define SafeRelease(p) if (NULL != p) { (p)->Release(); }
  4. #define SafeReleaseNULL(p) if (NULL != p) { (p)->Release(); (p) = NULL; }
  5. #define SafeFree(p) if (NULL != p) { free(p); }
  6. #define SafeFreeNULL(p) if (NULL != p) { free(p); (p) = NULL; }
  7. #define SafeDelete(p) if (NULL != p) { delete (p); }
  8. #define SafeDeleteNULL(p) if (NULL != p) { delete (p); (p) = NULL; }
  9. #define SafeLocalFree(p) if (NULL != p) { LocalFree(p); }
  10. #define SafeLocalFreeNULL(p) if (NULL != p) { LocalFree(p); (p) = NULL; }
  11. inline void SafeCloseHandle(HANDLE h)
  12. {
  13. if ( NULL != h )
  14. {
  15. CloseHandle(h);
  16. }
  17. }
  18. inline void SafeCloseHandleNULL(HANDLE & h)
  19. {
  20. if ( NULL != h )
  21. {
  22. CloseHandle(h);
  23. h = NULL;
  24. }
  25. }
  26. inline void SafeCloseFileHandle(HANDLE h)
  27. {
  28. if ( INVALID_HANDLE_VALUE != h )
  29. {
  30. CloseHandle(h);
  31. }
  32. }
  33. inline void SafeCloseFileHandleInvalidate(HANDLE & h)
  34. {
  35. if ( INVALID_HANDLE_VALUE != h )
  36. {
  37. CloseHandle(h);
  38. h = INVALID_HANDLE_VALUE;
  39. }
  40. }
  41. inline void SafeFreeBSTR(BSTR bstr)
  42. {
  43. SysFreeString(bstr); // SysFreeString takes no action if bstr == NULL
  44. }
  45. inline void SafeFreeBSTRNULL(BSTR &bstr)
  46. {
  47. SysFreeString(bstr);
  48. bstr = NULL;
  49. }
  50. inline int WUCompareString(LPCTSTR lpString1, LPCTSTR lpString2)
  51. {
  52. return CompareString(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT), 0, lpString1, -1, lpString2, -1);
  53. }
  54. inline int WUCompareStringI(LPCTSTR lpString1, LPCTSTR lpString2)
  55. {
  56. return CompareString(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT), NORM_IGNORECASE, lpString1, -1, lpString2, -1);
  57. }