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.

222 lines
5.1 KiB

  1. // ############################################################################
  2. #include "pch.hpp"
  3. extern "C" {
  4. HINSTANCE g_hInstDll; // instance for this DLL
  5. }
  6. #ifdef WIN16
  7. int CALLBACK LibMain(HINSTANCE hinst,
  8. WORD wDataSeg,
  9. WORD cbHeap,
  10. LPSTR lpszCmdLine )
  11. {
  12. g_hInstDll = hinst;
  13. return TRUE;
  14. }
  15. //+---------------------------------------------------------------------------
  16. //
  17. // Function: PrivateMalloc()
  18. //
  19. // Synopsis: Allocate and initialize memory
  20. //
  21. // Arguments: [size - Size of memory block to be allocated]
  22. //
  23. // Returns: pointer to memory block if successful
  24. // NULL otherwise
  25. //
  26. // History: 7/9/96 VetriV Created
  27. //
  28. //----------------------------------------------------------------------------
  29. void far *PrivateMalloc(size_t size)
  30. {
  31. void far * ReturnValue = NULL;
  32. ReturnValue = malloc(size);
  33. if (NULL != ReturnValue)
  34. memset(ReturnValue, 0, size);
  35. return ReturnValue;
  36. }
  37. //+---------------------------------------------------------------------------
  38. //
  39. // Function: PrivateReAlloc()
  40. //
  41. // Synopsis: Reallocate memory
  42. //
  43. // Arguments: [lpBlock - Block to be reallocated ]
  44. // [size - Size of memory block to be allocated]
  45. //
  46. // Returns: pointer to memory block if successful
  47. // NULL otherwise
  48. //
  49. // History: 7/25/96 ValdonB Created
  50. //
  51. //----------------------------------------------------------------------------
  52. void far *PrivateReAlloc(void far *lpBlock, size_t size)
  53. {
  54. void far *lpRetBlock;
  55. lpRetBlock = PrivateMalloc(size);
  56. if (NULL == lpRetBlock)
  57. return NULL;
  58. if (NULL != lpBlock)
  59. {
  60. size_t OldBlockSize, MoveSize;
  61. OldBlockSize = _msize(lpBlock);
  62. MoveSize = min(OldBlockSize, size);
  63. memmove(lpRetBlock, lpBlock, MoveSize);
  64. PrivateFree(lpBlock);
  65. }
  66. return lpRetBlock;
  67. }
  68. //+---------------------------------------------------------------------------
  69. //
  70. // Function: PrivateFree
  71. //
  72. // Synopsis: Free a block of memory
  73. //
  74. // Arguments: [lpBlock - Block to be freed]
  75. //
  76. // Returns: Nothing
  77. //
  78. // History: 7/9/96 VetriV Created
  79. //
  80. //----------------------------------------------------------------------------
  81. void PrivateFree(void far *lpBlock)
  82. {
  83. free(lpBlock);
  84. }
  85. //+---------------------------------------------------------------------------
  86. //
  87. // Function: SearchPath()
  88. //
  89. // Synopsis: Searchs for the specified file in the given path
  90. //
  91. // Arguments: [lpPath - Address of search path]
  92. // [lpFileName - Address of filename]
  93. // [lpExtension - Address of Extension]
  94. // [nBufferLength - size, in characters, of buffer]
  95. // [lpBuffer - address of buffer for found filename]
  96. // [lpFilePart - address of pointer to file component]
  97. //
  98. // Returns: Length of string copied to buffer (not including terminating
  99. // NULL character) if successful
  100. // 0 otherwise
  101. //
  102. // History: 7/9/96 VetriV Created
  103. //
  104. //----------------------------------------------------------------------------
  105. DWORD SearchPath(LPCTSTR lpPath,LPCTSTR lpFileName, LPCTSTR lpExtension,
  106. DWORD nBufferLength, LPTSTR lpBuffer, LPTSTR *lpFilePart)
  107. {
  108. BOOL bUseExtension = FALSE, bPathContainsFileName = FALSE;
  109. DWORD dwRequiredLength;
  110. LPSTR lpszPath = lpPath;
  111. char szFileName[MAX_PATH+1];
  112. OFSTRUCT OpenBuf;
  113. // Check if extension should be used
  114. //
  115. if ((NULL != lpExtension) && !strchr(lpFileName, '.'))
  116. bUseExtension = TRUE;
  117. //
  118. // Form Filename
  119. //
  120. lstrcpy(szFileName, lpFileName);
  121. if (bUseExtension)
  122. lstrcat(szFileName, lpExtension);
  123. //
  124. // If search path is NULL, then try to OpenFile using OF_SEARCH flag
  125. // get the full path in OpenBuf struct
  126. //
  127. if (NULL == lpszPath)
  128. {
  129. if (HFILE_ERROR != OpenFile(szFileName, &OpenBuf, OF_EXIST | OF_SEARCH))
  130. {
  131. //
  132. // This path contains the file name also
  133. //
  134. lpszPath = &OpenBuf.szPathName[0];
  135. bPathContainsFileName = TRUE;
  136. }
  137. else
  138. return 0;
  139. }
  140. //
  141. // Check if output buffer length is sufficient
  142. //
  143. dwRequiredLength = lstrlen(lpszPath) +
  144. (bPathContainsFileName ? 0 :lstrlen(szFileName)) + 1;
  145. if (nBufferLength < dwRequiredLength)
  146. return 0;
  147. //
  148. // Copy the full name to buffer
  149. //
  150. if (bPathContainsFileName)
  151. lstrcpy(lpBuffer, lpszPath);
  152. else
  153. wsprintf(lpBuffer, "%s\\%s", lpszPath, szFileName);
  154. //
  155. // Do not include the terminating null character in return length
  156. //
  157. return dwRequiredLength - 1;
  158. }
  159. #else // WIN16
  160. #ifdef _NOT_USING_ACTIVEX
  161. extern "C" __declspec(dllexport) BOOL WINAPI DllMain(
  162. HINSTANCE hinstDLL, // handle to DLL module
  163. DWORD fdwReason, // reason for calling function
  164. LPVOID lpvReserved // reserved
  165. )
  166. {
  167. if (fdwReason == DLL_PROCESS_ATTACH)
  168. g_hInstDll = hinstDLL;
  169. return TRUE;
  170. }
  171. #if 0
  172. extern "C" __declspec(dllexport) BOOL WINAPI DllMain(
  173. HINSTANCE hinstDLL, // handle to DLL module
  174. DWORD fdwReason, // reason for calling function
  175. LPVOID lpvReserved // reserved
  176. )
  177. {
  178. if (fdwReason == DLL_PROCESS_ATTACH)
  179. g_hInstDll = hinstDLL;
  180. return TRUE;
  181. }
  182. #endif
  183. #endif
  184. #endif // WIN16