Source code of Windows XP (NT5)
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.

1941 lines
47 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. ocinterf.c
  5. Abstract:
  6. Routines to interface with optional components via the OC Manager
  7. interface routine exported from the component's installation DLL.
  8. Author:
  9. Ted Miller (tedm) 16-Sep-1996
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. #ifdef DEBUGPERFTRACE
  15. #define RES_BUFFER 512
  16. #define MAX_LOGLINE 1024
  17. #define EOL_LENGTH 3
  18. #define BUFFER_SIZE 64*1024
  19. VOID
  20. DebugLogPerf(
  21. VOID
  22. )
  23. {
  24. LPTSTR lpProcessName;
  25. NTSTATUS Status;
  26. ULONG Offset1;
  27. PUCHAR CurrentBuffer;
  28. PSYSTEM_PROCESS_INFORMATION ProcessInfo;
  29. LPTSTR lpTemp;//[RES_BUFFER];
  30. HMODULE hNtDll;
  31. LONG_PTR (*NtQSI)(); // Ptr to NtQuerySystemInformation
  32. HANDLE hProcessName;
  33. TCHAR szLogLine[MAX_LOGLINE+EOL_LENGTH];
  34. LPCTSTR szResBuf = TEXT("%7i%20ws->%10u%10u%10u%10u%10u%10u%10u\r\n");
  35. if ((hNtDll = LoadLibrary(TEXT("NTDLL.DLL"))) == NULL)
  36. {
  37. return;
  38. }
  39. NtQSI = GetProcAddress(hNtDll, "NtQuerySystemInformation" );
  40. if( NtQSI == NULL )
  41. {
  42. FreeLibrary(hNtDll);
  43. return;
  44. }
  45. //header for mem area
  46. TRACE (( TEXT("Proc ID Proc.Name Wrkng.Set PagedPool NonPgdPl Pagefile Commit Handles Threads\n") ));
  47. /* grab all process information */
  48. /* log line format, all comma delimited,CR delimited:
  49. pid,name,WorkingSetSize,QuotaPagedPoolUsage,QuotaNonPagedPoolUsage,PagefileUsage,CommitCharge<CR>
  50. log all process information */
  51. /* from pmon */
  52. Offset1 = 0;
  53. if ((CurrentBuffer = VirtualAlloc (NULL,
  54. BUFFER_SIZE,
  55. MEM_COMMIT,
  56. PAGE_READWRITE)) != NULL)
  57. {
  58. /* from memsnap */
  59. /* get commit charge */
  60. /* get all of the status information */
  61. Status = (NTSTATUS)(*NtQSI)(
  62. SystemProcessInformation,
  63. CurrentBuffer,
  64. BUFFER_SIZE,
  65. NULL );
  66. if (NT_SUCCESS(Status)){
  67. for (;;)
  68. {
  69. /* get process info from buffer */
  70. ProcessInfo = (PSYSTEM_PROCESS_INFORMATION)&CurrentBuffer[Offset1];
  71. Offset1 += ProcessInfo->NextEntryOffset;
  72. if (ProcessInfo->ImageName.Buffer) {
  73. if (!lstrcmpi(ProcessInfo->ImageName.Buffer, TEXT("sysocmgr.exe")) ||
  74. !lstrcmpi(ProcessInfo->ImageName.Buffer, TEXT("setup.exe")) ) {
  75. wsprintf(szLogLine,
  76. szResBuf,
  77. ProcessInfo->UniqueProcessId,
  78. ProcessInfo->ImageName.Buffer,
  79. ProcessInfo->WorkingSetSize / 1024,
  80. ProcessInfo->QuotaPagedPoolUsage / 1024,
  81. ProcessInfo->QuotaNonPagedPoolUsage / 1024,
  82. ProcessInfo->PagefileUsage / 1024,
  83. ProcessInfo->PrivatePageCount / 1024,
  84. ProcessInfo->HandleCount,
  85. ProcessInfo->NumberOfThreads );
  86. TRACE(( szLogLine ));
  87. }
  88. }
  89. #if 0
  90. // if buffer is null then it's idle process or unknown
  91. if (!ProcessInfo->ImageName.Buffer)
  92. {
  93. if (ProcessInfo->UniqueProcessId == (HANDLE)0)
  94. lpTemp = TEXT("Idle");
  95. else
  96. lpTemp = TEXT("Unknown");
  97. wsprintf(szLogLine,
  98. szResBuf,
  99. ProcessInfo->UniqueProcessId,
  100. lpTemp,
  101. ProcessInfo->WorkingSetSize / 1024,
  102. ProcessInfo->QuotaPagedPoolUsage / 1024,
  103. ProcessInfo->QuotaNonPagedPoolUsage / 1024,
  104. ProcessInfo->PagefileUsage / 1024,
  105. ProcessInfo->PrivatePageCount / 1024,
  106. ProcessInfo->HandleCount,
  107. ProcessInfo->NumberOfThreads );
  108. }
  109. else
  110. {
  111. wsprintf(szLogLine,
  112. szResBuf,
  113. ProcessInfo->UniqueProcessId,
  114. ProcessInfo->ImageName.Buffer,
  115. ProcessInfo->WorkingSetSize / 1024,
  116. ProcessInfo->QuotaPagedPoolUsage / 1024,
  117. ProcessInfo->QuotaNonPagedPoolUsage / 1024,
  118. ProcessInfo->PagefileUsage / 1024,
  119. ProcessInfo->PrivatePageCount / 1024,
  120. ProcessInfo->HandleCount,
  121. ProcessInfo->NumberOfThreads );
  122. }
  123. TRACE(( szLogLine ));
  124. #endif
  125. if (ProcessInfo->NextEntryOffset == 0)
  126. {
  127. break;
  128. }
  129. }
  130. //status failed
  131. }
  132. /* free mem */
  133. VirtualFree(CurrentBuffer,0,MEM_RELEASE);
  134. }
  135. //tail for mem area
  136. TRACE(( TEXT("\n") ));
  137. FreeLibrary(hNtDll);
  138. }
  139. #endif
  140. #ifdef UNICODE
  141. NTSYSAPI
  142. BOOLEAN
  143. NTAPI
  144. RtlValidateProcessHeaps (
  145. VOID
  146. );
  147. #define ASSERT_HEAP_IS_VALID(_x_) sapiAssert(RtlValidateProcessHeaps && _x_)
  148. #else
  149. #define ASSERT_HEAP_IS_VALID(_x_)
  150. #endif
  151. DWORD gecode;
  152. PVOID geaddr;
  153. DWORD
  154. efilter(
  155. LPEXCEPTION_POINTERS ep
  156. )
  157. /*++
  158. Routine Description:
  159. handles exception during calls to oc component routines
  160. Arguments:
  161. ep - exception information
  162. Return Value:
  163. always 1 - execute the handler
  164. --*/
  165. {
  166. gecode = ep->ExceptionRecord->ExceptionCode;
  167. geaddr = ep->ExceptionRecord->ExceptionAddress;
  168. return EXCEPTION_EXECUTE_HANDLER;
  169. }
  170. BOOL
  171. pOcInterface(
  172. IN POC_MANAGER OcManager,
  173. OUT PUINT Result,
  174. IN LONG ComponentId,
  175. IN LPCTSTR Subcomponent, OPTIONAL
  176. IN UINT Function,
  177. IN UINT_PTR Param1,
  178. IN PVOID Param2
  179. )
  180. /*++
  181. Routine Description:
  182. Perform the actual call to the OC interface routine.
  183. Converts Unicode component/subcomponent names to ANSI if needed.
  184. Arguments:
  185. OcManager - supplies OC Manager context structure.
  186. Result -
  187. ComponentId -
  188. Remaining arguments specify parameters to be passed directly to
  189. the interface.
  190. Return Value:
  191. TRUE if the interface routine was successfully called and returned
  192. without faulting. LastError() is preserved in this case.
  193. FALSE otherwise.
  194. --*/
  195. {
  196. LONG OldComponentStringId;
  197. BOOL b;
  198. LPCTSTR Component;
  199. OPTIONAL_COMPONENT Oc;
  200. LPCVOID comp,subcomp;
  201. #ifdef UNICODE
  202. CHAR AnsiComp[500];
  203. CHAR AnsiSub[500];
  204. #endif
  205. //
  206. // Get the name of the component and the optional component data
  207. // from the string table.
  208. //
  209. // Though it would be strange, it is possible that this will fail,
  210. // so we do a little checking for robustness.
  211. //
  212. Component = pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId);
  213. b = pSetupStringTableGetExtraData(OcManager->ComponentStringTable,ComponentId,&Oc,sizeof(OPTIONAL_COMPONENT));
  214. if(!Component || !b || !Oc.InstallationRoutine) {
  215. return(FALSE);
  216. }
  217. OldComponentStringId = OcManager->CurrentComponentStringId;
  218. OcManager->CurrentComponentStringId = ComponentId;
  219. #ifdef UNICODE
  220. //
  221. // If necessary, convert component name and subcomponent name to ANSI.
  222. //
  223. if((Function != OC_PREINITIALIZE) && (Oc.Flags & OCFLAG_ANSI)) {
  224. WideCharToMultiByte(CP_ACP,0,Component,-1,AnsiComp,sizeof(AnsiComp),NULL,NULL);
  225. comp = AnsiComp;
  226. if(Subcomponent) {
  227. WideCharToMultiByte(CP_ACP,0,Subcomponent,-1,AnsiSub,sizeof(AnsiSub),NULL,NULL);
  228. subcomp = AnsiSub;
  229. } else {
  230. subcomp = NULL;
  231. }
  232. } else
  233. #endif
  234. {
  235. comp = Component;
  236. subcomp = Subcomponent;
  237. }
  238. *Result = CallComponent(OcManager, &Oc, comp, subcomp, Function, Param1, Param2);
  239. b = (*Result == ERROR_CALL_COMPONENT) ? FALSE : TRUE;
  240. OcManager->CurrentComponentStringId = OldComponentStringId;
  241. return b;
  242. }
  243. DWORD
  244. CallComponent(
  245. IN POC_MANAGER OcManager,
  246. IN POPTIONAL_COMPONENT Oc,
  247. IN LPCVOID ComponentId,
  248. IN LPCVOID SubcomponentId,
  249. IN UINT Function,
  250. IN UINT_PTR Param1,
  251. IN OUT PVOID Param2
  252. )
  253. /*++
  254. Routine Description:
  255. Calls a component's interface routine with a try-except block.
  256. Arguments:
  257. Oc - supplies a pointer to the component description structure
  258. ComponentId - string description of the component
  259. SubcomponentId - string description of the subcomponent
  260. Function - notification being sent to the component
  261. Param1 - differs with each function
  262. Param2 - differs with each function
  263. Return Value:
  264. Component return value. Meaning differs with each function.
  265. --*/
  266. {
  267. DWORD result;
  268. BOOL exception = FALSE;
  269. TCHAR *comp;
  270. LONG id;
  271. int i;
  272. #ifdef DEBUGPERFTRACE
  273. DWORD tick;
  274. #endif
  275. // don't call dead components
  276. id = OcManager->CurrentComponentStringId;
  277. sapiAssert(id > 0);
  278. if (pOcComponentWasRemoved(OcManager, id))
  279. return NO_ERROR;
  280. sapiAssert(Oc->InstallationRoutine);
  281. #ifdef PRERELEASE
  282. #ifdef DBG
  283. ASSERT_HEAP_IS_VALID("The process heap was corrupted before calling the component.");
  284. #if 0
  285. if (FTestForOutstandingCoInits() != S_OK) {
  286. sapiAssert( FALSE && "There is an unbalanced call to CoInitialize()");
  287. }
  288. #endif
  289. #endif
  290. #endif
  291. #ifdef DEBUGPERFTRACE
  292. TRACE(( TEXT("before calling component\n") ));
  293. DebugLogPerf();
  294. tick = GetTickCount();
  295. TRACE(( TEXT("calling component, %d:\n"), tick ));
  296. #endif
  297. try {
  298. result = Oc->InstallationRoutine(ComponentId, SubcomponentId, Function, Param1, Param2);
  299. } except(efilter(GetExceptionInformation())) {
  300. exception = TRUE;
  301. }
  302. #ifdef DEBUGPERFTRACE
  303. TRACE(( TEXT("after calling component, %d (time = %d)\n"),GetTickCount(), GetTickCount() - tick));
  304. DebugLogPerf();
  305. #endif
  306. #ifdef PRERELEASE
  307. #ifdef DBG
  308. ASSERT_HEAP_IS_VALID("The process heap was corrupted after calling the component. If you did not get an assertion before calling the component, this indicates an error in the component. Click yes and get a stack trace to detect the component.");
  309. #if 0
  310. if (FTestForOutstandingCoInits() != S_OK) {
  311. sapiAssert( FALSE && "There is an unbalanced call to CoInitialize()");
  312. }
  313. #endif
  314. #endif
  315. #endif
  316. if (exception) {
  317. #ifdef UNICODE
  318. if (Oc->Flags & OCFLAG_ANSI)
  319. comp = pSetupAnsiToUnicode(ComponentId);
  320. else
  321. #endif
  322. comp = (TCHAR *)ComponentId;
  323. _LogError(
  324. OcManager,
  325. OcErrLevError|MB_ICONEXCLAMATION|MB_OK,
  326. MSG_OC_EXCEPTION_IN_COMPONENT,
  327. comp,
  328. Oc->InstallationRoutine,
  329. Function,
  330. Param1,
  331. Param2,
  332. gecode,
  333. geaddr
  334. );
  335. #ifdef UNICODE
  336. if (Oc->Flags & OCFLAG_ANSI)
  337. pSetupFree(comp);
  338. #endif
  339. sapiAssert(0);
  340. pOcRemoveComponent(OcManager, id, pidCallComponent);
  341. result = ERROR_CALL_COMPONENT;
  342. }
  343. return result;
  344. }
  345. UINT
  346. OcInterfacePreinitialize(
  347. IN OUT POC_MANAGER OcManager,
  348. IN LONG ComponentId
  349. )
  350. /*++
  351. Routine Description:
  352. Sets up and calls the OC_PREINITIALIZE function for a
  353. given component.
  354. Arguments:
  355. OcManager - supplies a pointer to the context data structure
  356. for the OC Manager.
  357. ComponentId - supplies the string id of the component whose
  358. interface routine is to be called. This is for a string in
  359. the ComponentStringTable string table (a handle to which
  360. is in the OcManager structure).
  361. Return Value:
  362. Flags bitfield (OCFLAG_xxx) for the component. 0 means error.
  363. --*/
  364. {
  365. BOOL b;
  366. UINT FlagsIn;
  367. UINT FlagsOut;
  368. OPTIONAL_COMPONENT Oc;
  369. #ifdef UNICODE
  370. CHAR AnsiName[250];
  371. LPCWSTR UnicodeName;
  372. #endif
  373. TRACE((
  374. TEXT("OCM: OC_PREINITIALIZE Component %s..."),
  375. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId)
  376. ));
  377. //
  378. // Set up input flags.
  379. //
  380. FlagsIn = OCFLAG_ANSI;
  381. #ifdef UNICODE
  382. FlagsIn |= OCFLAG_UNICODE;
  383. UnicodeName = pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId);
  384. if(!UnicodeName) {
  385. return(0);
  386. }
  387. WideCharToMultiByte(CP_ACP,0,UnicodeName,-1,AnsiName,sizeof(AnsiName),NULL,NULL);
  388. #endif
  389. b = pOcInterface(
  390. OcManager,
  391. &FlagsOut,
  392. ComponentId,
  393. #ifdef UNICODE
  394. (LPCTSTR)AnsiName,
  395. #else
  396. NULL,
  397. #endif
  398. OC_PREINITIALIZE,
  399. FlagsIn,
  400. 0
  401. );
  402. TRACE(( TEXT("...%x (retval %s)\n"), FlagsOut, b ? TEXT("TRUE") : TEXT("FALSE") ));
  403. if(!b) {
  404. goto error;
  405. }
  406. //
  407. // If neither flag is set, error.
  408. //
  409. if(!(FlagsOut & (OCFLAG_ANSI | OCFLAG_UNICODE))) {
  410. goto error;
  411. }
  412. #ifdef UNICODE
  413. //
  414. // Use Unicode if it is supported by the component.
  415. //
  416. if(FlagsOut & OCFLAG_UNICODE) {
  417. FlagsOut = OCFLAG_UNICODE;
  418. }
  419. #else
  420. //
  421. // If ANSI is not supported then we've got a problem.
  422. //
  423. if(FlagsOut & OCFLAG_ANSI) {
  424. FlagsOut = OCFLAG_ANSI;
  425. } else {
  426. goto error;
  427. }
  428. #endif
  429. goto eof;
  430. error:
  431. pOcRemoveComponent(OcManager, ComponentId, pidPreInit);
  432. FlagsOut = 0;
  433. eof:
  434. return(FlagsOut);
  435. }
  436. UINT
  437. OcInterfaceInitComponent(
  438. IN OUT POC_MANAGER OcManager,
  439. IN LONG ComponentId
  440. )
  441. /*++
  442. Routine Description:
  443. Sets up and calls the OC_INIT_COMPONENT interface function for a
  444. given component.
  445. Arguments:
  446. OcManager - supplies a pointer to the context data structure
  447. for the OC Manager.
  448. ComponentId - supplies the string id of the component whose
  449. interface routine is to be called. This is for a string in
  450. the ComponentStringTable string table (a handle to which
  451. is in the OcManager structure).
  452. Return Value:
  453. Win32 error indicating value returned by the component.
  454. --*/
  455. {
  456. OPTIONAL_COMPONENT Oc;
  457. OC_INF OcInf;
  458. BOOL b;
  459. SETUP_INIT_COMPONENTA InitDataA;
  460. #ifdef UNICODE
  461. SETUP_INIT_COMPONENTW InitDataW;
  462. #endif
  463. UINT u;
  464. PUINT pu;
  465. PHELPER_CONTEXT HelperContext;
  466. #ifdef UNICODE
  467. ZeroMemory( &InitDataW, sizeof( InitDataW ));
  468. #else
  469. ZeroMemory( &InitDataA, sizeof( InitDataA ));
  470. #endif
  471. TRACE((
  472. TEXT("OCM: OC_INIT_COMPONENT Component %s..."),
  473. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId)
  474. ));
  475. HelperContext = pSetupMalloc(sizeof(HELPER_CONTEXT));
  476. if(!HelperContext) {
  477. return(ERROR_NOT_ENOUGH_MEMORY);
  478. }
  479. HelperContext->OcManager = OcManager;
  480. HelperContext->ComponentStringId = ComponentId;
  481. //
  482. // Fetch the optional component data.
  483. //
  484. b = pSetupStringTableGetExtraData(
  485. OcManager->ComponentStringTable,
  486. ComponentId,
  487. &Oc,
  488. sizeof(OPTIONAL_COMPONENT)
  489. );
  490. if(b) {
  491. if(Oc.InfStringId == -1) {
  492. OcInf.Handle = NULL;
  493. b = TRUE;
  494. } else {
  495. b = pSetupStringTableGetExtraData(
  496. OcManager->InfListStringTable,
  497. Oc.InfStringId,
  498. &OcInf,
  499. sizeof(OC_INF)
  500. );
  501. }
  502. }
  503. if(!b) {
  504. //
  505. // Strange case, should never get here.
  506. //
  507. pSetupFree(HelperContext);
  508. return(ERROR_INVALID_PARAMETER);
  509. }
  510. //
  511. // Set up the main part of the initialization structure
  512. // and the HelperRoutines table.
  513. //
  514. // Also set up the SetupData part of the initialization structure.
  515. // This is specific to the environment in which the OC Manager
  516. // common library is linked, so we call out to a routine that
  517. // lives elsewhere to do this part.
  518. //
  519. #ifdef UNICODE
  520. if(Oc.Flags & OCFLAG_UNICODE) {
  521. InitDataW.HelperRoutines = HelperRoutinesW;
  522. InitDataW.OCManagerVersion = OCMANAGER_VERSION;
  523. InitDataW.ComponentVersion = 0;
  524. InitDataW.OCInfHandle = OcManager->MasterOcInf;
  525. InitDataW.ComponentInfHandle = OcInf.Handle;
  526. InitDataW.HelperRoutines.OcManagerContext = HelperContext;
  527. OcFillInSetupDataW(&InitDataW.SetupData);
  528. pu = &InitDataW.ComponentVersion;
  529. b = pOcInterface(OcManager,&u,ComponentId,NULL,OC_INIT_COMPONENT,0,&InitDataW);
  530. } else
  531. #endif
  532. {
  533. InitDataA.HelperRoutines = HelperRoutinesA;
  534. InitDataA.OCManagerVersion = OCMANAGER_VERSION;
  535. InitDataA.ComponentVersion = 0;
  536. InitDataA.OCInfHandle = OcManager->MasterOcInf;
  537. InitDataA.ComponentInfHandle = OcInf.Handle;
  538. InitDataA.HelperRoutines.OcManagerContext = HelperContext;
  539. OcFillInSetupDataA(&InitDataA.SetupData);
  540. pu = &InitDataA.ComponentVersion;
  541. b = pOcInterface(OcManager,&u,ComponentId,NULL,OC_INIT_COMPONENT,0,&InitDataA);
  542. }
  543. TRACE(( TEXT("...returns %d, expect version %x\n"), u, *pu ));
  544. if(b) {
  545. if(u == NO_ERROR) {
  546. //
  547. // Remember the version of the OC Manager that the
  548. // component expects to be dealing with.
  549. //
  550. Oc.ExpectedVersion = *pu;
  551. Oc.HelperContext = HelperContext;
  552. pSetupStringTableSetExtraData(
  553. OcManager->ComponentStringTable,
  554. ComponentId,
  555. &Oc,
  556. sizeof(OPTIONAL_COMPONENT)
  557. );
  558. }
  559. } else {
  560. u = ERROR_INVALID_PARAMETER;
  561. }
  562. if(u != NO_ERROR) {
  563. pSetupFree(HelperContext);
  564. pOcRemoveComponent(OcManager, ComponentId, pidInitComponent);
  565. }
  566. return(u);
  567. }
  568. UINT
  569. OcInterfaceExtraRoutines(
  570. IN OUT POC_MANAGER OcManager,
  571. IN LONG ComponentId
  572. )
  573. /*++
  574. Routine Description:
  575. Sets up and calls the OC_EXTRA_ROUTINES interface function for a
  576. given component.
  577. Arguments:
  578. OcManager - supplies a pointer to the context data structure
  579. for the OC Manager.
  580. ComponentId - supplies the string id of the component whose
  581. interface routine is to be called. This is for a string in
  582. the ComponentStringTable string table (a handle to which
  583. is in the OcManager structure).
  584. Return Value:
  585. Win32 error indicating value returned by the component.
  586. --*/
  587. {
  588. BOOL b;
  589. UINT u;
  590. PVOID param2;
  591. OPTIONAL_COMPONENT Oc;
  592. TRACE((
  593. TEXT("OC: OC_EXTRA_ROUTINES Component %s\n"),
  594. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId)
  595. ));
  596. //
  597. // Fetch the optional component data.
  598. //
  599. b = pSetupStringTableGetExtraData(
  600. OcManager->ComponentStringTable,
  601. ComponentId,
  602. &Oc,
  603. sizeof(OPTIONAL_COMPONENT)
  604. );
  605. if(!b) {
  606. //
  607. // Strange case, should never get here.
  608. //
  609. return ERROR_INVALID_PARAMETER;
  610. }
  611. #ifdef UNICODE
  612. if (Oc.Flags & OCFLAG_UNICODE)
  613. b = pOcInterface(OcManager, &u, ComponentId, NULL, OC_EXTRA_ROUTINES, 0, &ExtraRoutinesW);
  614. else
  615. #endif
  616. b = pOcInterface(OcManager, &u, ComponentId, NULL, OC_EXTRA_ROUTINES, 0, &ExtraRoutinesA);
  617. TRACE(( TEXT("...returns %d (retval %s)\n"),
  618. u,
  619. b ? TEXT("TRUE") : TEXT("FALSE") ));
  620. if (!b)
  621. u = ERROR_INVALID_PARAMETER;
  622. if(u != NO_ERROR)
  623. pOcRemoveComponent(OcManager, ComponentId, pidExtraRoutines);
  624. return u;
  625. }
  626. SubComponentState
  627. OcInterfaceQueryState(
  628. IN OUT POC_MANAGER OcManager,
  629. IN LONG ComponentId,
  630. IN LPCTSTR Subcomponent,
  631. IN UINT WhichState
  632. )
  633. /*++
  634. Routine Description:
  635. Sets up and calls OC_QUERY_STATE interface routine.
  636. Arguments:
  637. OcManager - supplies oc manager context
  638. ComponentId - supplies the string id for the top-level component
  639. whose subcomponent is being detected/queried
  640. Subcomponent - supplies the name of the subcomponent whose
  641. state is to be detected/queried.
  642. WhichState - one of OCSELSTATETYPE_ORIGINAL or OCSELSTATETYPE_CURRENT.
  643. Return Value:
  644. Member of the SubComponentState enum indicating what to do.
  645. If an error occurs, SubcompUseOcManagerDefault will be returned.
  646. There is no error return.
  647. --*/
  648. {
  649. SubComponentState s;
  650. TRACE((
  651. TEXT("OCM: OC_QUERY_STATE Comp(%s) Sub(%s)"),
  652. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId),
  653. Subcomponent == NULL ? TEXT("NULL") : Subcomponent
  654. ));
  655. if(pOcInterface(OcManager,(PUINT)&s,ComponentId,Subcomponent,OC_QUERY_STATE,WhichState,0)) {
  656. TRACE(( TEXT("...returns TRUE (%d state)\n"), s ));
  657. if((s != SubcompOn) && (s != SubcompOff)) {
  658. s = SubcompUseOcManagerDefault;
  659. }
  660. } else {
  661. TRACE(( TEXT("...returns FALSE\n") ));
  662. s = SubcompUseOcManagerDefault;
  663. }
  664. return(s);
  665. }
  666. BOOL
  667. OcInterfaceSetLanguage(
  668. IN OUT POC_MANAGER OcManager,
  669. IN LONG ComponentId,
  670. IN WORD LanguageId
  671. )
  672. /*++
  673. Routine Description:
  674. Sets up and calls the OC_SET_LANGUAGE interface function for a
  675. given component.
  676. Arguments:
  677. OcManager - supplies a pointer to the context data structure
  678. for the OC Manager.
  679. ComponentId - supplies the string id of the component whose
  680. interface routine is to be called. This is for a string in
  681. the ComponentStringTable string table (a handle to which
  682. is in the OcManager structure).
  683. LanguageId - supplies the Win32 language id to pass to the component.
  684. Return Value:
  685. TRUE if the component indicated it could support the language.
  686. FALSE otherwise.
  687. --*/
  688. {
  689. LPCTSTR p;
  690. BOOL b;
  691. BOOL Result = FALSE;
  692. TRACE((
  693. TEXT("OCM: OC_SET_LANGUAGE Comp(%s)LanguageId %d..."),
  694. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId),
  695. LanguageId
  696. ));
  697. b = pOcInterface(OcManager,&Result,ComponentId,NULL,OC_SET_LANGUAGE,LanguageId,NULL);
  698. TRACE(( TEXT("...returns %d (retval %s)\n"),
  699. Result ? TEXT("TRUE") : TEXT("FALSE"),
  700. b ? TEXT("TRUE") : TEXT("FALSE") ));
  701. if(!b) {
  702. Result = FALSE;
  703. }
  704. return(Result);
  705. }
  706. HBITMAP
  707. OcInterfaceQueryImage(
  708. IN OUT POC_MANAGER OcManager,
  709. IN LONG ComponentId,
  710. IN LPCTSTR Subcomponent,
  711. IN SubComponentInfo WhichImage,
  712. IN UINT DesiredWidth,
  713. IN UINT DesiredHeight
  714. )
  715. /*++
  716. Routine Description:
  717. Sets up and calls the OC_QUERY_IMAGE interface function for a
  718. given component.
  719. Arguments:
  720. OcManager - supplies a pointer to the context data structure
  721. for the OC Manager.
  722. ComponentId - supplies the string id of the component whose
  723. interface routine is to be called. This is for a string in
  724. the ComponentStringTable string table (a handle to which
  725. is in the OcManager structure).
  726. Subcomponent - supplies the name of the subcomponent for which
  727. to request the image.
  728. WhichImage - specifies which image is desired.
  729. DesiredWidth - specifies desired width, in pixels, of the bitmap.
  730. DesiredHeight - specifies desired height, in pixels, of the bitmap.
  731. Return Value:
  732. GDI handle to the bitmap as returned by the component,
  733. or NULL if an error occurred.
  734. --*/
  735. {
  736. LPCTSTR p;
  737. BOOL b;
  738. HBITMAP Bitmap = NULL;
  739. TRACE((
  740. TEXT("OCM: OC_QUERY_IMAGE Comp(%s) Sub(%s)..."),
  741. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId),
  742. Subcomponent == NULL ? TEXT("NULL") : Subcomponent
  743. ));
  744. b = pOcInterface(
  745. OcManager,
  746. (PUINT)&Bitmap,
  747. ComponentId,
  748. Subcomponent,
  749. OC_QUERY_IMAGE,
  750. WhichImage,
  751. LongToPtr(MAKELONG(DesiredWidth,DesiredHeight))
  752. );
  753. TRACE(( TEXT("...returns %s, (retval 0x%08x)\n"),
  754. b ? TEXT("TRUE") : TEXT("FALSE"),
  755. (ULONG_PTR)Bitmap ));
  756. if(!b) {
  757. Bitmap = NULL;
  758. }
  759. return(Bitmap);
  760. }
  761. HBITMAP
  762. OcInterfaceQueryImageEx(
  763. IN OUT POC_MANAGER OcManager,
  764. IN LONG ComponentId,
  765. IN LPCTSTR Subcomponent,
  766. IN SubComponentInfo WhichImage,
  767. IN UINT DesiredWidth,
  768. IN UINT DesiredHeight
  769. )
  770. /*++
  771. Routine Description:
  772. Sets up and calls the OC_QUERY_IMAGE interface function for a
  773. given component.
  774. Arguments:
  775. OcManager - supplies a pointer to the context data structure
  776. for the OC Manager.
  777. ComponentId - supplies the string id of the component whose
  778. interface routine is to be called. This is for a string in
  779. the ComponentStringTable string table (a handle to which
  780. is in the OcManager structure).
  781. Subcomponent - supplies the name of the subcomponent for which
  782. to request the image.
  783. WhichImage - specifies which image is desired.
  784. DesiredWidth - specifies desired width, in pixels, of the bitmap.
  785. DesiredHeight - specifies desired height, in pixels, of the bitmap.
  786. Return Value:
  787. GDI handle to the bitmap as returned by the component,
  788. or NULL if an error occurred.
  789. --*/
  790. {
  791. LPCTSTR p;
  792. BOOL b;
  793. BOOL Result = FALSE;
  794. HBITMAP Bitmap = NULL;
  795. OC_QUERY_IMAGE_INFO QueryImageInfo;
  796. QueryImageInfo.SizeOfStruct = sizeof(QueryImageInfo);
  797. QueryImageInfo.ComponentInfo = WhichImage;
  798. QueryImageInfo.DesiredWidth = DesiredWidth;
  799. QueryImageInfo.DesiredHeight = DesiredHeight;
  800. TRACE((
  801. TEXT("OCM: OC_QUERY_IMAGE_EX Comp(%s) Sub(%s)..."),
  802. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId),
  803. Subcomponent == NULL ? TEXT("NULL") : Subcomponent
  804. ));
  805. b = pOcInterface(
  806. OcManager,
  807. &Result,
  808. ComponentId,
  809. Subcomponent,
  810. OC_QUERY_IMAGE_EX,
  811. (UINT_PTR)&QueryImageInfo,
  812. &Bitmap
  813. );
  814. TRACE(( TEXT("...returns %s, (retval = %s)\n"),
  815. Result ? TEXT("TRUE") : TEXT("FALSE"),
  816. b ? TEXT("TRUE") : TEXT("FALSE") ));
  817. if(!b) {
  818. Bitmap = NULL;
  819. }
  820. return((Result == TRUE) ? Bitmap : NULL);
  821. }
  822. UINT
  823. OcInterfaceRequestPages(
  824. IN OUT POC_MANAGER OcManager,
  825. IN LONG ComponentId,
  826. IN WizardPagesType WhichPages,
  827. OUT PSETUP_REQUEST_PAGES *RequestPages
  828. )
  829. /*++
  830. Routine Description:
  831. Sets up and calls the OC_REQUEST_PAGES interface function for a
  832. given component.
  833. Note that this routine does not enforce any policy regarding whether
  834. the component is *supposed* to be asked for pages, ordering, etc.
  835. The caller is expected to do that.
  836. Arguments:
  837. OcManager - supplies a pointer to the context data structure
  838. for the OC Manager.
  839. ComponentId - supplies the string id of the component whose
  840. interface routine is to be called. This is for a string in
  841. the ComponentStringTable string table (a handle to which
  842. is in the OcManager structure).
  843. WhichPages - specifies which set of pages is to be requested.
  844. RequestPages - on successful return, receives a pointer to
  845. a SETUP_REQUEST_PAGES structure containing a count and handles
  846. for returned pages. The caller can free this structure with
  847. pSetupFree() when it is no longer needed.
  848. Return Value:
  849. Win32 error code indicating outcome.
  850. --*/
  851. {
  852. UINT PageCount;
  853. PSETUP_REQUEST_PAGES pages;
  854. PVOID p;
  855. BOOL b;
  856. UINT ec;
  857. //
  858. // Start with room for 10 pages.
  859. //
  860. #define INITIAL_PAGE_CAPACITY 10
  861. TRACE((
  862. TEXT("OCM: OC_REQUEST_PAGES Component %s..."),
  863. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId)
  864. ));
  865. pages = pSetupMalloc(offsetof(SETUP_REQUEST_PAGES,Pages)
  866. + (INITIAL_PAGE_CAPACITY * sizeof(HPROPSHEETPAGE)));
  867. if(!pages) {
  868. return(ERROR_NOT_ENOUGH_MEMORY);
  869. }
  870. pages->MaxPages = INITIAL_PAGE_CAPACITY;
  871. b = pOcInterface(
  872. OcManager,
  873. &PageCount,
  874. ComponentId,
  875. NULL,
  876. OC_REQUEST_PAGES,
  877. WhichPages,
  878. pages
  879. );
  880. if(b && (PageCount != (UINT)(-1)) && (PageCount > INITIAL_PAGE_CAPACITY)) {
  881. p = pSetupRealloc(
  882. pages,
  883. offsetof(SETUP_REQUEST_PAGES,Pages) + (PageCount * sizeof(HPROPSHEETPAGE))
  884. );
  885. if(p) {
  886. pages = p;
  887. } else {
  888. pSetupFree(pages);
  889. return(ERROR_NOT_ENOUGH_MEMORY);
  890. }
  891. pages->MaxPages = PageCount;
  892. b = pOcInterface(
  893. OcManager,
  894. &PageCount,
  895. ComponentId,
  896. NULL,
  897. OC_REQUEST_PAGES,
  898. WhichPages,
  899. pages
  900. );
  901. }
  902. TRACE(( TEXT("...returns %d pages (retval %s)\n"),
  903. PageCount,
  904. b ? TEXT("TRUE") : TEXT("FALSE") ));
  905. if(!b) {
  906. pSetupFree(pages);
  907. return ERROR_CALL_COMPONENT;
  908. }
  909. if(PageCount == (UINT)(-1)) {
  910. ec = GetLastError();
  911. pSetupFree(pages);
  912. pOcRemoveComponent(OcManager, ComponentId, pidRequestPages);
  913. return(ec);
  914. }
  915. //
  916. // Success. Realloc the array down to its final size and return.
  917. //
  918. p = pSetupRealloc(
  919. pages,
  920. offsetof(SETUP_REQUEST_PAGES,Pages) + (PageCount * sizeof(HPROPSHEETPAGE))
  921. );
  922. if(p) {
  923. pages = p;
  924. pages->MaxPages = PageCount;
  925. *RequestPages = pages;
  926. return(NO_ERROR);
  927. }
  928. pSetupFree(pages);
  929. return(ERROR_NOT_ENOUGH_MEMORY);
  930. }
  931. BOOL
  932. OcInterfaceQuerySkipPage(
  933. IN OUT POC_MANAGER OcManager,
  934. IN LONG ComponentId,
  935. IN OcManagerPage WhichPage
  936. )
  937. /*++
  938. Routine Description:
  939. This routine asks a component dll (identified by a top-level
  940. component's string id) whether it wants to skip displaying
  941. a particular page that is owned by the oc manager.
  942. Arguments:
  943. OcManager - supplies OC Manager context
  944. ComponentId - supplies string id of a top-level component
  945. WhichPage - supplies a value indicating which page oc manager
  946. is asking the component about.
  947. Return Value:
  948. Boolean value indicating whether the component wants to skip
  949. the page.
  950. --*/
  951. {
  952. BOOL Result;
  953. BOOL b;
  954. TRACE((
  955. TEXT("OCM: OC_QUERY_SKIP_PAGE Component %s Page %d..."),
  956. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId),
  957. WhichPage
  958. ));
  959. //
  960. // Send out the notification to the component DLL.
  961. //
  962. b = pOcInterface(
  963. OcManager,
  964. &Result,
  965. ComponentId,
  966. NULL,
  967. OC_QUERY_SKIP_PAGE,
  968. WhichPage,
  969. NULL
  970. );
  971. TRACE(( TEXT("...returns %x (retval %s)\n"),
  972. Result,
  973. b ? TEXT("TRUE") : TEXT("FALSE") ));
  974. if(b) {
  975. b = Result;
  976. } else {
  977. //
  978. // Error calling component, don't skip page.
  979. //
  980. b = FALSE;
  981. }
  982. return(b);
  983. }
  984. BOOL
  985. OcInterfaceNeedMedia(
  986. IN OUT POC_MANAGER OcManager,
  987. IN LONG ComponentId,
  988. IN PSOURCE_MEDIA SourceMedia,
  989. OUT LPTSTR NewPath
  990. )
  991. /*++
  992. Routine Description:
  993. This routine invokes the OC_NEED_MEDIA interface entry point
  994. for a (top-level) component.
  995. Arguments:
  996. OcManager - supplies OC Manager context
  997. ComponentId - supplies string id of top level component
  998. SourceMedia - supplies setupapi source media description
  999. NewPath - receives path where files on media are to be found
  1000. Return Value:
  1001. Boolean value indicating outcome.
  1002. --*/
  1003. {
  1004. BOOL Result;
  1005. BOOL b;
  1006. TRACE((
  1007. TEXT("OCM: OC_NEED_MEDIA Component %s..."),
  1008. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId)
  1009. ));
  1010. //
  1011. // Send out the notification to the component DLL.
  1012. //
  1013. b = pOcInterface(
  1014. OcManager,
  1015. &Result,
  1016. ComponentId,
  1017. NULL,
  1018. OC_NEED_MEDIA,
  1019. (UINT_PTR)SourceMedia,
  1020. NewPath
  1021. );
  1022. TRACE(( TEXT("...returns %x (retval %s, NewPath %s)\n"),
  1023. Result,
  1024. b ? TEXT("TRUE") : TEXT("FALSE"),
  1025. NewPath ? NewPath : TEXT("NULL")
  1026. ));
  1027. if(b) {
  1028. b = Result;
  1029. }
  1030. return(b);
  1031. }
  1032. BOOL
  1033. OcInterfaceFileBusy(
  1034. IN OUT POC_MANAGER OcManager,
  1035. IN LONG ComponentId,
  1036. IN PFILEPATHS FilePaths,
  1037. OUT LPTSTR NewPath
  1038. )
  1039. /*++
  1040. Routine Description:
  1041. This routine invokes the OC_FILE_BUSY interface entry point
  1042. for a (top-level) component.
  1043. Arguments:
  1044. OcManager - supplies OC Manager context
  1045. ComponentId - supplies string id of top level component
  1046. SourceMedia - supplies setupapi source media description
  1047. NewPath - receives path where files on media are to be found
  1048. Return Value:
  1049. Boolean value indicating outcome.
  1050. --*/
  1051. {
  1052. BOOL Result;
  1053. BOOL b;
  1054. TRACE((
  1055. TEXT("OCM: OC_FILE_BUSY Component %s..."),
  1056. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId)
  1057. ));
  1058. //
  1059. // Send out the notification to the component DLL.
  1060. //
  1061. b = pOcInterface(
  1062. OcManager,
  1063. &Result,
  1064. ComponentId,
  1065. NULL,
  1066. OC_FILE_BUSY,
  1067. (UINT_PTR)FilePaths,
  1068. NewPath
  1069. );
  1070. TRACE(( TEXT("...returns %x (retval %s, newpath %s)\n"),
  1071. Result,
  1072. b ? TEXT("TRUE") : TEXT("FALSE"),
  1073. NewPath ? NewPath : TEXT("NULL") ));
  1074. if(b) {
  1075. b = Result;
  1076. }
  1077. return(b);
  1078. }
  1079. BOOL
  1080. OcInterfaceQueryChangeSelState(
  1081. IN OUT POC_MANAGER OcManager,
  1082. IN LONG ComponentId,
  1083. IN LPCTSTR Subcomponent,
  1084. IN BOOL Selected,
  1085. IN UINT Flags
  1086. )
  1087. /*++
  1088. Routine Description:
  1089. Sets up and calls the OC_QUERY_CHANGE_SEL_STATE interface function
  1090. for a given component and subcomponent.
  1091. Arguments:
  1092. OcManager - supplies a pointer to the context data structure
  1093. for the OC Manager.
  1094. ComponentId - supplies the string id of the component whose
  1095. interface routine is to be called. This is for a string in
  1096. the ComponentStringTable string table (a handle to which
  1097. is in the OcManager structure).
  1098. Subcomponent - supplies the name of the subcomponent whose
  1099. selection state is potentially to be changed.
  1100. Selected - if TRUE then the proposed new selection state is
  1101. "selected." If FALSE then the proposed new selection state
  1102. is "unselected."
  1103. Flags - supplies misc flags to be passed to the interface routine
  1104. as param2.
  1105. Return Value:
  1106. TRUE if the new selection state should be accepted.
  1107. --*/
  1108. {
  1109. BOOL b;
  1110. UINT Result;
  1111. TRACE((
  1112. TEXT("OCM: OC_QUERY_CHANGE_SEL_STATE Comp(%s) Sub(%s) State %d..."),
  1113. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId),
  1114. Subcomponent == NULL ? TEXT("NULL") : Subcomponent,
  1115. Selected
  1116. ));
  1117. b = pOcInterface(
  1118. OcManager,
  1119. &Result,
  1120. ComponentId,
  1121. Subcomponent,
  1122. OC_QUERY_CHANGE_SEL_STATE,
  1123. Selected,
  1124. UlongToPtr((Flags & OCQ_ACTUAL_SELECTION))
  1125. );
  1126. TRACE(( TEXT("...returns %x (retval %s)\n"),
  1127. Result,
  1128. b ? TEXT("TRUE") : TEXT("FALSE") ));
  1129. if(!b) {
  1130. //
  1131. // If we can't call the component for some reason,
  1132. // allow the new state.
  1133. //
  1134. Result = TRUE;
  1135. }
  1136. return(Result);
  1137. }
  1138. VOID
  1139. OcInterfaceWizardCreated(
  1140. IN OUT POC_MANAGER OcManager,
  1141. IN LONG ComponentId,
  1142. IN HWND DialogHandle
  1143. )
  1144. /*++
  1145. Routine Description:
  1146. Sets up and calls the OC_WIZARD_CREATED interface function
  1147. for a given component.
  1148. Arguments:
  1149. OcManager - supplies a pointer to the context data structure
  1150. for the OC Manager.
  1151. ComponentId - supplies the string id of the component whose
  1152. interface routine is to be called. This is for a string in
  1153. the ComponentStringTable string table (a handle to which
  1154. is in the OcManager structure).
  1155. DialogHandle - Supplies wizard dialog handle.
  1156. Return Value:
  1157. None.
  1158. --*/
  1159. {
  1160. UINT Result;
  1161. BOOL b;
  1162. TRACE((
  1163. TEXT("OCM: OC_WIZARD_CREATED Component %s..."),
  1164. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId)
  1165. ));
  1166. b = pOcInterface(
  1167. OcManager,
  1168. &Result,
  1169. ComponentId,
  1170. NULL,
  1171. OC_WIZARD_CREATED,
  1172. 0,
  1173. DialogHandle
  1174. );
  1175. TRACE(( TEXT("...returns %x (retval %s)\n"),
  1176. Result,
  1177. b ? TEXT("TRUE") : TEXT("FALSE") ));
  1178. }
  1179. UINT
  1180. OcInterfaceCalcDiskSpace(
  1181. IN OUT POC_MANAGER OcManager,
  1182. IN LONG ComponentId,
  1183. IN LPCTSTR Subcomponent,
  1184. IN HDSKSPC DiskSpaceList,
  1185. IN BOOL AddingToList
  1186. )
  1187. /*++
  1188. Routine Description:
  1189. Sets up and calls the OC_CALC_DISK_SPACE interface function for a
  1190. given component and subcomponent.
  1191. Arguments:
  1192. OcManager - supplies a pointer to the context data structure
  1193. for the OC Manager.
  1194. ComponentId - supplies the string id of the component whose
  1195. interface routine is to be called. This is for a string in
  1196. the ComponentStringTable string table (a handle to which
  1197. is in the OcManager structure).
  1198. Subcomponent - supplies the name of the subcomponent whose files
  1199. are to be added or removed. This may be NULL, such as when
  1200. there is no per-component inf.
  1201. DiskSpaceList - supplies a SETUPAPI disk space list handle.
  1202. AddingToList - if TRUE, the component is being directed to add
  1203. files for the (sub)component. If FALSE, the component is
  1204. being directed to remove files.
  1205. Return Value:
  1206. Win32 error code indicating outcome.
  1207. --*/
  1208. {
  1209. BOOL b;
  1210. UINT Result;
  1211. TRACE((
  1212. TEXT("OCM: OC_CALC_DISK_SPACE Comp(%s) Sub(%s) AddtoList(%s)..."),
  1213. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId),
  1214. Subcomponent == NULL ? TEXT("NULL") : Subcomponent,
  1215. AddingToList ? TEXT("Yes") : TEXT("No")
  1216. ));
  1217. b = pOcInterface(
  1218. OcManager,
  1219. &Result,
  1220. ComponentId,
  1221. Subcomponent,
  1222. OC_CALC_DISK_SPACE,
  1223. AddingToList,
  1224. DiskSpaceList
  1225. );
  1226. TRACE(( TEXT("...returns %x (retval %s)\n"),
  1227. Result,
  1228. b ? TEXT("TRUE") : TEXT("FALSE") ));
  1229. if(!b) {
  1230. pOcRemoveComponent(OcManager, ComponentId, pidCalcDiskSpace);
  1231. Result = ERROR_INVALID_PARAMETER;
  1232. }
  1233. return(Result);
  1234. }
  1235. UINT
  1236. OcInterfaceQueueFileOps(
  1237. IN OUT POC_MANAGER OcManager,
  1238. IN LONG ComponentId,
  1239. IN LPCTSTR Subcomponent,
  1240. IN HSPFILEQ FileQueue
  1241. )
  1242. /*++
  1243. Routine Description:
  1244. Sets up and calls the OC_QUEUE_FILE_OPS interface function for a
  1245. given component and subcomponent.
  1246. Arguments:
  1247. OcManager - supplies a pointer to the context data structure
  1248. for the OC Manager.
  1249. ComponentId - supplies the string id of the component whose
  1250. interface routine is to be called. This is for a string in
  1251. the ComponentStringTable string table (a handle to which
  1252. is in the OcManager structure).
  1253. Subcomponent - supplies the name of the subcomponent whose file ops
  1254. are to be queued. This may be NULL, such as when there is no
  1255. per-component inf.
  1256. FileQueue - supplies a SETUPAPI file queue handle.
  1257. Return Value:
  1258. Win32 error code indicating outcome.
  1259. --*/
  1260. {
  1261. UINT Result;
  1262. TRACE((
  1263. TEXT("OCM: OC_QUEUE_FILE_OPS Comp(%s) Sub(%s)..."),
  1264. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId),
  1265. Subcomponent == NULL ? TEXT("NULL") : Subcomponent
  1266. ));
  1267. if(!pOcInterface(OcManager,&Result,ComponentId,Subcomponent,OC_QUEUE_FILE_OPS,0,FileQueue)) {
  1268. pOcRemoveComponent(OcManager, ComponentId, pidQueueFileOps);
  1269. TRACE(( TEXT("...(returns %x initially) "), Result ));
  1270. Result = ERROR_INVALID_PARAMETER;
  1271. }
  1272. TRACE(( TEXT("...returns %x\n"), Result ));
  1273. return(Result);
  1274. }
  1275. UINT
  1276. OcInterfaceQueryStepCount(
  1277. IN OUT POC_MANAGER OcManager,
  1278. IN LONG ComponentId,
  1279. IN LPCTSTR Subcomponent,
  1280. OUT PUINT StepCount
  1281. )
  1282. /*++
  1283. Routine Description:
  1284. Sets up and calls the OC_QUERY_STEP_COUNT interface function for a
  1285. given component and subcomponent.
  1286. Arguments:
  1287. OcManager - supplies a pointer to the context data structure
  1288. for the OC Manager.
  1289. ComponentId - supplies the string id of the component whose
  1290. interface routine is to be called. This is for a string in
  1291. the ComponentStringTable string table (a handle to which
  1292. is in the OcManager structure).
  1293. Subcomponent - supplies the name of the subcomponent whose step count
  1294. is to be determined. This may be NULL, such as when there is no
  1295. per-component inf.
  1296. StepCount - if the routine returns NO_ERROR then StepCount receives
  1297. the number of steps as returned by the component's interface routine.
  1298. Return Value:
  1299. Win32 error code indicating outcome.
  1300. --*/
  1301. {
  1302. UINT Result;
  1303. TRACE((
  1304. TEXT("OCM: OC_QUERY_STEP_COUNT Comp(%s) Sub(%s)..."),
  1305. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId),
  1306. Subcomponent == NULL ? TEXT("NULL") : Subcomponent
  1307. ));
  1308. if(pOcInterface(OcManager,StepCount,ComponentId,Subcomponent,OC_QUERY_STEP_COUNT,0,0)) {
  1309. if(*StepCount == (UINT)(-1)) {
  1310. Result = GetLastError();
  1311. } else {
  1312. Result = NO_ERROR;
  1313. }
  1314. } else {
  1315. Result = ERROR_INVALID_PARAMETER;
  1316. }
  1317. TRACE(( TEXT("...returns %s (%d steps)\n"),
  1318. Result ? TEXT("TRUE") : TEXT("FALSE"),
  1319. *StepCount ));
  1320. if (Result != NO_ERROR) {
  1321. pOcRemoveComponent(OcManager, ComponentId, pidQueryStepCount);
  1322. }
  1323. return(Result);
  1324. }
  1325. UINT
  1326. OcInterfaceCompleteInstallation(
  1327. IN OUT POC_MANAGER OcManager,
  1328. IN LONG ComponentId,
  1329. IN LPCTSTR Subcomponent,
  1330. IN BOOL PreQueueCommit
  1331. )
  1332. /*++
  1333. Routine Description:
  1334. Sets up and calls the OC_ABOUT_TO_COMMIT_QUEUE or
  1335. OC_COMPLETE_INSTALLATION interface function for a given
  1336. component and subcomponent.
  1337. Arguments:
  1338. OcManager - supplies a pointer to the context data structure
  1339. for the OC Manager.
  1340. ComponentId - supplies the string id of the component whose
  1341. interface routine is to be called. This is for a string in
  1342. the ComponentStringTable string table (a handle to which
  1343. is in the OcManager structure).
  1344. Subcomponent - supplies the name of the subcomponent whose
  1345. installation is to be completed. This may be NULL,
  1346. such as when there is no per-component inf.
  1347. PreQueueCommit - if non-0, then OC_ABOUT_TO_COMMIT_QUEUE is sent.
  1348. If 0, then OC_COMPLETE_INSTALLATION is sent.
  1349. Return Value:
  1350. Win32 error code indicating outcome.
  1351. --*/
  1352. {
  1353. UINT Result;
  1354. BOOL b;
  1355. LPTSTR p;
  1356. TCHAR DisplayText[300],FormatString[200];
  1357. OPTIONAL_COMPONENT Oc;
  1358. HELPER_CONTEXT Helper;
  1359. TRACE((
  1360. TEXT("OCM:%s Comp(%s) Sub(%s)..."),
  1361. PreQueueCommit ? TEXT("OC_ABOUT_TO_COMMIT_QUEUE") : TEXT("OC_COMPLETE_INSTALLATION"),
  1362. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId),
  1363. Subcomponent == NULL ? TEXT("NULL") : Subcomponent
  1364. ));
  1365. //
  1366. // update the installation text for this component
  1367. //
  1368. __try {
  1369. if (pSetupStringTableGetExtraData(
  1370. OcManager->ComponentStringTable,
  1371. ComponentId,
  1372. &Oc,
  1373. sizeof(OPTIONAL_COMPONENT)
  1374. ) && (*Oc.Description != 0)) {
  1375. p = Oc.Description;
  1376. } else if ((p = pSetupStringTableStringFromId(OcManager->ComponentStringTable, ComponentId)) != NULL) {
  1377. } else {
  1378. p = TEXT("Component");
  1379. }
  1380. LoadString(
  1381. MyModuleHandle,
  1382. PreQueueCommit
  1383. ? IDS_CONFIGURE_FORMAT
  1384. : IDS_INSTALL_FORMAT,
  1385. FormatString,
  1386. sizeof(FormatString)/sizeof(TCHAR)
  1387. );
  1388. wsprintf(DisplayText,FormatString,p);
  1389. Helper.OcManager = OcManager;
  1390. Helper.ComponentStringId = ComponentId;
  1391. #ifdef UNICODE
  1392. HelperRoutinesW.SetProgressText(&Helper,DisplayText);
  1393. #else
  1394. HelperRoutinesA.SetProgressText(&Helper,DisplayText);
  1395. #endif
  1396. } __except (EXCEPTION_EXECUTE_HANDLER) {
  1397. ERR(( TEXT("OCM: OcCompleteInstallation exception, ec = 0x%08x\n"), GetExceptionCode() ));
  1398. }
  1399. b = pOcInterface(
  1400. OcManager,
  1401. &Result,
  1402. ComponentId,
  1403. Subcomponent,
  1404. PreQueueCommit ? OC_ABOUT_TO_COMMIT_QUEUE : OC_COMPLETE_INSTALLATION,
  1405. 0,
  1406. 0
  1407. );
  1408. TRACE(( TEXT("...returns %x (retval %s)\n"),
  1409. Result,
  1410. b ? TEXT("TRUE") : TEXT("FALSE") ));
  1411. if(!b) {
  1412. Result = ERROR_INVALID_PARAMETER;
  1413. }
  1414. // Don't shutdown the component if it returns an error.
  1415. // Let them deal with it in OC_QUERY_STATE(SELSTATETYPE_FINAL)
  1416. return(Result);
  1417. }
  1418. VOID
  1419. OcInterfaceCleanup(
  1420. IN OUT POC_MANAGER OcManager,
  1421. IN LONG ComponentId
  1422. )
  1423. /*++
  1424. Routine Description:
  1425. Sets up and calls the OC_CLEANUP interface function for a
  1426. given component, to inform the component that it is about to be unloaded.
  1427. Arguments:
  1428. OcManager - supplies a pointer to the context data structure
  1429. for the OC Manager.
  1430. ComponentId - supplies the string id of the component whose
  1431. interface routine is to be called. This is for a string in
  1432. the ComponentStringTable string table (a handle to which
  1433. is in the OcManager structure).
  1434. Return Value:
  1435. None.
  1436. --*/
  1437. {
  1438. UINT DontCare;
  1439. BOOL b;
  1440. TRACE((
  1441. TEXT("OCM: OC_CLEANUP Comp(%s)..."),
  1442. pSetupStringTableStringFromId(OcManager->ComponentStringTable,ComponentId)
  1443. ));
  1444. b = pOcInterface(OcManager,&DontCare,ComponentId,NULL,OC_CLEANUP,0,0);
  1445. TRACE(( TEXT("...returns %x (retval %s)\n"),
  1446. DontCare,
  1447. b ? TEXT("TRUE") : TEXT("FALSE") ));
  1448. }