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.

111 lines
3.6 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : utils.h //
  3. // //
  4. // DESCRIPTION : Define some common utilities. //
  5. // //
  6. // AUTHOR : DanL. //
  7. // //
  8. // HISTORY : //
  9. // Oct 19 1999 DannyL Creation. //
  10. // //
  11. // Copyright (C) 1999 Microsoft Corporation All Rights Reserved //
  12. /////////////////////////////////////////////////////////////////////////////
  13. #ifndef __UTILS__UTILS_H
  14. #define __UTILS__UTILS_H
  15. #include "string.h"
  16. /*
  17. - macro: SafeStringCopy
  18. -
  19. * Purpose:
  20. * Safely copy a source string to a fixed size destination buffer.
  21. *
  22. * Arguments:
  23. * dstStr - Destination string.
  24. * srcStr - Source string.
  25. *
  26. * Remarks:
  27. * This macro calculates the size of a fixed size destination buffer,
  28. * and ensures that it will not overflow when copying to it.
  29. * An attempt to use this macro on a heap allocated buffer will result
  30. * in an assertion failure. In the latter case it is recommended to use
  31. * StringCopy.
  32. */
  33. #define SafeStringCopy(dstStr,srcStr) \
  34. StringCopy(dstStr,srcStr,dstStr?(sizeof(dstStr)/sizeof(dstStr[0]) - 1):0);
  35. /*
  36. - StringCopy
  37. -
  38. * Purpose:
  39. * Copy counted number of characters to a destination string.
  40. *
  41. * Arguments:
  42. * [in] dstStr - Destination buffer.
  43. * [in] srcStr - Source buffer.
  44. * [in] iSize - Number of chars to copy.
  45. *
  46. * Returns:
  47. * [N/A]
  48. *
  49. * Remarks:
  50. * [N/A]
  51. */
  52. void _inline StringCopy(char* dstStr,const char* srcStr,int iSize)
  53. {
  54. SDBG_PROC_ENTRY("StringCopy");
  55. ASSERT(dstStr && iSize > 0);
  56. *dstStr = 0;
  57. strncat(dstStr,srcStr,iSize);
  58. RETURN;
  59. }
  60. //////////////////////////////////////////////////////////////////////////////////////////
  61. // Localization macros
  62. /*
  63. - macro: PROMPT
  64. -
  65. * Purpose:
  66. * Pop a message box with localized text.
  67. *
  68. * Arguments:
  69. * hwnd - Handle to parent window.
  70. * idtext - Message box text resource id.
  71. * idcapt - Message box caption resource id
  72. * type - Message box type. (i.e. MB_ICONINFORMATION)
  73. *
  74. * Remarks:
  75. * This macro loads the resource strings, which id name's are of the form
  76. * IDS_MB_XXX and IDS_MB_CAPTION_XXX where XXX represents the idtext and
  77. * idcapt respectively.
  78. */
  79. #define PROMPT(hwnd,idtext,idcapt,type)\
  80. {\
  81. char szText[MAX_PATH]="";\
  82. char szCapt[MAX_PATH]="";\
  83. LoadString(g_hModule,IDS_MB_##idtext,szText,sizeof(szText));\
  84. LoadString(g_hModule,IDS_MB_CAPTION_##idcapt,szCapt,sizeof(szCapt));\
  85. MessageBox(hwnd,szText,szCapt,type);\
  86. }
  87. /*
  88. - macro: ERROR_PROMPT
  89. -
  90. * Purpose:
  91. * Pop a message box for unexpected error.
  92. *
  93. * Arguments:
  94. * hwnd - Handle to parent window.
  95. * idtext - Message box text resource id.
  96. *
  97. * Remarks:
  98. * This macro is merely a simplified version of PROMPT for the sake of
  99. * error notifications.
  100. */
  101. #define ERROR_PROMPT(hwnd,idtext) PROMPT(hwnd,idtext,ERROR,MB_ICONEXCLAMATION)
  102. #endif //__UTILS__UTILS_H