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.

181 lines
4.0 KiB

  1. /* File: D:\WACKER\tdll\load_res.c (Created: 16-Dec-1993)
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 7 $
  7. * $Date: 4/12/02 4:59p $
  8. */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #include "stdtyp.h"
  12. #include "session.h"
  13. #include "assert.h"
  14. #include "tdll.h"
  15. #include "htchar.h"
  16. #include "load_res.h"
  17. #if defined(DEADWOOD)
  18. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  19. * FUNCTION:
  20. * resLoadDataBlock
  21. *
  22. * DESCRIPTION:
  23. * This function is used to get a block of data stored in the resource file
  24. * as an RCDATA item. Note that in WIN32, it is not necessary to free the
  25. * resource after it has been locked.
  26. *
  27. * PARAMETERS:
  28. * hSession -- the session handle
  29. * pszName -- the id for the data block
  30. * ppData -- where to put the pointer to the data block
  31. * pSize -- addres of integer for size value
  32. *
  33. * RETURNS: 0 if successful, otherwise a defined error value.
  34. *
  35. * The size of the resource that has been loaded (in bytes).
  36. * NOTE: The return value may be (and often is) larger than the actual
  37. * size of the resource as it is defined in the rc file. For resources
  38. * of type RCDATA, the resource definition itself should include either a
  39. * delimiter, or a count of the number of items included in that resource.
  40. * See also RCDATA_TYPE in stdtype.h
  41. */
  42. INT_PTR resLoadDataBlock(const HINSTANCE hInst,
  43. const int id,
  44. const void **ppData,
  45. DWORD *pSize)
  46. {
  47. HGLOBAL hG = NULL;
  48. HRSRC hR = NULL;
  49. LPVOID pV = NULL;
  50. DWORD nSize = 0;
  51. if(pSize)
  52. {
  53. *pSize = nSize;
  54. }
  55. hR = FindResource(hInst, MAKEINTRESOURCE(id), (LPCTSTR)RT_RCDATA);
  56. if (hR == NULL)
  57. {
  58. assert(FALSE);
  59. return LDR_BAD_ID;
  60. }
  61. hG = LoadResource(hInst, hR);
  62. if (hG == NULL)
  63. {
  64. assert(FALSE);
  65. return LDR_NO_RES;
  66. }
  67. nSize = SizeofResource(hInst, hR);
  68. if (nSize == 0)
  69. {
  70. assert(FALSE);
  71. return LDR_NO_RES;
  72. }
  73. if(pSize)
  74. {
  75. *pSize = nSize;
  76. }
  77. pV = LockResource(hG);
  78. if (pV == 0)
  79. {
  80. assert(FALSE);
  81. return LDR_NO_RES;
  82. }
  83. if (ppData == NULL)
  84. {
  85. assert(FALSE);
  86. return LDR_BAD_PTR;
  87. }
  88. *ppData = pV;
  89. return 0;
  90. }
  91. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  92. * FUNCTION:
  93. * resFreeDataBlock
  94. *
  95. * DESCRIPTION:
  96. * This function is not necessary for WIN32.
  97. *
  98. * PARAMETERS:
  99. * hSession -- the session handle
  100. * pData -- pointer to the data block
  101. *
  102. * RETURNS:
  103. * ZERO if everything is OK, otherwise an error code.
  104. */
  105. INT_PTR resFreeDataBlock(const HSESSION hSession,
  106. const void *pData)
  107. {
  108. return 0;
  109. }
  110. #endif // defined(DEADWOOD)
  111. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  112. * FUNCTION:
  113. * resLoadFileMask
  114. *
  115. * DESCRIPTION:
  116. * This function is used to get around a problem that exists in loading
  117. * strings into the common file dialogs. The file name masks are two strings
  118. * that are NULL separated. This internal NULL is not treated with any
  119. * respect by the resource functions, so we split them up and do a two part
  120. * load to rebuild the string.
  121. *
  122. * PARAMETERS:
  123. * hInst -- the instance handle to use
  124. * uId -- the ID of the first resource to load
  125. * nCount -- the number of string PAIRS to load, starting a uId
  126. * pszBuffer -- where to put the strings
  127. * nSize -- the size of the buffer in characters
  128. *
  129. * RETURNS:
  130. * Zero if everything is OK, otherwise (-1)
  131. */
  132. INT_PTR resLoadFileMask(HINSTANCE hInst,
  133. UINT uId,
  134. int nCount,
  135. LPTSTR pszBuffer,
  136. int nSize)
  137. {
  138. int i;
  139. LPTSTR pszEnd;
  140. LPTSTR pszPtr;
  141. if (pszBuffer == 0 || nSize == 0)
  142. {
  143. assert(0);
  144. return -1;
  145. }
  146. TCHAR_Fill(pszBuffer, TEXT('\0'), nSize);
  147. pszPtr = pszBuffer;
  148. pszEnd = pszBuffer + nSize;
  149. for (nCount *= 2 ; nCount > 0 ; --nCount)
  150. {
  151. i = LoadString(hInst, uId++, pszPtr, (int)(pszEnd - pszPtr - 1));
  152. pszPtr += (unsigned)i + sizeof(TCHAR);
  153. if (pszPtr >= pszEnd)
  154. {
  155. assert(0);
  156. return -1;
  157. }
  158. }
  159. return 0;
  160. }