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.

446 lines
12 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All Rights Reserved.
  3. Module Name:
  4. stubs.c
  5. Abstract:
  6. Stubs for various API's
  7. Author:
  8. Jamie Hunter (jamiehun) 2001-11-27
  9. Revision History:
  10. Jamie Hunter (jamiehun) 2001-11-27
  11. Initial Version
  12. --*/
  13. #include "msoobcip.h"
  14. #define MODULE_SYSSETUP TEXT("syssetup.dll")
  15. #define MODULE_KERNEL32 TEXT("kernel32.dll")
  16. #define MODULE_SETUPAPI TEXT("setupapi.dll")
  17. #define NAME_SetupQueryRegisteredOsComponent "SetupQueryRegisteredOsComponent"
  18. #define NAME_GetSystemWindowsDirectory "GetSystemWindowsDirectoryW"
  19. #define NAME_SetupRegisterOsComponent "SetupRegisterOsComponent"
  20. #define NAME_SetupUnRegisterOsComponent "SetupUnRegisterOsComponent"
  21. #define NAME_SetupCopyOEMInf "SetupCopyOEMInfW"
  22. #define NAME_SetupQueryInfOriginalFileInformation "SetupQueryInfOriginalFileInformationW"
  23. #define NAME_SetupDiGetDeviceInfoListDetail "SetupDiGetDeviceInfoListDetailW"
  24. #define NAME_CM_Set_DevNode_Problem_Ex "CM_Set_DevNode_Problem_Ex"
  25. typedef BOOL (WINAPI *API_SetupQueryRegisteredOsComponent)(LPGUID,PSETUP_OS_COMPONENT_DATA,PSETUP_OS_EXCEPTION_DATA);
  26. typedef BOOL (WINAPI *API_SetupRegisterOsComponent)(PSETUP_OS_COMPONENT_DATA,PSETUP_OS_EXCEPTION_DATA);
  27. typedef BOOL (WINAPI *API_SetupUnRegisterOsComponent)(LPGUID);
  28. typedef BOOL (WINAPI *API_GetSystemWindowsDirectory)(LPTSTR,UINT);
  29. typedef BOOL (WINAPI *API_SetupQueryInfOriginalFileInformation)(PSP_INF_INFORMATION,UINT,PSP_ALTPLATFORM_INFO,PSP_ORIGINAL_FILE_INFO);
  30. typedef BOOL (WINAPI *API_SetupCopyOEMInf)(PCTSTR,PCTSTR,DWORD,DWORD,PTSTR,DWORD,PDWORD,PTSTR*);
  31. typedef BOOL (WINAPI *API_SetupDiGetDeviceInfoListDetail)(HDEVINFO,PSP_DEVINFO_LIST_DETAIL_DATA);
  32. typedef CONFIGRET (WINAPI *API_CM_Set_DevNode_Problem_Ex)(DEVINST,ULONG,ULONG,HMACHINE);
  33. FARPROC
  34. GetModProc(
  35. IN OUT HMODULE * phModule,
  36. IN LPCTSTR ModuleName,
  37. IN LPCSTR ApiName
  38. )
  39. /*++
  40. Routine Description:
  41. Demand-load specific API
  42. combines LoadLibrary with GetProcAddress
  43. Arguments:
  44. phModule - if points to NULL, replaced by handle to module ModuleName
  45. ModuleName - valid if phModule points to NULL
  46. ApiName - name of API to load
  47. Return Value:
  48. procedure, or NULL
  49. --*/
  50. {
  51. HMODULE hMod = *phModule;
  52. if(!hMod) {
  53. HMODULE hModPrev;
  54. //
  55. // need to load
  56. //
  57. hMod = LoadLibrary(ModuleName);
  58. if(hMod == NULL) {
  59. //
  60. // error linking to module
  61. //
  62. return NULL;
  63. }
  64. hModPrev = InterlockedCompareExchangePointer(phModule,hMod,NULL);
  65. if(hModPrev) {
  66. //
  67. // someone else set phModule
  68. //
  69. FreeLibrary(hMod);
  70. hMod = hModPrev;
  71. }
  72. }
  73. return GetProcAddress(hMod,ApiName);
  74. }
  75. FARPROC
  76. GetSysSetupProc(
  77. IN LPCSTR ApiName
  78. )
  79. /*++
  80. Routine Description:
  81. Demand-load specific API from syssetup.dll
  82. 1st time side-effect is that we'll load and keep syssetup.dll in memory
  83. ok to not deref syssetup.dll when dll exists.
  84. Arguments:
  85. ApiName - name of API to load
  86. Return Value:
  87. procedure, or NULL
  88. --*/
  89. {
  90. static HMODULE hSysSetupDll = NULL;
  91. return GetModProc(&hSysSetupDll,MODULE_SYSSETUP,ApiName);
  92. }
  93. FARPROC
  94. GetSetupApiProc(
  95. IN LPCSTR ApiName
  96. )
  97. /*++
  98. Routine Description:
  99. Demand-load specific API from setupapi.dll
  100. 1st time side-effect is that we'll ref and keep setupapi.dll in memory
  101. ok to not deref syssetup.dll when dll exists.
  102. Arguments:
  103. ApiName - name of API to load
  104. Return Value:
  105. procedure, or NULL
  106. --*/
  107. {
  108. static HMODULE hSetupApiDll = NULL;
  109. return GetModProc(&hSetupApiDll,MODULE_SETUPAPI,ApiName);
  110. }
  111. FARPROC
  112. GetKernelProc(
  113. IN LPCSTR ApiName
  114. )
  115. /*++
  116. Routine Description:
  117. Demand-load specific API from kernel32.dll
  118. 1st time side-effect is that we'll load and keep kernel32.dll in memory
  119. (it's in memory anyway)
  120. ok to not deref kernel32.dll when dll exists.
  121. Arguments:
  122. ApiName - name of API to load
  123. Return Value:
  124. procedure, or NULL
  125. --*/
  126. {
  127. static HMODULE hKernel32Dll = NULL;
  128. return GetModProc(&hKernel32Dll,MODULE_KERNEL32,ApiName);
  129. }
  130. BOOL
  131. WINAPI
  132. QueryRegisteredOsComponent(
  133. IN LPGUID ComponentGuid,
  134. OUT PSETUP_OS_COMPONENT_DATA SetupOsComponentData,
  135. OUT PSETUP_OS_EXCEPTION_DATA SetupOsExceptionData
  136. )
  137. /*++
  138. Routine Description:
  139. Demand-load and use SetupQueryRegisteredOsComponent from syssetup.dll, or
  140. use static version if not available
  141. Arguments:
  142. as SetupQueryRegisteredOsComponent
  143. Return Value:
  144. as SetupQueryRegisteredOsComponent
  145. --*/
  146. {
  147. static API_SetupQueryRegisteredOsComponent Func_SetupQueryRegisteredOsComponent = NULL;
  148. if(!Func_SetupQueryRegisteredOsComponent) {
  149. Func_SetupQueryRegisteredOsComponent = (API_SetupQueryRegisteredOsComponent)GetSysSetupProc(NAME_SetupQueryRegisteredOsComponent);
  150. if(!Func_SetupQueryRegisteredOsComponent) {
  151. Func_SetupQueryRegisteredOsComponent = SetupQueryRegisteredOsComponent; // static
  152. }
  153. }
  154. return Func_SetupQueryRegisteredOsComponent(ComponentGuid,SetupOsComponentData,SetupOsExceptionData);
  155. }
  156. BOOL
  157. WINAPI
  158. RegisterOsComponent (
  159. IN const PSETUP_OS_COMPONENT_DATA ComponentData,
  160. IN const PSETUP_OS_EXCEPTION_DATA ExceptionData
  161. )
  162. /*++
  163. Routine Description:
  164. Demand-load and use SetupRegisterOsComponent from syssetup.dll, or
  165. use static version if not available
  166. Arguments:
  167. as SetupRegisterOsComponent
  168. Return Value:
  169. as SetupRegisterOsComponent
  170. --*/
  171. {
  172. static API_SetupRegisterOsComponent Func_SetupRegisterOsComponent = NULL;
  173. if(!Func_SetupRegisterOsComponent) {
  174. Func_SetupRegisterOsComponent = (API_SetupRegisterOsComponent)GetSysSetupProc(NAME_SetupRegisterOsComponent);
  175. if(!Func_SetupRegisterOsComponent) {
  176. Func_SetupRegisterOsComponent = SetupRegisterOsComponent; // static
  177. }
  178. }
  179. return Func_SetupRegisterOsComponent(ComponentData,ExceptionData);
  180. }
  181. BOOL
  182. WINAPI
  183. UnRegisterOsComponent (
  184. IN const LPGUID ComponentGuid
  185. )
  186. /*++
  187. Routine Description:
  188. Demand-load and use SetupUnRegisterOsComponent from syssetup.dll, or
  189. use static version if not available
  190. Arguments:
  191. as SetupUnRegisterOsComponent
  192. Return Value:
  193. as SetupUnRegisterOsComponent
  194. --*/
  195. {
  196. static API_SetupUnRegisterOsComponent Func_SetupUnRegisterOsComponent = NULL;
  197. if(!Func_SetupUnRegisterOsComponent) {
  198. Func_SetupUnRegisterOsComponent = (API_SetupUnRegisterOsComponent)GetSysSetupProc(NAME_SetupUnRegisterOsComponent);
  199. if(!Func_SetupUnRegisterOsComponent) {
  200. Func_SetupUnRegisterOsComponent = SetupUnRegisterOsComponent; // static
  201. }
  202. }
  203. return Func_SetupUnRegisterOsComponent(ComponentGuid);
  204. }
  205. UINT
  206. GetRealWindowsDirectory(
  207. LPTSTR lpBuffer, // buffer to receive directory name
  208. UINT uSize // size of name buffer
  209. )
  210. /*++
  211. Routine Description:
  212. Use GetSystemWindowsDirectory if it exists
  213. otherwise use GetWindowsDirectory
  214. Arguments:
  215. as GetSystemWindowsDirectory
  216. Return Value:
  217. as GetSystemWindowsDirectory
  218. --*/
  219. {
  220. static API_GetSystemWindowsDirectory Func_GetSystemWindowsDirectory = NULL;
  221. if(!Func_GetSystemWindowsDirectory) {
  222. Func_GetSystemWindowsDirectory = (API_GetSystemWindowsDirectory)GetKernelProc(NAME_GetSystemWindowsDirectory);
  223. if(!Func_GetSystemWindowsDirectory) {
  224. Func_GetSystemWindowsDirectory = GetWindowsDirectory; // static
  225. }
  226. }
  227. return Func_GetSystemWindowsDirectory(lpBuffer,uSize);
  228. }
  229. BOOL Downlevel_SetupQueryInfOriginalFileInformation(
  230. PSP_INF_INFORMATION InfInformation,
  231. UINT InfIndex,
  232. PSP_ALTPLATFORM_INFO AlternatePlatformInfo,
  233. PSP_ORIGINAL_FILE_INFO OriginalFileInfo
  234. )
  235. {
  236. SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  237. return FALSE;
  238. }
  239. BOOL QueryInfOriginalFileInformation(
  240. PSP_INF_INFORMATION InfInformation,
  241. UINT InfIndex,
  242. PSP_ALTPLATFORM_INFO AlternatePlatformInfo,
  243. PSP_ORIGINAL_FILE_INFO OriginalFileInfo
  244. )
  245. {
  246. static API_SetupQueryInfOriginalFileInformation Func_SetupQueryInfOriginalFileInformation = NULL;
  247. if(!Func_SetupQueryInfOriginalFileInformation) {
  248. Func_SetupQueryInfOriginalFileInformation = (API_SetupQueryInfOriginalFileInformation)GetSetupApiProc(NAME_SetupQueryInfOriginalFileInformation);
  249. if(!Func_SetupQueryInfOriginalFileInformation) {
  250. Func_SetupQueryInfOriginalFileInformation = Downlevel_SetupQueryInfOriginalFileInformation;
  251. }
  252. }
  253. return Func_SetupQueryInfOriginalFileInformation(InfInformation,InfIndex,AlternatePlatformInfo,OriginalFileInfo);
  254. }
  255. BOOL
  256. WINAPI
  257. Downlevel_SetupCopyOEMInf(
  258. PCTSTR SourceInfFileName,
  259. PCTSTR OEMSourceMediaLocation,
  260. DWORD OEMSourceMediaType,
  261. DWORD CopyStyle,
  262. PTSTR DestinationInfFileName,
  263. DWORD DestinationInfFileNameSize,
  264. PDWORD RequiredSize,
  265. PTSTR *DestinationInfFileNameComponent
  266. )
  267. {
  268. SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  269. return FALSE;
  270. }
  271. BOOL CopyOEMInf(
  272. PCTSTR SourceInfFileName,
  273. PCTSTR OEMSourceMediaLocation,
  274. DWORD OEMSourceMediaType,
  275. DWORD CopyStyle,
  276. PTSTR DestinationInfFileName,
  277. DWORD DestinationInfFileNameSize,
  278. PDWORD RequiredSize,
  279. PTSTR *DestinationInfFileNameComponent
  280. )
  281. {
  282. static API_SetupCopyOEMInf Func_SetupCopyOEMInf = NULL;
  283. if(!Func_SetupCopyOEMInf) {
  284. Func_SetupCopyOEMInf = (API_SetupCopyOEMInf)GetSetupApiProc(NAME_SetupCopyOEMInf);
  285. if(!Func_SetupCopyOEMInf) {
  286. Func_SetupCopyOEMInf = Downlevel_SetupCopyOEMInf; // static
  287. }
  288. }
  289. return Func_SetupCopyOEMInf(SourceInfFileName,
  290. OEMSourceMediaLocation,
  291. OEMSourceMediaType,
  292. CopyStyle,
  293. DestinationInfFileName,
  294. DestinationInfFileNameSize,
  295. RequiredSize,
  296. DestinationInfFileNameComponent
  297. );
  298. }
  299. BOOL
  300. WINAPI
  301. Downlevel_SetupDiGetDeviceInfoListDetail(
  302. IN HDEVINFO DeviceInfoSet,
  303. OUT PSP_DEVINFO_LIST_DETAIL_DATA DeviceInfoSetDetailData
  304. )
  305. {
  306. SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  307. return FALSE;
  308. }
  309. BOOL
  310. GetDeviceInfoListDetail(
  311. IN HDEVINFO DeviceInfoSet,
  312. OUT PSP_DEVINFO_LIST_DETAIL_DATA DeviceInfoSetDetailData
  313. )
  314. {
  315. static API_SetupDiGetDeviceInfoListDetail Func_SetupDiGetDeviceInfoListDetail = NULL;
  316. if(!Func_SetupDiGetDeviceInfoListDetail) {
  317. Func_SetupDiGetDeviceInfoListDetail = (API_SetupDiGetDeviceInfoListDetail)GetSetupApiProc(NAME_SetupDiGetDeviceInfoListDetail);
  318. if(!Func_SetupDiGetDeviceInfoListDetail) {
  319. Func_SetupDiGetDeviceInfoListDetail = Downlevel_SetupDiGetDeviceInfoListDetail; // static
  320. }
  321. }
  322. return Func_SetupDiGetDeviceInfoListDetail(DeviceInfoSet,DeviceInfoSetDetailData);
  323. }
  324. CONFIGRET
  325. WINAPI
  326. Downlevel_CM_Set_DevNode_Problem_Ex(
  327. IN DEVINST dnDevInst,
  328. IN ULONG ulProblem,
  329. IN ULONG ulFlags,
  330. IN HMACHINE hMachine
  331. )
  332. {
  333. return CR_SUCCESS;
  334. }
  335. CONFIGRET
  336. Set_DevNode_Problem_Ex(
  337. IN DEVINST dnDevInst,
  338. IN ULONG ulProblem,
  339. IN ULONG ulFlags,
  340. IN HMACHINE hMachine
  341. )
  342. {
  343. static API_CM_Set_DevNode_Problem_Ex Func_CM_Set_DevNode_Problem_Ex = NULL;
  344. if(!Func_CM_Set_DevNode_Problem_Ex) {
  345. Func_CM_Set_DevNode_Problem_Ex = (API_CM_Set_DevNode_Problem_Ex)GetSetupApiProc(NAME_CM_Set_DevNode_Problem_Ex);
  346. if(!Func_CM_Set_DevNode_Problem_Ex) {
  347. Func_CM_Set_DevNode_Problem_Ex = Downlevel_CM_Set_DevNode_Problem_Ex; // static
  348. }
  349. }
  350. return Func_CM_Set_DevNode_Problem_Ex(dnDevInst,ulProblem,ulFlags,hMachine);
  351. }