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.

3728 lines
104 KiB

  1. //=--------------------------------------------------------------------------=
  2. // proxy.cpp
  3. //=--------------------------------------------------------------------------=
  4. // Copyright (c) 1999, Microsoft Corp.
  5. // All Rights Reserved
  6. // Information Contained Herein Is Proprietary and Confidential.
  7. //=--------------------------------------------------------------------------=
  8. //
  9. // MMC Interfcace Proxy and Stub Functions
  10. //
  11. //=--------------------------------------------------------------------------=
  12. // This file contains proxy and stub functions for MMC methods that are not
  13. // remotable using a MIDL generated proxy and stub. Non-remotable methods have
  14. // parameters that are ambiguous i.e. can be casted to different data types.
  15. // For example, IComponentData::Notify() is passed an event and two additional
  16. // LPARAM arguments that are interpreted according to the event. Sometimes an
  17. // LPARAM contains a simple value such as a long or two BOOLs and sometimes it
  18. // contains an IDataObject *. MIDL doesn't know the difference between
  19. // MMCN_SELECT and MMCN_PRINT so we need to write some code to help out.
  20. //
  21. // The version of MMC.IDL in the designer directory has added a [local]
  22. // attribute to all non-remotable methods. In addition, an extra method has
  23. // been added to the same interface that is a remotable version of the method.
  24. // The remotable version has more parameters and represents the union of all
  25. // possible interpretations of the ambiguous parameter. For example,
  26. // IExtendControlbar::ControlbarNotify() is defined as:
  27. //
  28. // [helpstring("User actions"), local]
  29. // HRESULT ControlbarNotify([in] MMC_NOTIFY_TYPE event,
  30. // [in] LPARAM arg, [in] LPARAM param);
  31. //
  32. // This method can receive MMCN_SELECT, MMCN_BTN_CLICK, and MMCN_MENU_BTNCLICK.
  33. // The union of all possible parameter types is used in the following method
  34. // added to that interface:
  35. //
  36. //
  37. // HRESULT RemControlbarNotify([in] MMC_NOTIFY_TYPE event,
  38. // [in] LPARAM lparam,
  39. // [in] IDataObject *piDataObject,
  40. // [in] MENUBUTTONDATA *MenuButtonData);
  41. //
  42. // Note, that normal, in-proc, non-remoted versions of IExtendControlbar do not
  43. // have this extra method in their vtable because no one is going to call it.
  44. // It is only used in the MILD generated proxy object.
  45. //
  46. // In order to tell MIDL which method remotes ControlbarNotify() an attribute
  47. // control file (ACF) is used. The entry in the ACF for IExtendControlbar is:
  48. //
  49. // interface IExtendControlbar
  50. // {
  51. // [call_as (ControlbarNotify)]
  52. // RemControlbarNotify();
  53. //
  54. // }
  55. //
  56. // This says that RemControlbarNotify should be called when remoting
  57. // ControlbarNotify(). MIDL generates the proxy/stub code as usual but it only
  58. // generates the prototypes for ControlbarNotify proxy and stub. We have to
  59. // write these routines.
  60. //
  61. // When a remote client has an IExtendControlbarNotify pointer it actually
  62. // points into the proxy vtable. MIDL sets the ControlbarNotify entry pointing to
  63. // our IExtendControlbar_ControlbarNotify_Proxy() function below. That function
  64. // interprets the parameters and then calls the MIDL generated
  65. // IExtendControlbar_RemControlbarNotify_Proxy() that packs up the parameters
  66. // and sends them off to the server. If a parameters is not applicable, (e.g.
  67. // MMCN_SELECT does not receive a pointer to a MENUBUTTONDATA stuct), then a
  68. // pointer to an empty struct or zeroes are sent.
  69. //
  70. // When the packet reaches the server side the MIDL generated
  71. // IExtendControlbar_RemControlbarNotify_Stub() unpacks them and then calls our
  72. // IExtendControlbar_ControlbarNotify_Stub() passing it the parameters and the
  73. // IExtendControlbar pointer into the server. This function interprets the
  74. // parameters and then calls ControlbarNotify in the server.
  75. //
  76. //=--------------------------------------------------------------------------=
  77. #include "mmc.h"
  78. extern HRESULT GetClipboardFormat
  79. (
  80. WCHAR *pwszFormatName,
  81. CLIPFORMAT *pcfFormat
  82. );
  83. extern HRESULT CreateMultiSelDataObject
  84. (
  85. IDataObject **ppiDataObjects,
  86. long cDataObjects,
  87. IDataObject **ppiMultiSelDataObject
  88. );
  89. static HRESULT MenuButtonClickProxy
  90. (
  91. IExtendControlbar __RPC_FAR *This,
  92. IDataObject *piDataObject,
  93. MENUBUTTONDATA *pMenuButtonData
  94. );
  95. static HRESULT IsMultiSelect(IDataObject *piDataObject, BOOL *pfMultiSelect)
  96. {
  97. HRESULT hr = S_OK;
  98. DWORD *pdwMultiSelect = NULL;
  99. BOOL fGotData = FALSE;
  100. FORMATETC FmtEtc;
  101. STGMEDIUM StgMed;
  102. ZeroMemory(&FmtEtc, sizeof(FmtEtc));
  103. ZeroMemory(&StgMed, sizeof(StgMed));
  104. *pfMultiSelect = FALSE;
  105. if (NULL == piDataObject)
  106. {
  107. goto Cleanup;
  108. }
  109. if (IS_SPECIAL_DATAOBJECT(piDataObject))
  110. {
  111. goto Cleanup;
  112. }
  113. hr = GetClipboardFormat(CCF_MMC_MULTISELECT_DATAOBJECT, &FmtEtc.cfFormat);
  114. if (FAILED(hr))
  115. {
  116. goto Cleanup;
  117. }
  118. FmtEtc.dwAspect = DVASPECT_CONTENT;
  119. FmtEtc.lindex = -1L;
  120. FmtEtc.tymed = TYMED_HGLOBAL;
  121. StgMed.tymed = TYMED_HGLOBAL;
  122. hr = piDataObject->lpVtbl->GetData(piDataObject, &FmtEtc, &StgMed);
  123. if (SUCCEEDED(hr))
  124. {
  125. fGotData = TRUE;
  126. }
  127. else
  128. {
  129. hr = S_OK;
  130. }
  131. // Ignore any failures and assume that it is not multi-select. Snap-ins
  132. // should return DV_E_FORMATETC or DV_E_CLIPFORMAT but in practice that
  133. // is not the case. For example, the IIS snap-in returns E_NOTIMPL.
  134. // It would be impossible to cover the range of reasonable return codes so
  135. // we treat any error as format not supported.
  136. if (fGotData)
  137. {
  138. pdwMultiSelect = (DWORD *)GlobalLock(StgMed.hGlobal);
  139. if ((DWORD)1 == *pdwMultiSelect)
  140. {
  141. *pfMultiSelect = TRUE;
  142. }
  143. }
  144. Cleanup:
  145. if (NULL != pdwMultiSelect)
  146. {
  147. (void)GlobalUnlock(StgMed.hGlobal);
  148. }
  149. if (fGotData)
  150. {
  151. ReleaseStgMedium(&StgMed);
  152. }
  153. return hr;
  154. }
  155. static HRESULT InterpretMultiSelect
  156. (
  157. IDataObject *piDataObject,
  158. long *pcDataObjects,
  159. IDataObject ***pppiDataObjects
  160. )
  161. {
  162. HRESULT hr = S_OK;
  163. SMMCDataObjects *pMMCDataObjects = NULL;
  164. BOOL fGotData = FALSE;
  165. size_t cbObjectTypes = 0;
  166. long i = 0;
  167. FORMATETC FmtEtc;
  168. STGMEDIUM StgMed;
  169. ZeroMemory(&FmtEtc, sizeof(FmtEtc));
  170. ZeroMemory(&StgMed, sizeof(StgMed));
  171. *pcDataObjects = 0;
  172. *pppiDataObjects = NULL;
  173. // Get the SMMCDataObjects structure from MMC
  174. hr = GetClipboardFormat(CCF_MULTI_SELECT_SNAPINS, &FmtEtc.cfFormat);
  175. if (FAILED(hr))
  176. {
  177. goto Cleanup;
  178. }
  179. FmtEtc.dwAspect = DVASPECT_CONTENT;
  180. FmtEtc.lindex = -1L;
  181. FmtEtc.tymed = TYMED_HGLOBAL;
  182. StgMed.tymed = TYMED_HGLOBAL;
  183. hr = piDataObject->lpVtbl->GetData(piDataObject, &FmtEtc, &StgMed);
  184. if (FAILED(hr))
  185. {
  186. goto Cleanup;
  187. }
  188. fGotData = TRUE;
  189. pMMCDataObjects = (SMMCDataObjects *)GlobalLock(StgMed.hGlobal);
  190. if (NULL == pMMCDataObjects)
  191. {
  192. hr = HRESULT_FROM_WIN32(GetLastError());
  193. goto Cleanup;
  194. }
  195. // Allocate an array of IDataObject and copy the IDataObjects to it
  196. *pcDataObjects = pMMCDataObjects->count;
  197. *pppiDataObjects = (IDataObject **)GlobalAlloc(GPTR,
  198. pMMCDataObjects->count * sizeof(IDataObject *));
  199. if (NULL == *pppiDataObjects)
  200. {
  201. hr = E_OUTOFMEMORY;
  202. goto Cleanup;
  203. }
  204. for (i = 0; i < *pcDataObjects; i++)
  205. {
  206. (*pppiDataObjects)[i] = pMMCDataObjects->lpDataObject[i];
  207. }
  208. Cleanup:
  209. if (NULL != pMMCDataObjects)
  210. {
  211. (void)GlobalUnlock(StgMed.hGlobal);
  212. }
  213. if (fGotData)
  214. {
  215. ReleaseStgMedium(&StgMed);
  216. }
  217. return hr;
  218. }
  219. void CheckForSpecialDataObjects
  220. (
  221. IDataObject **ppiDataObject,
  222. BOOL *pfSpecialDataObject,
  223. long *plSpecialDataObject
  224. )
  225. {
  226. long lSpecialDataObject = (long)(*ppiDataObject);
  227. if (IS_SPECIAL_DATAOBJECT(lSpecialDataObject))
  228. {
  229. *plSpecialDataObject = lSpecialDataObject;
  230. *ppiDataObject = NULL;
  231. *pfSpecialDataObject = TRUE;
  232. }
  233. else
  234. {
  235. *pfSpecialDataObject = FALSE;
  236. }
  237. }
  238. static HRESULT SetRemote(IUnknown *This)
  239. {
  240. HRESULT hr = S_OK;
  241. IMMCRemote *piMMCRemote = NULL;
  242. DWORD cbFileName = 0;
  243. char szModuleFileName[MAX_PATH] = "";
  244. // Call IMMCRemote methods: ObjectIsRemote and SetMMCExePath so that the
  245. // snap-in will know it is remote and so that it will have MMC.EXE's full
  246. // path in order to build taskpad display strings.
  247. hr = This->lpVtbl->QueryInterface(This, &IID_IMMCRemote,
  248. (void **)&piMMCRemote);
  249. if (FAILED(hr))
  250. {
  251. // If the object doesn't support IMMCRemote that is not an error.
  252. // The designer runtime will get this QI on both its main object and
  253. // its IComponent object but only the main object needs to support the
  254. // interface.
  255. hr = S_OK;
  256. goto Cleanup;
  257. }
  258. hr = piMMCRemote->lpVtbl->ObjectIsRemote(piMMCRemote);
  259. if (FAILED(hr))
  260. {
  261. goto Cleanup;
  262. }
  263. cbFileName = GetModuleFileName(NULL, // get executable that loaded us (MMC)
  264. szModuleFileName,
  265. sizeof(szModuleFileName));
  266. if (0 == cbFileName)
  267. {
  268. hr = HRESULT_FROM_WIN32(GetLastError());
  269. goto Cleanup;
  270. }
  271. hr = piMMCRemote->lpVtbl->SetMMCExePath(piMMCRemote, szModuleFileName);
  272. if (FAILED(hr))
  273. {
  274. goto Cleanup;
  275. }
  276. hr = piMMCRemote->lpVtbl->SetMMCCommandLine(piMMCRemote, GetCommandLine());
  277. if (FAILED(hr))
  278. {
  279. goto Cleanup;
  280. }
  281. Cleanup:
  282. if (NULL != piMMCRemote)
  283. {
  284. piMMCRemote->lpVtbl->Release(piMMCRemote);
  285. }
  286. return hr;
  287. }
  288. HRESULT STDMETHODCALLTYPE IExtendControlbar_SetControlbar_Proxy
  289. (
  290. IExtendControlbar __RPC_FAR *This,
  291. LPCONTROLBAR pControlbar
  292. )
  293. {
  294. HRESULT hr = S_OK;
  295. // Make sure the snap-in knows we are remoted. We do this here because
  296. // this is the first opportunity for the proxy to inform a toolbar
  297. // extension that it is remote.
  298. hr = SetRemote((IUnknown *)This);
  299. if (FAILED(hr))
  300. {
  301. goto Cleanup;
  302. }
  303. hr = IExtendControlbar_RemSetControlbar_Proxy(This, pControlbar);
  304. Cleanup:
  305. return hr;
  306. }
  307. HRESULT STDMETHODCALLTYPE IExtendControlbar_SetControlbar_Stub
  308. (
  309. IExtendControlbar __RPC_FAR *This,
  310. LPCONTROLBAR pControlbar
  311. )
  312. {
  313. return This->lpVtbl->SetControlbar(This, pControlbar);
  314. }
  315. HRESULT STDMETHODCALLTYPE IExtendControlbar_ControlbarNotify_Proxy
  316. (
  317. IExtendControlbar __RPC_FAR *This,
  318. MMC_NOTIFY_TYPE event,
  319. LPARAM arg,
  320. LPARAM param
  321. )
  322. {
  323. HRESULT hr = S_OK;
  324. BOOL fIsMultiSelect = FALSE;
  325. long cDataObjects = 1L;
  326. IDataObject *piDataObject = NULL; // Not AddRef()ed
  327. IDataObject **ppiDataObjects = NULL;
  328. BOOL fSpecialDataObject = FALSE;
  329. long lSpecialDataObject = 0;
  330. // If this is not a menu button click then we can use the generated remoting
  331. // code with the arg and param unions
  332. if (MMCN_MENU_BTNCLICK == event)
  333. {
  334. hr = MenuButtonClickProxy(This,
  335. (IDataObject *)arg,
  336. (MENUBUTTONDATA *)param);
  337. goto Cleanup;
  338. }
  339. // Get any IDataObject associated with the event
  340. switch (event)
  341. {
  342. case MMCN_SELECT:
  343. piDataObject = (IDataObject *)param;
  344. break;
  345. case MMCN_BTN_CLICK:
  346. piDataObject = (IDataObject *)arg;
  347. break;
  348. default:
  349. piDataObject = NULL;
  350. break;
  351. }
  352. // Check for special data objects such DOBJ_CUSTOMWEB etc.
  353. CheckForSpecialDataObjects(&piDataObject, &fSpecialDataObject, &lSpecialDataObject);
  354. // If this is a mutliple selection then we need to extract the data
  355. // objects in the HGLOBAL
  356. if (!fSpecialDataObject)
  357. {
  358. hr = IsMultiSelect(piDataObject, &fIsMultiSelect);
  359. if (FAILED(hr))
  360. {
  361. goto Cleanup;
  362. }
  363. }
  364. if (fIsMultiSelect)
  365. {
  366. hr = InterpretMultiSelect(piDataObject, &cDataObjects,
  367. &ppiDataObjects);
  368. if (FAILED(hr))
  369. {
  370. goto Cleanup;
  371. }
  372. }
  373. else
  374. {
  375. ppiDataObjects = &piDataObject;
  376. }
  377. hr = IExtendControlbar_RemControlbarNotify_Proxy(This,
  378. cDataObjects,
  379. ppiDataObjects,
  380. fSpecialDataObject,
  381. lSpecialDataObject,
  382. event, arg, param);
  383. Cleanup:
  384. if ( fIsMultiSelect && (NULL != ppiDataObjects) )
  385. {
  386. (void)GlobalFree(ppiDataObjects);
  387. }
  388. return hr;
  389. }
  390. HRESULT STDMETHODCALLTYPE IExtendControlbar_ControlbarNotify_Stub
  391. (
  392. IExtendControlbar __RPC_FAR *This,
  393. long cDataObjects,
  394. IDataObject **ppiDataObjects,
  395. BOOL fSpecialDataObject,
  396. long lSpecialDataObject,
  397. MMC_NOTIFY_TYPE event,
  398. LPARAM arg,
  399. LPARAM param
  400. )
  401. {
  402. HRESULT hr = S_OK;
  403. IDataObject *piDataObject = NULL; // Not AddRef()ed
  404. IDataObject *piMultiSelDataObject = NULL;
  405. // If there is more than one data object then we need to pack them into a
  406. // a separate data object that appears as a multi-select data object.
  407. if (cDataObjects > 1L)
  408. {
  409. hr = CreateMultiSelDataObject(ppiDataObjects, cDataObjects,
  410. &piMultiSelDataObject);
  411. if (FAILED(hr))
  412. {
  413. goto Cleanup;
  414. }
  415. piDataObject = piMultiSelDataObject;
  416. }
  417. else if (fSpecialDataObject)
  418. {
  419. piDataObject = (IDataObject *)lSpecialDataObject;
  420. }
  421. else
  422. {
  423. piDataObject = ppiDataObjects[0];
  424. }
  425. // Put the IDataObject into the corresponding parameter for the event
  426. switch (event)
  427. {
  428. case MMCN_SELECT:
  429. param = (LPARAM)piDataObject;
  430. break;
  431. case MMCN_BTN_CLICK:
  432. arg = (LPARAM)piDataObject;
  433. break;
  434. default:
  435. break;
  436. }
  437. // Call into the snap-in with all parameters appearing as they would
  438. // when in-proc.
  439. hr = This->lpVtbl->ControlbarNotify(This, event, arg, param);
  440. Cleanup:
  441. if (NULL != piMultiSelDataObject)
  442. {
  443. piMultiSelDataObject->lpVtbl->Release(piMultiSelDataObject);
  444. }
  445. return hr;
  446. }
  447. static HRESULT MenuButtonClickProxy
  448. (
  449. IExtendControlbar __RPC_FAR *This,
  450. IDataObject *piDataObject,
  451. MENUBUTTONDATA *pMenuButtonData
  452. )
  453. {
  454. HRESULT hr = S_OK;
  455. POPUP_MENUDEF *pPopupMenuDef = NULL;
  456. HMENU hMenu = NULL;
  457. UINT uiSelectedItemID = 0;
  458. IExtendControlbarRemote *piECRemote = NULL;
  459. long i = 0;
  460. BOOL fIsMultiSelect = FALSE;
  461. long cDataObjects = 1L;
  462. IDataObject **ppiDataObjects = NULL;
  463. // The generated remoting cannot easily handle what we need to do so we get
  464. // IExtendControlbarRemote on the snap-in. This interface has methods that
  465. // allow us to ask the snap-in for its popup menu items, display the menu
  466. // here on the MMC side, and then tell the snap-in which item was selected.
  467. hr = This->lpVtbl->QueryInterface(This, &IID_IExtendControlbarRemote,
  468. (void **)&piECRemote);
  469. if (FAILED(hr))
  470. {
  471. goto Cleanup;
  472. }
  473. // Tell the snap-in about the menu button click and get back its list of
  474. // popup menu items.
  475. hr = piECRemote->lpVtbl->MenuButtonClick(piECRemote,
  476. piDataObject,
  477. pMenuButtonData->idCommand,
  478. &pPopupMenuDef);
  479. if ( FAILED(hr) || (NULL == pPopupMenuDef) )
  480. {
  481. goto Cleanup;
  482. }
  483. // Create an empty Win32 menu
  484. hMenu = CreatePopupMenu();
  485. if (NULL == hMenu)
  486. {
  487. hr = HRESULT_FROM_WIN32(GetLastError());
  488. goto Cleanup;
  489. }
  490. // Iterate through each of the items and add them to the menu
  491. for (i = 0; i < pPopupMenuDef->cMenuItems; i++)
  492. {
  493. if (!AppendMenu(hMenu,
  494. pPopupMenuDef->MenuItems[i].uiFlags,
  495. pPopupMenuDef->MenuItems[i].uiItemID,
  496. pPopupMenuDef->MenuItems[i].pszItemText))
  497. {
  498. hr = HRESULT_FROM_WIN32(GetLastError());
  499. goto Cleanup;
  500. }
  501. }
  502. // If the owner HWND is NULL then this is an extension and it does not have
  503. // access to IConsole2 on MMC to get the main frame HWND. In this case just
  504. // use the active window on this thread.
  505. if (NULL == pPopupMenuDef->hwndMenuOwner)
  506. {
  507. pPopupMenuDef->hwndMenuOwner = GetActiveWindow();
  508. }
  509. // Display the popup menu and wait for a selection.
  510. uiSelectedItemID = (UINT)TrackPopupMenu(
  511. hMenu, // menu to display
  512. TPM_LEFTALIGN | // align left side of menu with x
  513. TPM_TOPALIGN | // align top of menu with y
  514. TPM_NONOTIFY | // don't send any messages during selection
  515. TPM_RETURNCMD | // make the ret val the selected item
  516. TPM_LEFTBUTTON, // allow selection with left button only
  517. pMenuButtonData->x, // left side coordinate
  518. pMenuButtonData->y, // top coordinate
  519. 0, // reserved,
  520. pPopupMenuDef->hwndMenuOwner, // owner window, this comes from snap-in
  521. // as it can call IConsole2->GetMainWindow
  522. NULL); // not used
  523. // A zero return could indicate either an error or that the user hit
  524. // Escape or clicked off of the menu to cancel the operation. GetLastError()
  525. // determines whether there was an error. Either way we're done but set the
  526. // hr first.
  527. if (0 == uiSelectedItemID)
  528. {
  529. hr = HRESULT_FROM_WIN32(GetLastError());
  530. goto Cleanup;
  531. }
  532. // If i is non-zero then it contains the ID of the selected item.
  533. // Tell the snap-in what was selected and pass it the extra IUnknown it
  534. // included in its menu definition (this is snap-in defined and it allows
  535. // the snap-in to include some more identifying information to handle the
  536. // event).
  537. if (0 != uiSelectedItemID)
  538. {
  539. hr = piECRemote->lpVtbl->PopupMenuClick(
  540. piECRemote,
  541. piDataObject,
  542. uiSelectedItemID,
  543. pPopupMenuDef->punkSnapInDefined);
  544. }
  545. Cleanup:
  546. if (NULL != piECRemote)
  547. {
  548. piECRemote->lpVtbl->Release(piECRemote);
  549. }
  550. if (NULL != hMenu)
  551. {
  552. (void)DestroyMenu(hMenu);
  553. }
  554. if (NULL != pPopupMenuDef)
  555. {
  556. for (i = 0; i < pPopupMenuDef->cMenuItems; i++)
  557. {
  558. if (NULL != pPopupMenuDef->MenuItems[i].pszItemText)
  559. {
  560. CoTaskMemFree(pPopupMenuDef->MenuItems[i].pszItemText);
  561. }
  562. }
  563. if (NULL != pPopupMenuDef->punkSnapInDefined)
  564. {
  565. pPopupMenuDef->punkSnapInDefined->lpVtbl->Release(pPopupMenuDef->punkSnapInDefined);
  566. }
  567. CoTaskMemFree(pPopupMenuDef);
  568. }
  569. return hr;
  570. }
  571. HRESULT STDMETHODCALLTYPE IExtendControlbarRemote_MenuButtonClick_Proxy
  572. (
  573. IExtendControlbarRemote __RPC_FAR *This,
  574. IDataObject __RPC_FAR *piDataObject,
  575. int idCommand,
  576. POPUP_MENUDEF __RPC_FAR *__RPC_FAR *ppPopupMenuDef
  577. )
  578. {
  579. HRESULT hr = S_OK;
  580. BOOL fIsMultiSelect = FALSE;
  581. long cDataObjects = 1L;
  582. IDataObject **ppiDataObjects = NULL;
  583. BOOL fSpecialDataObject = FALSE;
  584. long lSpecialDataObject = 0;
  585. // Check for special data objects such DOBJ_CUSTOMWEB etc.
  586. CheckForSpecialDataObjects(&piDataObject, &fSpecialDataObject, &lSpecialDataObject);
  587. // If this is a mutliple selection then we need to extract the data
  588. // objects in the HGLOBAL
  589. if (!fSpecialDataObject)
  590. {
  591. hr = IsMultiSelect(piDataObject, &fIsMultiSelect);
  592. if (FAILED(hr))
  593. {
  594. goto Cleanup;
  595. }
  596. }
  597. if (fIsMultiSelect)
  598. {
  599. hr = InterpretMultiSelect(piDataObject, &cDataObjects, &ppiDataObjects);
  600. if (FAILED(hr))
  601. {
  602. goto Cleanup;
  603. }
  604. }
  605. else
  606. {
  607. ppiDataObjects = &piDataObject;
  608. }
  609. hr = IExtendControlbarRemote_RemMenuButtonClick_Proxy(This,
  610. cDataObjects,
  611. ppiDataObjects,
  612. fSpecialDataObject,
  613. lSpecialDataObject,
  614. idCommand,
  615. ppPopupMenuDef);
  616. Cleanup:
  617. if ( fIsMultiSelect && (NULL != ppiDataObjects) )
  618. {
  619. (void)GlobalFree(ppiDataObjects);
  620. }
  621. return hr;
  622. }
  623. HRESULT STDMETHODCALLTYPE IExtendControlbarRemote_MenuButtonClick_Stub
  624. (
  625. IExtendControlbarRemote __RPC_FAR *This,
  626. long cDataObjects,
  627. IDataObject __RPC_FAR *__RPC_FAR ppiDataObjects[ ],
  628. BOOL fSpecialDataObject,
  629. long lSpecialDataObject,
  630. int idCommand,
  631. POPUP_MENUDEF __RPC_FAR *__RPC_FAR *ppPopupMenuDef
  632. )
  633. {
  634. HRESULT hr = S_OK;
  635. IDataObject *piDataObject = NULL; // Not AddRef()ed
  636. IDataObject *piMultiSelDataObject = NULL;
  637. // If there is more than one data object then we need to pack them into a
  638. // a separate data object that appears as a multi-select data object.
  639. if (cDataObjects > 1L)
  640. {
  641. hr = CreateMultiSelDataObject(ppiDataObjects, cDataObjects,
  642. &piMultiSelDataObject);
  643. if (FAILED(hr))
  644. {
  645. goto Cleanup;
  646. }
  647. piDataObject = piMultiSelDataObject;
  648. }
  649. else if (fSpecialDataObject)
  650. {
  651. piDataObject = (IDataObject *)lSpecialDataObject;
  652. }
  653. else
  654. {
  655. piDataObject = ppiDataObjects[0];
  656. }
  657. // Call the snap-in
  658. hr = This->lpVtbl->MenuButtonClick(This, piDataObject,
  659. idCommand, ppPopupMenuDef);
  660. Cleanup:
  661. if (NULL != piMultiSelDataObject)
  662. {
  663. piMultiSelDataObject->lpVtbl->Release(piMultiSelDataObject);
  664. }
  665. return hr;
  666. }
  667. HRESULT STDMETHODCALLTYPE IExtendControlbarRemote_PopupMenuClick_Proxy
  668. (
  669. IExtendControlbarRemote __RPC_FAR *This,
  670. IDataObject __RPC_FAR *piDataObject,
  671. UINT uIDItem,
  672. IUnknown __RPC_FAR *punkParam
  673. )
  674. {
  675. HRESULT hr = S_OK;
  676. BOOL fIsMultiSelect = FALSE;
  677. long cDataObjects = 1L;
  678. IDataObject **ppiDataObjects = NULL;
  679. BOOL fSpecialDataObject = FALSE;
  680. long lSpecialDataObject = 0;
  681. // Check for special data objects such DOBJ_CUSTOMWEB etc.
  682. CheckForSpecialDataObjects(&piDataObject, &fSpecialDataObject, &lSpecialDataObject);
  683. // If this is a mutliple selection then we need to extract the data
  684. // objects in the HGLOBAL
  685. if (!fSpecialDataObject)
  686. {
  687. hr = IsMultiSelect(piDataObject, &fIsMultiSelect);
  688. if (FAILED(hr))
  689. {
  690. goto Cleanup;
  691. }
  692. }
  693. if (fIsMultiSelect)
  694. {
  695. hr = InterpretMultiSelect(piDataObject, &cDataObjects, &ppiDataObjects);
  696. if (FAILED(hr))
  697. {
  698. goto Cleanup;
  699. }
  700. }
  701. else
  702. {
  703. ppiDataObjects = &piDataObject;
  704. }
  705. hr = IExtendControlbarRemote_RemPopupMenuClick_Proxy(This,
  706. cDataObjects,
  707. ppiDataObjects,
  708. fSpecialDataObject,
  709. lSpecialDataObject,
  710. uIDItem,
  711. punkParam);
  712. Cleanup:
  713. if ( fIsMultiSelect && (NULL != ppiDataObjects) )
  714. {
  715. (void)GlobalFree(ppiDataObjects);
  716. }
  717. return hr;
  718. }
  719. HRESULT STDMETHODCALLTYPE IExtendControlbarRemote_PopupMenuClick_Stub
  720. (
  721. IExtendControlbarRemote __RPC_FAR *This,
  722. long cDataObjects,
  723. IDataObject __RPC_FAR *__RPC_FAR ppiDataObjects[ ],
  724. BOOL fSpecialDataObject,
  725. long lSpecialDataObject,
  726. UINT uIDItem,
  727. IUnknown __RPC_FAR *punkParam
  728. )
  729. {
  730. HRESULT hr = S_OK;
  731. IDataObject *piDataObject = NULL; // Not AddRef()ed
  732. IDataObject *piMultiSelDataObject = NULL;
  733. // If there is more than one data object then we need to pack them into a
  734. // a separate data object that appears as a multi-select data object.
  735. if (cDataObjects > 1L)
  736. {
  737. hr = CreateMultiSelDataObject(ppiDataObjects, cDataObjects,
  738. &piMultiSelDataObject);
  739. if (FAILED(hr))
  740. {
  741. goto Cleanup;
  742. }
  743. piDataObject = piMultiSelDataObject;
  744. }
  745. else if (fSpecialDataObject)
  746. {
  747. piDataObject = (IDataObject *)lSpecialDataObject;
  748. }
  749. else
  750. {
  751. piDataObject = ppiDataObjects[0];
  752. }
  753. // Call the snap-in
  754. hr = This->lpVtbl->PopupMenuClick(This, piDataObject, uIDItem, punkParam);
  755. Cleanup:
  756. if (NULL != piMultiSelDataObject)
  757. {
  758. piMultiSelDataObject->lpVtbl->Release(piMultiSelDataObject);
  759. }
  760. return hr;
  761. }
  762. HRESULT STDMETHODCALLTYPE IComponentData_Initialize_Proxy
  763. (
  764. IComponentData *This,
  765. LPUNKNOWN pUnknown
  766. )
  767. {
  768. HRESULT hr = S_OK;
  769. // Tell the object it is remote and give the path to mmc.exe
  770. hr = SetRemote((IUnknown *)This);
  771. if (FAILED(hr))
  772. {
  773. goto Cleanup;
  774. }
  775. // Now pass on the Initiaize call normally. Using this order allows a snap-in
  776. // to know it is remote prior to its IComponentData::Initialize in case it
  777. // needs that information up front.
  778. hr = IComponentData_RemInitialize_Proxy(This, pUnknown);
  779. if (FAILED(hr))
  780. {
  781. goto Cleanup;
  782. }
  783. Cleanup:
  784. return hr;
  785. }
  786. HRESULT STDMETHODCALLTYPE IComponentData_Initialize_Stub
  787. (
  788. IComponentData *This,
  789. LPUNKNOWN pUnknown
  790. )
  791. {
  792. return This->lpVtbl->Initialize(This, pUnknown);
  793. }
  794. HRESULT STDMETHODCALLTYPE IComponentData_CreateComponent_Proxy
  795. (
  796. IComponentData *This,
  797. LPCOMPONENT *ppComponent
  798. )
  799. {
  800. HRESULT hr = S_OK;
  801. // Tell the object it is remote and give the path to mmc.exe
  802. hr = SetRemote((IUnknown *)This);
  803. if (FAILED(hr))
  804. {
  805. goto Cleanup;
  806. }
  807. // Now pass on the CreateComponent call normally. Using this order allows a
  808. // snap-in to know it is remote prior to its
  809. // IComponentData::CreateComponent in case it needs that information up
  810. // front.
  811. // We do this in IComponentData::Initialize and
  812. // IComponentData::CreateComponent. Most cases will use Initialize but in
  813. // MMC 1.1 a taskpad extension does not receive IComponentData::Initialize.
  814. // MMC only calls IComponentData::CreateComponent. As a taskpad extension
  815. // may need to resolve a res:// URL to use the mmc.exe path we need to do
  816. // it here as well.
  817. hr = IComponentData_RemCreateComponent_Proxy(This, ppComponent);
  818. if (FAILED(hr))
  819. {
  820. goto Cleanup;
  821. }
  822. Cleanup:
  823. return hr;
  824. }
  825. HRESULT STDMETHODCALLTYPE IComponentData_CreateComponent_Stub
  826. (
  827. IComponentData *This,
  828. LPCOMPONENT *ppComponent
  829. )
  830. {
  831. return This->lpVtbl->CreateComponent(This, ppComponent);
  832. }
  833. HRESULT STDMETHODCALLTYPE IComponentData_Notify_Proxy
  834. (
  835. IComponentData __RPC_FAR *This,
  836. LPDATAOBJECT piDataObject,
  837. MMC_NOTIFY_TYPE event,
  838. LPARAM arg,
  839. LPARAM param
  840. )
  841. {
  842. BOOL fSpecialDataObject = FALSE;
  843. long lSpecialDataObject = 0;
  844. ICDNotifyParam ParamUnion;
  845. ZeroMemory(&ParamUnion, sizeof(ParamUnion));
  846. // Check for special data objects such DOBJ_CUSTOMWEB etc.
  847. CheckForSpecialDataObjects(&piDataObject, &fSpecialDataObject, &lSpecialDataObject);
  848. ParamUnion.value = param;
  849. return IComponentData_RemNotify_Proxy(This, piDataObject,
  850. fSpecialDataObject,
  851. lSpecialDataObject,
  852. event, arg, &ParamUnion);
  853. }
  854. HRESULT STDMETHODCALLTYPE IComponentData_Notify_Stub
  855. (
  856. IComponentData __RPC_FAR *This,
  857. LPDATAOBJECT piDataObject,
  858. BOOL fSpecialDataObject,
  859. long lSpecialDataObject,
  860. MMC_NOTIFY_TYPE event,
  861. LPARAM arg,
  862. ICDNotifyParam *pParamUnion
  863. )
  864. {
  865. if (fSpecialDataObject)
  866. {
  867. piDataObject = (IDataObject *)lSpecialDataObject;
  868. }
  869. return This->lpVtbl->Notify(This, piDataObject,
  870. event, arg, pParamUnion->value);
  871. }
  872. HRESULT STDMETHODCALLTYPE IComponentData_CompareObjects_Proxy
  873. (
  874. IComponentData __RPC_FAR *This,
  875. IDataObject *piDataObjectA,
  876. IDataObject *piDataObjectB
  877. )
  878. {
  879. HRESULT hr = S_OK;
  880. BOOL fIsMultiSelectA = FALSE;
  881. long cDataObjectsA = 1L;
  882. IDataObject **ppiDataObjectsA = NULL;
  883. BOOL fSpecialDataObjectA = FALSE;
  884. long lSpecialDataObjectA = 0;
  885. BOOL fIsMultiSelectB = FALSE;
  886. long cDataObjectsB = 1L;
  887. IDataObject **ppiDataObjectsB = NULL;
  888. BOOL fSpecialDataObjectB = FALSE;
  889. long lSpecialDataObjectB = 0;
  890. // Check for special data objects such DOBJ_CUSTOMWEB etc.
  891. CheckForSpecialDataObjects(&piDataObjectA, &fSpecialDataObjectA, &lSpecialDataObjectA);
  892. CheckForSpecialDataObjects(&piDataObjectB, &fSpecialDataObjectB, &lSpecialDataObjectB);
  893. // If this is a mutliple selection then we need to extract the data
  894. // objects in the HGLOBAL
  895. if (!fSpecialDataObjectA)
  896. {
  897. hr = IsMultiSelect(piDataObjectA, &fIsMultiSelectA);
  898. if (FAILED(hr))
  899. {
  900. goto Cleanup;
  901. }
  902. }
  903. if (!fSpecialDataObjectB)
  904. {
  905. hr = IsMultiSelect(piDataObjectB, &fIsMultiSelectB);
  906. if (FAILED(hr))
  907. {
  908. goto Cleanup;
  909. }
  910. }
  911. if (fIsMultiSelectA)
  912. {
  913. hr = InterpretMultiSelect(piDataObjectA, &cDataObjectsA, &ppiDataObjectsA);
  914. if (FAILED(hr))
  915. {
  916. goto Cleanup;
  917. }
  918. }
  919. else
  920. {
  921. ppiDataObjectsA = &piDataObjectA;
  922. }
  923. if (fIsMultiSelectB)
  924. {
  925. hr = InterpretMultiSelect(piDataObjectB, &cDataObjectsB, &ppiDataObjectsB);
  926. if (FAILED(hr))
  927. {
  928. goto Cleanup;
  929. }
  930. }
  931. else
  932. {
  933. ppiDataObjectsB = &piDataObjectB;
  934. }
  935. hr = IComponentData_RemCompareObjects_Proxy(This,
  936. cDataObjectsA,
  937. ppiDataObjectsA,
  938. fSpecialDataObjectA,
  939. lSpecialDataObjectA,
  940. cDataObjectsB,
  941. ppiDataObjectsB,
  942. fSpecialDataObjectB,
  943. lSpecialDataObjectB);
  944. Cleanup:
  945. if ( fIsMultiSelectA && (NULL != ppiDataObjectsA) )
  946. {
  947. (void)GlobalFree(ppiDataObjectsA);
  948. }
  949. if ( fIsMultiSelectB && (NULL != ppiDataObjectsB) )
  950. {
  951. (void)GlobalFree(ppiDataObjectsB);
  952. }
  953. return hr;
  954. }
  955. HRESULT STDMETHODCALLTYPE IComponentData_CompareObjects_Stub
  956. (
  957. IComponentData __RPC_FAR *This,
  958. long cDataObjectsA,
  959. IDataObject __RPC_FAR *__RPC_FAR ppiDataObjectsA[ ],
  960. BOOL fSpecialDataObjectA,
  961. long lSpecialDataObjectA,
  962. long cDataObjectsB,
  963. IDataObject __RPC_FAR *__RPC_FAR ppiDataObjectsB[ ],
  964. BOOL fSpecialDataObjectB,
  965. long lSpecialDataObjectB
  966. )
  967. {
  968. HRESULT hr = S_OK;
  969. IDataObject *piDataObjectA = NULL; // Not AddRef()ed
  970. IDataObject *piMultiSelDataObjectA = NULL;
  971. IDataObject *piDataObjectB = NULL; // Not AddRef()ed
  972. IDataObject *piMultiSelDataObjectB = NULL;
  973. // If there is more than one data object then we need to pack them into a
  974. // a separate data object that appears as a multi-select data object.
  975. if (cDataObjectsA > 1L)
  976. {
  977. hr = CreateMultiSelDataObject(ppiDataObjectsA, cDataObjectsA,
  978. &piMultiSelDataObjectA);
  979. if (FAILED(hr))
  980. {
  981. goto Cleanup;
  982. }
  983. piDataObjectA = piMultiSelDataObjectA;
  984. }
  985. else if (fSpecialDataObjectA)
  986. {
  987. piDataObjectA = (IDataObject *)lSpecialDataObjectA;
  988. }
  989. else
  990. {
  991. piDataObjectA = ppiDataObjectsA[0];
  992. }
  993. if (cDataObjectsB > 1L)
  994. {
  995. hr = CreateMultiSelDataObject(ppiDataObjectsB, cDataObjectsB,
  996. &piMultiSelDataObjectB);
  997. if (FAILED(hr))
  998. {
  999. goto Cleanup;
  1000. }
  1001. piDataObjectB = piMultiSelDataObjectB;
  1002. }
  1003. else if (fSpecialDataObjectB)
  1004. {
  1005. piDataObjectB = (IDataObject *)lSpecialDataObjectB;
  1006. }
  1007. else
  1008. {
  1009. piDataObjectB = ppiDataObjectsB[0];
  1010. }
  1011. // Call the snap-in
  1012. hr = This->lpVtbl->CompareObjects(This, piDataObjectA, piDataObjectB);
  1013. Cleanup:
  1014. if (NULL != piMultiSelDataObjectA)
  1015. {
  1016. piMultiSelDataObjectA->lpVtbl->Release(piMultiSelDataObjectA);
  1017. }
  1018. if (NULL != piMultiSelDataObjectB)
  1019. {
  1020. piMultiSelDataObjectB->lpVtbl->Release(piMultiSelDataObjectB);
  1021. }
  1022. return hr;
  1023. }
  1024. HRESULT STDMETHODCALLTYPE IComponent_Notify_Proxy
  1025. (
  1026. IComponent __RPC_FAR *This,
  1027. LPDATAOBJECT piDataObject,
  1028. MMC_NOTIFY_TYPE event,
  1029. LPARAM arg,
  1030. LPARAM param
  1031. )
  1032. {
  1033. ICNotifyArg ArgUnion;
  1034. ICNotifyParam ParamUnion;
  1035. ICOutParam *pOutParam = NULL;
  1036. HRESULT hr = S_OK;
  1037. BOOL fIsMultiSelect = FALSE;
  1038. long cDataObjects = 1L;
  1039. IDataObject **ppiDataObjects = NULL;
  1040. BOOL fSpecialDataObject = FALSE;
  1041. long lSpecialDataObject = 0;
  1042. ZeroMemory(&ArgUnion, sizeof(ArgUnion));
  1043. ZeroMemory(&ParamUnion, sizeof(ParamUnion));
  1044. // Switch any potential multiselect data objects with arg/param so that
  1045. // piDataObject always contains the potential multiselect.
  1046. switch (event)
  1047. {
  1048. case MMCN_QUERY_PASTE:
  1049. ArgUnion.pidoQueryPasteTarget = piDataObject;
  1050. piDataObject = (IDataObject *)arg;
  1051. ParamUnion.value = param;
  1052. break;
  1053. case MMCN_PASTE:
  1054. ArgUnion.pidoPasteTarget = piDataObject;
  1055. piDataObject = (IDataObject *)arg;
  1056. // Pass through param as an LPARAM rather than the IDataObject **
  1057. // it really is. This is just to let the stub know whether it is
  1058. // a copy or a move. If it is a move the CUTORMOVE IDataObject will
  1059. // be in the ICOutParam returned from the stub.
  1060. ParamUnion.value = param;
  1061. break;
  1062. case MMCN_RESTORE_VIEW:
  1063. ArgUnion.value = arg;
  1064. // Don't pass param because it is a BOOL * that will not be
  1065. // marshaled. The BOOL will be received in the ICOutParam returned
  1066. // from the stub.
  1067. break;
  1068. default:
  1069. ArgUnion.value = arg;
  1070. ParamUnion.value = param;
  1071. }
  1072. // Check for special data objects such DOBJ_CUSTOMWEB etc.
  1073. CheckForSpecialDataObjects(&piDataObject, &fSpecialDataObject, &lSpecialDataObject);
  1074. // If this is a mutliple selection then we need to extract the data
  1075. // objects in the HGLOBAL
  1076. if (!fSpecialDataObject)
  1077. {
  1078. hr = IsMultiSelect(piDataObject, &fIsMultiSelect);
  1079. if (FAILED(hr))
  1080. {
  1081. goto Cleanup;
  1082. }
  1083. }
  1084. if (fIsMultiSelect)
  1085. {
  1086. hr = InterpretMultiSelect(piDataObject, &cDataObjects, &ppiDataObjects);
  1087. if (FAILED(hr))
  1088. {
  1089. goto Cleanup;
  1090. }
  1091. }
  1092. else
  1093. {
  1094. ppiDataObjects = &piDataObject;
  1095. }
  1096. hr = IComponent_RemNotify_Proxy(This,
  1097. cDataObjects, ppiDataObjects,
  1098. fSpecialDataObject, lSpecialDataObject,
  1099. event, &ArgUnion, &ParamUnion, &pOutParam);
  1100. Cleanup:
  1101. if (NULL != pOutParam)
  1102. {
  1103. if (MMCN_PASTE == event)
  1104. {
  1105. *((IDataObject **)param) = pOutParam->pidoCutOrMove;
  1106. }
  1107. else if (MMCN_RESTORE_VIEW == event)
  1108. {
  1109. *((BOOL *)param) = pOutParam->fRestoreHandled;
  1110. }
  1111. CoTaskMemFree(pOutParam);
  1112. }
  1113. if ( fIsMultiSelect && (NULL != ppiDataObjects) )
  1114. {
  1115. (void)GlobalFree(ppiDataObjects);
  1116. }
  1117. return hr;
  1118. }
  1119. HRESULT STDMETHODCALLTYPE IComponent_Notify_Stub
  1120. (
  1121. IComponent __RPC_FAR *This,
  1122. long cDataObjects,
  1123. IDataObject **ppiDataObjects,
  1124. BOOL fSpecialDataObject,
  1125. long lSpecialDataObject,
  1126. MMC_NOTIFY_TYPE event,
  1127. ICNotifyArg *pArgUnion,
  1128. ICNotifyParam *pParamUnion,
  1129. ICOutParam **ppOutParam
  1130. )
  1131. {
  1132. HRESULT hr = S_OK;
  1133. IDataObject *piDataObject = NULL; // Not AddRef()ed
  1134. IDataObject *piMultiSelDataObject = NULL;
  1135. LPARAM Arg = 0;
  1136. LPARAM Param = 0;
  1137. *ppOutParam = (ICOutParam *)CoTaskMemAlloc(sizeof(ICOutParam));
  1138. if (NULL == *ppOutParam)
  1139. {
  1140. hr = E_OUTOFMEMORY;
  1141. goto Cleanup;
  1142. }
  1143. ZeroMemory(*ppOutParam, sizeof(ICOutParam));
  1144. // If there is more than one data object then we need to pack them into a
  1145. // a separate data object that appears as a multi-select data object.
  1146. if (cDataObjects > 1L)
  1147. {
  1148. hr = CreateMultiSelDataObject(ppiDataObjects, cDataObjects,
  1149. &piMultiSelDataObject);
  1150. if (FAILED(hr))
  1151. {
  1152. goto Cleanup;
  1153. }
  1154. piDataObject = piMultiSelDataObject;
  1155. }
  1156. else if (fSpecialDataObject)
  1157. {
  1158. piDataObject = (IDataObject *)lSpecialDataObject;
  1159. }
  1160. else
  1161. {
  1162. piDataObject = ppiDataObjects[0];
  1163. }
  1164. // If the event required swaping Arg and IDataObject then swap it back
  1165. // before calling into the object. For MMCN_QUERY_PASTE and
  1166. // MMCN_RESTORE_VIEW we need to make Param contain the out pointer.
  1167. switch (event)
  1168. {
  1169. case MMCN_PASTE:
  1170. Arg = (LPARAM)piDataObject;
  1171. piDataObject = pArgUnion->pidoPasteTarget;
  1172. if (0 == pParamUnion->value)
  1173. {
  1174. // This is a copy, pass zero in Param so snap-in will know that
  1175. Param = 0;
  1176. }
  1177. else
  1178. {
  1179. // This is a move. Pass the address of the IDataObject in
  1180. // the ICOutParam that we will return to the proxy.
  1181. Param = (LPARAM)&((*ppOutParam)->pidoCutOrMove);
  1182. }
  1183. break;
  1184. case MMCN_QUERY_PASTE:
  1185. Arg = (LPARAM)piDataObject;
  1186. piDataObject = pArgUnion->pidoQueryPasteTarget;
  1187. Param = pParamUnion->value;
  1188. break;
  1189. case MMCN_RESTORE_VIEW:
  1190. Arg = pArgUnion->value;
  1191. Param = (LPARAM)&((*ppOutParam)->fRestoreHandled);
  1192. break;
  1193. default:
  1194. Arg = pArgUnion->value;
  1195. Param = pParamUnion->value;
  1196. break;
  1197. }
  1198. hr = This->lpVtbl->Notify(This, piDataObject, event, Arg, Param);
  1199. Cleanup:
  1200. if (FAILED(hr))
  1201. {
  1202. if (NULL != *ppOutParam)
  1203. {
  1204. CoTaskMemFree(*ppOutParam);
  1205. *ppOutParam = NULL;
  1206. }
  1207. }
  1208. if (NULL != piMultiSelDataObject)
  1209. {
  1210. piMultiSelDataObject->lpVtbl->Release(piMultiSelDataObject);
  1211. }
  1212. return hr;
  1213. }
  1214. HRESULT STDMETHODCALLTYPE IComponent_CompareObjects_Proxy
  1215. (
  1216. IComponent __RPC_FAR *This,
  1217. IDataObject *piDataObjectA,
  1218. IDataObject *piDataObjectB
  1219. )
  1220. {
  1221. HRESULT hr = S_OK;
  1222. BOOL fIsMultiSelectA = FALSE;
  1223. long cDataObjectsA = 1L;
  1224. IDataObject **ppiDataObjectsA = NULL;
  1225. BOOL fSpecialDataObjectA = FALSE;
  1226. long lSpecialDataObjectA = 0;
  1227. BOOL fIsMultiSelectB = FALSE;
  1228. long cDataObjectsB = 1L;
  1229. IDataObject **ppiDataObjectsB = NULL;
  1230. BOOL fSpecialDataObjectB = FALSE;
  1231. long lSpecialDataObjectB = 0;
  1232. // Check for special data objects such DOBJ_CUSTOMWEB etc.
  1233. CheckForSpecialDataObjects(&piDataObjectA, &fSpecialDataObjectA, &lSpecialDataObjectA);
  1234. CheckForSpecialDataObjects(&piDataObjectB, &fSpecialDataObjectB, &lSpecialDataObjectB);
  1235. // If this is a mutliple selection then we need to extract the data
  1236. // objects in the HGLOBAL
  1237. if (!fSpecialDataObjectA)
  1238. {
  1239. hr = IsMultiSelect(piDataObjectA, &fIsMultiSelectA);
  1240. if (FAILED(hr))
  1241. {
  1242. goto Cleanup;
  1243. }
  1244. }
  1245. if (!fSpecialDataObjectB)
  1246. {
  1247. hr = IsMultiSelect(piDataObjectB, &fIsMultiSelectB);
  1248. if (FAILED(hr))
  1249. {
  1250. goto Cleanup;
  1251. }
  1252. }
  1253. if (fIsMultiSelectA)
  1254. {
  1255. hr = InterpretMultiSelect(piDataObjectA, &cDataObjectsA, &ppiDataObjectsA);
  1256. if (FAILED(hr))
  1257. {
  1258. goto Cleanup;
  1259. }
  1260. }
  1261. else
  1262. {
  1263. ppiDataObjectsA = &piDataObjectA;
  1264. }
  1265. if (fIsMultiSelectB)
  1266. {
  1267. hr = InterpretMultiSelect(piDataObjectB, &cDataObjectsB, &ppiDataObjectsB);
  1268. if (FAILED(hr))
  1269. {
  1270. goto Cleanup;
  1271. }
  1272. }
  1273. else
  1274. {
  1275. ppiDataObjectsB = &piDataObjectB;
  1276. }
  1277. hr = IComponent_RemCompareObjects_Proxy(This,
  1278. cDataObjectsA,
  1279. ppiDataObjectsA,
  1280. fSpecialDataObjectA,
  1281. lSpecialDataObjectA,
  1282. cDataObjectsB,
  1283. ppiDataObjectsB,
  1284. fSpecialDataObjectB,
  1285. lSpecialDataObjectB);
  1286. Cleanup:
  1287. if ( fIsMultiSelectA && (NULL != ppiDataObjectsA) )
  1288. {
  1289. (void)GlobalFree(ppiDataObjectsA);
  1290. }
  1291. if ( fIsMultiSelectB && (NULL != ppiDataObjectsB) )
  1292. {
  1293. (void)GlobalFree(ppiDataObjectsB);
  1294. }
  1295. return hr;
  1296. }
  1297. HRESULT STDMETHODCALLTYPE IComponent_CompareObjects_Stub
  1298. (
  1299. IComponent __RPC_FAR *This,
  1300. long cDataObjectsA,
  1301. IDataObject __RPC_FAR *__RPC_FAR ppiDataObjectsA[ ],
  1302. BOOL fSpecialDataObjectA,
  1303. long lSpecialDataObjectA,
  1304. long cDataObjectsB,
  1305. IDataObject __RPC_FAR *__RPC_FAR ppiDataObjectsB[ ],
  1306. BOOL fSpecialDataObjectB,
  1307. long lSpecialDataObjectB
  1308. )
  1309. {
  1310. HRESULT hr = S_OK;
  1311. IDataObject *piDataObjectA = NULL; // Not AddRef()ed
  1312. IDataObject *piMultiSelDataObjectA = NULL;
  1313. IDataObject *piDataObjectB = NULL; // Not AddRef()ed
  1314. IDataObject *piMultiSelDataObjectB = NULL;
  1315. // If there is more than one data object then we need to pack them into a
  1316. // a separate data object that appears as a multi-select data object.
  1317. if (cDataObjectsA > 1L)
  1318. {
  1319. hr = CreateMultiSelDataObject(ppiDataObjectsA, cDataObjectsA,
  1320. &piMultiSelDataObjectA);
  1321. if (FAILED(hr))
  1322. {
  1323. goto Cleanup;
  1324. }
  1325. piDataObjectA = piMultiSelDataObjectA;
  1326. }
  1327. else if (fSpecialDataObjectA)
  1328. {
  1329. piDataObjectA = (IDataObject *)lSpecialDataObjectA;
  1330. }
  1331. else
  1332. {
  1333. piDataObjectA = ppiDataObjectsA[0];
  1334. }
  1335. if (cDataObjectsB > 1L)
  1336. {
  1337. hr = CreateMultiSelDataObject(ppiDataObjectsB, cDataObjectsB,
  1338. &piMultiSelDataObjectB);
  1339. if (FAILED(hr))
  1340. {
  1341. goto Cleanup;
  1342. }
  1343. piDataObjectB = piMultiSelDataObjectB;
  1344. }
  1345. else if (fSpecialDataObjectB)
  1346. {
  1347. piDataObjectB = (IDataObject *)lSpecialDataObjectB;
  1348. }
  1349. else
  1350. {
  1351. piDataObjectB = ppiDataObjectsB[0];
  1352. }
  1353. // Call the snap-in
  1354. hr = This->lpVtbl->CompareObjects(This, piDataObjectA, piDataObjectB);
  1355. Cleanup:
  1356. if (NULL != piMultiSelDataObjectA)
  1357. {
  1358. piMultiSelDataObjectA->lpVtbl->Release(piMultiSelDataObjectA);
  1359. }
  1360. if (NULL != piMultiSelDataObjectB)
  1361. {
  1362. piMultiSelDataObjectB->lpVtbl->Release(piMultiSelDataObjectB);
  1363. }
  1364. return hr;
  1365. }
  1366. //=--------------------------------------------------------------------------=
  1367. //
  1368. // SCOPEDATAITEM Marshaling
  1369. //
  1370. //
  1371. //=--------------------------------------------------------------------------=
  1372. // Caveat: When returning a string in SCOPEDATAITEM MMC does not use a
  1373. // callee allocate/caller free strategy. When in-proc, the owner of the memory
  1374. // must insure that it stays alive for as long as the caller is expected to
  1375. // use it (e.g. scope item display name must remain valid for the life of the
  1376. // scope item). When out-of-proc, that returned string will be allocated by
  1377. // the proxy using CoTaskMemAlloc() and it will never be freed so there will
  1378. // be some leaks.
  1379. //=--------------------------------------------------------------------------=
  1380. static void SCOPEDATAITEM_TO_WIRE
  1381. (
  1382. SCOPEDATAITEM *psdi,
  1383. WIRE_SCOPEDATAITEM *pwsdi
  1384. )
  1385. {
  1386. pwsdi->mask = psdi->mask;
  1387. pwsdi->nImage = psdi->nImage;
  1388. pwsdi->nOpenImage = psdi->nOpenImage;
  1389. pwsdi->nState = psdi->nState;
  1390. pwsdi->cChildren = psdi->cChildren;
  1391. pwsdi->lParam = psdi->lParam;
  1392. pwsdi->relativeID = psdi->relativeID;
  1393. pwsdi->ID = psdi->ID;
  1394. if ( SDI_STR != (psdi->mask & SDI_STR) )
  1395. {
  1396. pwsdi->pwszDisplayName = NULL;
  1397. pwsdi->fUsingCallbackForString = FALSE;
  1398. }
  1399. else if (MMC_CALLBACK == psdi->displayname)
  1400. {
  1401. pwsdi->pwszDisplayName = NULL;
  1402. pwsdi->fUsingCallbackForString = TRUE;
  1403. }
  1404. else if (NULL == psdi->displayname)
  1405. {
  1406. pwsdi->pwszDisplayName = NULL;
  1407. pwsdi->fUsingCallbackForString = FALSE;
  1408. }
  1409. else
  1410. {
  1411. // A string is being passed. Need to CoTaskMemAlloc() it so that
  1412. // the MIDL generated stub can free it after transmission
  1413. int cbString = (lstrlenW(psdi->displayname) + 1) * sizeof(psdi->displayname[0]);
  1414. pwsdi->pwszDisplayName = (LPOLESTR)CoTaskMemAlloc(cbString);
  1415. if (NULL == pwsdi->pwszDisplayName)
  1416. {
  1417. RpcRaiseException( E_OUTOFMEMORY );
  1418. }
  1419. else
  1420. {
  1421. memcpy(pwsdi->pwszDisplayName, psdi->displayname, cbString);
  1422. }
  1423. pwsdi->fUsingCallbackForString = FALSE;
  1424. }
  1425. }
  1426. static void WIRE_TO_SCOPEDATAITEM
  1427. (
  1428. WIRE_SCOPEDATAITEM *pwsdi,
  1429. SCOPEDATAITEM *psdi
  1430. )
  1431. {
  1432. psdi->mask = pwsdi->mask;
  1433. psdi->nImage = pwsdi->nImage;
  1434. psdi->nOpenImage = pwsdi->nOpenImage;
  1435. psdi->nState = pwsdi->nState;
  1436. psdi->cChildren = pwsdi->cChildren;
  1437. psdi->lParam = pwsdi->lParam;
  1438. psdi->relativeID = pwsdi->relativeID;
  1439. psdi->ID = pwsdi->ID;
  1440. if ( SDI_STR != (psdi->mask & SDI_STR) )
  1441. {
  1442. psdi->displayname = NULL;
  1443. }
  1444. else if (pwsdi->fUsingCallbackForString)
  1445. {
  1446. psdi->displayname = MMC_CALLBACK;
  1447. }
  1448. else
  1449. {
  1450. psdi->displayname = pwsdi->pwszDisplayName;
  1451. }
  1452. }
  1453. HRESULT STDMETHODCALLTYPE IComponentData_GetDisplayInfo_Proxy
  1454. (
  1455. IComponentData __RPC_FAR *This,
  1456. SCOPEDATAITEM __RPC_FAR *pScopeDataItem
  1457. )
  1458. {
  1459. WIRE_SCOPEDATAITEM wsdi;
  1460. HRESULT hr;
  1461. // Make sure the string pointer is NULL so that it is not marshaled as it
  1462. // is never passed from MMC to the snap-in. (MMC might not have initialized
  1463. // the pointer).
  1464. pScopeDataItem->displayname = NULL;
  1465. SCOPEDATAITEM_TO_WIRE(pScopeDataItem, &wsdi);
  1466. hr = IComponentData_RemGetDisplayInfo_Proxy(This, &wsdi);
  1467. WIRE_TO_SCOPEDATAITEM(&wsdi, pScopeDataItem);
  1468. return hr;
  1469. }
  1470. HRESULT STDMETHODCALLTYPE IComponentData_GetDisplayInfo_Stub
  1471. (
  1472. IComponentData __RPC_FAR *This,
  1473. WIRE_SCOPEDATAITEM __RPC_FAR *pwsdi
  1474. )
  1475. {
  1476. SCOPEDATAITEM sdi;
  1477. HRESULT hr;
  1478. WIRE_TO_SCOPEDATAITEM(pwsdi, &sdi);
  1479. hr = This->lpVtbl->GetDisplayInfo(This, &sdi);
  1480. SCOPEDATAITEM_TO_WIRE(&sdi, pwsdi);
  1481. return hr;
  1482. }
  1483. HRESULT STDMETHODCALLTYPE IConsoleNameSpace_InsertItem_Proxy
  1484. (
  1485. IConsoleNameSpace __RPC_FAR *This,
  1486. LPSCOPEDATAITEM pItem
  1487. )
  1488. {
  1489. WIRE_SCOPEDATAITEM wsdi;
  1490. HRESULT hr;
  1491. HSCOPEITEM ItemID;
  1492. SCOPEDATAITEM_TO_WIRE(pItem, &wsdi);
  1493. hr = IConsoleNameSpace_RemInsertItem_Proxy(This, &wsdi, &ItemID);
  1494. // The only returned field is the item ID so copy it from the wire
  1495. // structure to the client structure
  1496. pItem->ID = ItemID;
  1497. return hr;
  1498. }
  1499. HRESULT STDMETHODCALLTYPE IConsoleNameSpace_InsertItem_Stub
  1500. (
  1501. IConsoleNameSpace __RPC_FAR *This,
  1502. WIRE_SCOPEDATAITEM __RPC_FAR *pwsdi,
  1503. HSCOPEITEM __RPC_FAR *pItemID
  1504. )
  1505. {
  1506. SCOPEDATAITEM sdi;
  1507. HRESULT hr;
  1508. WIRE_TO_SCOPEDATAITEM(pwsdi, &sdi);
  1509. hr = This->lpVtbl->InsertItem(This, &sdi);
  1510. // The only returned field is the itemID.
  1511. *pItemID = sdi.ID;
  1512. return hr;
  1513. }
  1514. HRESULT STDMETHODCALLTYPE IConsoleNameSpace_SetItem_Proxy
  1515. (
  1516. IConsoleNameSpace __RPC_FAR *This,
  1517. LPSCOPEDATAITEM pItem
  1518. )
  1519. {
  1520. WIRE_SCOPEDATAITEM wsdi;
  1521. SCOPEDATAITEM_TO_WIRE(pItem, &wsdi);
  1522. return IConsoleNameSpace_RemSetItem_Proxy(This, &wsdi);
  1523. }
  1524. HRESULT STDMETHODCALLTYPE IConsoleNameSpace_SetItem_Stub
  1525. (
  1526. IConsoleNameSpace __RPC_FAR *This,
  1527. WIRE_SCOPEDATAITEM __RPC_FAR *pwsdi
  1528. )
  1529. {
  1530. SCOPEDATAITEM sdi;
  1531. WIRE_TO_SCOPEDATAITEM(pwsdi, &sdi);
  1532. return This->lpVtbl->SetItem(This, &sdi);
  1533. }
  1534. HRESULT STDMETHODCALLTYPE IConsoleNameSpace_GetItem_Proxy
  1535. (
  1536. IConsoleNameSpace __RPC_FAR *This,
  1537. LPSCOPEDATAITEM pItem
  1538. )
  1539. {
  1540. WIRE_SCOPEDATAITEM wsdi;
  1541. HRESULT hr;
  1542. // Make sure the string pointer is NULL so that it is not marshaled as it
  1543. // is never passed from the snap-in to MMC. (It might not have be
  1544. // initialized).
  1545. pItem->displayname = NULL;
  1546. SCOPEDATAITEM_TO_WIRE(pItem, &wsdi);
  1547. hr = IConsoleNameSpace_RemGetItem_Proxy(This, &wsdi);
  1548. WIRE_TO_SCOPEDATAITEM(&wsdi, pItem);
  1549. return hr;
  1550. }
  1551. HRESULT STDMETHODCALLTYPE IConsoleNameSpace_GetItem_Stub
  1552. (
  1553. IConsoleNameSpace __RPC_FAR *This,
  1554. WIRE_SCOPEDATAITEM __RPC_FAR *pwsdi
  1555. )
  1556. {
  1557. SCOPEDATAITEM sdi;
  1558. HRESULT hr;
  1559. WIRE_TO_SCOPEDATAITEM(pwsdi, &sdi);
  1560. hr = This->lpVtbl->GetItem(This, &sdi);
  1561. SCOPEDATAITEM_TO_WIRE(&sdi, pwsdi);
  1562. return hr;
  1563. }
  1564. //=--------------------------------------------------------------------------=
  1565. //
  1566. // RESULTDATAITEM Marshaling
  1567. //
  1568. //
  1569. //=--------------------------------------------------------------------------=
  1570. // Caveat: When returning a string in RESULTDATAITEM MMC does not use a
  1571. // callee allocate/caller free strategy. When in-proc, the owner of the memory
  1572. // must insure that it stays alive for as long as the caller is expected to
  1573. // use it (e.g. list item column data must remain valid for the life of the
  1574. // list item). When out-of-proc, that returned string will be allocated by
  1575. // the proxy using SysAllocString() and it will never be freed so there will
  1576. // be some leaks.
  1577. //=--------------------------------------------------------------------------=
  1578. static void RESULTDATAITEM_TO_WIRE
  1579. (
  1580. RESULTDATAITEM *prdi,
  1581. WIRE_RESULTDATAITEM *pwrdi
  1582. )
  1583. {
  1584. pwrdi->mask = prdi->mask;
  1585. pwrdi->bScopeItem = prdi->bScopeItem;
  1586. pwrdi->itemID = prdi->itemID;
  1587. pwrdi->nIndex = prdi->nIndex;
  1588. pwrdi->nCol = prdi->nCol;
  1589. pwrdi->nImage = prdi->nImage;
  1590. pwrdi->nState = prdi->nState;
  1591. pwrdi->lParam = prdi->lParam;
  1592. pwrdi->iIndent = prdi->iIndent;
  1593. if ( RDI_STR != (prdi->mask & RDI_STR) )
  1594. {
  1595. pwrdi->str = NULL;
  1596. pwrdi->fUsingCallbackForString = FALSE;
  1597. }
  1598. else if (MMC_CALLBACK == prdi->str)
  1599. {
  1600. pwrdi->str = NULL;
  1601. pwrdi->fUsingCallbackForString = TRUE;
  1602. }
  1603. else if (NULL == prdi->str)
  1604. {
  1605. pwrdi->str = NULL;
  1606. pwrdi->fUsingCallbackForString = FALSE;
  1607. }
  1608. else
  1609. {
  1610. // A string is being passed. Need to CoTaskMemAlloc() it so that
  1611. // the MIDL generated stub can free it after transmission
  1612. int cbString = (lstrlenW(prdi->str) + 1) * sizeof(prdi->str[0]);
  1613. pwrdi->str = (LPOLESTR)CoTaskMemAlloc(cbString);
  1614. if (NULL == pwrdi->str)
  1615. {
  1616. RpcRaiseException( E_OUTOFMEMORY );
  1617. }
  1618. else
  1619. {
  1620. memcpy(pwrdi->str, prdi->str, cbString);
  1621. }
  1622. pwrdi->fUsingCallbackForString = FALSE;
  1623. }
  1624. }
  1625. static void WIRE_TO_RESULTDATAITEM
  1626. (
  1627. WIRE_RESULTDATAITEM *pwrdi,
  1628. RESULTDATAITEM *prdi
  1629. )
  1630. {
  1631. prdi->mask = pwrdi->mask;
  1632. prdi->bScopeItem = pwrdi->bScopeItem;
  1633. prdi->itemID = pwrdi->itemID;
  1634. prdi->nIndex = pwrdi->nIndex;
  1635. prdi->nCol = pwrdi->nCol;
  1636. prdi->nImage = pwrdi->nImage;
  1637. prdi->nState = pwrdi->nState;
  1638. prdi->lParam = pwrdi->lParam;
  1639. prdi->iIndent = pwrdi->iIndent;
  1640. if ( RDI_STR != (prdi->mask & RDI_STR) )
  1641. {
  1642. prdi->str = NULL;
  1643. }
  1644. else if (pwrdi->fUsingCallbackForString)
  1645. {
  1646. prdi->str = MMC_CALLBACK;
  1647. }
  1648. else
  1649. {
  1650. prdi->str = pwrdi->str;
  1651. }
  1652. }
  1653. HRESULT STDMETHODCALLTYPE IComponent_GetDisplayInfo_Proxy
  1654. (
  1655. IComponent __RPC_FAR *This,
  1656. RESULTDATAITEM __RPC_FAR *pResultDataItem
  1657. )
  1658. {
  1659. WIRE_RESULTDATAITEM wrdi;
  1660. HRESULT hr;
  1661. // Make sure the string pointer is NULL so that it is not marshaled as it
  1662. // is never passed from MMC to the snap-in. (MMC might not have initialized
  1663. // the pointer).
  1664. pResultDataItem->str = NULL;
  1665. RESULTDATAITEM_TO_WIRE(pResultDataItem, &wrdi);
  1666. hr = IComponent_RemGetDisplayInfo_Proxy(This, &wrdi);
  1667. WIRE_TO_RESULTDATAITEM(&wrdi, pResultDataItem);
  1668. return hr;
  1669. }
  1670. HRESULT STDMETHODCALLTYPE IComponent_GetDisplayInfo_Stub
  1671. (
  1672. IComponent __RPC_FAR *This,
  1673. WIRE_RESULTDATAITEM __RPC_FAR *pwrdi
  1674. )
  1675. {
  1676. RESULTDATAITEM rdi;
  1677. HRESULT hr;
  1678. WIRE_TO_RESULTDATAITEM(pwrdi, &rdi);
  1679. hr = This->lpVtbl->GetDisplayInfo(This, &rdi);
  1680. RESULTDATAITEM_TO_WIRE(&rdi, pwrdi);
  1681. return hr;
  1682. }
  1683. HRESULT STDMETHODCALLTYPE IResultData_InsertItem_Proxy
  1684. (
  1685. IResultData __RPC_FAR *This,
  1686. LPRESULTDATAITEM pItem
  1687. )
  1688. {
  1689. WIRE_RESULTDATAITEM wrdi;
  1690. HRESULT hr;
  1691. HRESULTITEM ItemID;
  1692. RESULTDATAITEM_TO_WIRE(pItem, &wrdi);
  1693. hr = IResultData_RemInsertItem_Proxy(This, &wrdi, &ItemID);
  1694. // The only returned field is the itemID so copy it from the wire
  1695. // structure to the client structure
  1696. pItem->itemID = ItemID;
  1697. return hr;
  1698. }
  1699. HRESULT STDMETHODCALLTYPE IResultData_InsertItem_Stub
  1700. (
  1701. IResultData __RPC_FAR *This,
  1702. WIRE_RESULTDATAITEM __RPC_FAR *pwrdi,
  1703. HRESULTITEM __RPC_FAR *pItemID
  1704. )
  1705. {
  1706. RESULTDATAITEM rdi;
  1707. HRESULT hr;
  1708. WIRE_TO_RESULTDATAITEM(pwrdi, &rdi);
  1709. hr = This->lpVtbl->InsertItem(This, &rdi);
  1710. // The only returned field is the itemID.
  1711. *pItemID = rdi.itemID;
  1712. return hr;
  1713. }
  1714. HRESULT STDMETHODCALLTYPE IResultData_SetItem_Proxy
  1715. (
  1716. IResultData __RPC_FAR *This,
  1717. LPRESULTDATAITEM pItem
  1718. )
  1719. {
  1720. WIRE_RESULTDATAITEM wrdi;
  1721. RESULTDATAITEM_TO_WIRE(pItem, &wrdi);
  1722. return IResultData_RemSetItem_Proxy(This, &wrdi);
  1723. }
  1724. HRESULT STDMETHODCALLTYPE IResultData_SetItem_Stub
  1725. (
  1726. IResultData __RPC_FAR *This,
  1727. WIRE_RESULTDATAITEM __RPC_FAR *pwrdi
  1728. )
  1729. {
  1730. RESULTDATAITEM rdi;
  1731. WIRE_TO_RESULTDATAITEM(pwrdi, &rdi);
  1732. return This->lpVtbl->SetItem(This, &rdi);
  1733. }
  1734. HRESULT STDMETHODCALLTYPE IResultData_GetItem_Proxy
  1735. (
  1736. IResultData __RPC_FAR *This,
  1737. LPRESULTDATAITEM pItem
  1738. )
  1739. {
  1740. WIRE_RESULTDATAITEM wrdi;
  1741. HRESULT hr;
  1742. // Make sure the string pointer is NULL so that it is not marshaled as it
  1743. // is never passed from the snap-in to MMC. (It might not have be
  1744. // initialized).
  1745. pItem->str = NULL;
  1746. RESULTDATAITEM_TO_WIRE(pItem, &wrdi);
  1747. hr = IResultData_RemGetItem_Proxy(This, &wrdi);
  1748. WIRE_TO_RESULTDATAITEM(&wrdi, pItem);
  1749. return hr;
  1750. }
  1751. HRESULT STDMETHODCALLTYPE IResultData_GetItem_Stub
  1752. (
  1753. IResultData __RPC_FAR *This,
  1754. WIRE_RESULTDATAITEM __RPC_FAR *pwrdi
  1755. )
  1756. {
  1757. RESULTDATAITEM rdi;
  1758. HRESULT hr;
  1759. WIRE_TO_RESULTDATAITEM(pwrdi, &rdi);
  1760. hr = This->lpVtbl->GetItem(This, &rdi);
  1761. RESULTDATAITEM_TO_WIRE(&rdi, pwrdi);
  1762. return hr;
  1763. }
  1764. HRESULT STDMETHODCALLTYPE IResultData_GetNextItem_Proxy
  1765. (
  1766. IResultData __RPC_FAR *This,
  1767. LPRESULTDATAITEM pItem
  1768. )
  1769. {
  1770. WIRE_RESULTDATAITEM wrdi;
  1771. HRESULT hr;
  1772. // Make sure the string pointer is NULL so that it is not marshaled as it
  1773. // is never passed from the snap-in to MMC. (It might not have be
  1774. // initialized).
  1775. pItem->str = NULL;
  1776. RESULTDATAITEM_TO_WIRE(pItem, &wrdi);
  1777. hr = IResultData_RemGetNextItem_Proxy(This, &wrdi);
  1778. WIRE_TO_RESULTDATAITEM(&wrdi, pItem);
  1779. return hr;
  1780. }
  1781. HRESULT STDMETHODCALLTYPE IResultData_GetNextItem_Stub
  1782. (
  1783. IResultData __RPC_FAR *This,
  1784. WIRE_RESULTDATAITEM __RPC_FAR *pwrdi
  1785. )
  1786. {
  1787. RESULTDATAITEM rdi;
  1788. HRESULT hr;
  1789. WIRE_TO_RESULTDATAITEM(pwrdi, &rdi);
  1790. hr = This->lpVtbl->GetNextItem(This, &rdi);
  1791. RESULTDATAITEM_TO_WIRE(&rdi, pwrdi);
  1792. return hr;
  1793. }
  1794. //=--------------------------------------------------------------------------=
  1795. //
  1796. // HICON Marshaling
  1797. //
  1798. //=--------------------------------------------------------------------------=
  1799. // In wtypes.idl HICON is defined with the wire_marshal attribute with its
  1800. // 'on-the-wire' type as a pointer to a RemotableHandle. RemotableHandle is
  1801. // defined in wtypes.idl as
  1802. //
  1803. // typedef union _RemotableHandle switch( long fContext ) u
  1804. // {
  1805. // case WDT_INPROC_CALL: long hInproc;
  1806. // case WDT_REMOTE_CALL: long hRemote;
  1807. // } RemotableHandle;
  1808. //
  1809. // A wire_marshal type must supply routines to size, marhsal, unmarshal, and
  1810. // free marshaling data. Those routines are in ole32.dll but someone forgot to
  1811. // export them. (ole32 also has routines to marshal bitmaps, hwnds, etc. that
  1812. // are all exported). The code has been plagiarized here from ole32. The source
  1813. // is in \\savik\cairo\src\ole32\oleprx32\proxy\transmit.cxx with some macros in
  1814. // transmit.h in that same directory.
  1815. //
  1816. //=--------------------------------------------------------------------------=
  1817. //
  1818. // The following defines and macros are from transmit.h. Note that
  1819. // USER_CALL_CTXT_MASK is from rpcndr.h and WDT_REMOTE_CALL is from wtypes.idl.
  1820. //
  1821. #define ALIGN( pStuff, cAlign ) \
  1822. pStuff = (unsigned char *)((ULONG_PTR)((pStuff) + (cAlign)) & ~ (cAlign))
  1823. #define LENGTH_ALIGN( Length, cAlign ) \
  1824. Length = (((Length) + (cAlign)) & ~ (cAlign))
  1825. #define PULONG_LV_CAST *(unsigned long __RPC_FAR * __RPC_FAR *)&
  1826. #define DIFFERENT_MACHINE_CALL( Flags) \
  1827. (USER_CALL_CTXT_MASK(Flags) == MSHCTX_DIFFERENTMACHINE)
  1828. #define WDT_HANDLE_MARKER WDT_INPROC_CALL
  1829. //=--------------------------------------------------------------------------=
  1830. // HICON_UserSize
  1831. //=--------------------------------------------------------------------------=
  1832. //
  1833. // Parameters:
  1834. // unsigned long __RPC_FAR *pFlags [in] data format & context (see below)
  1835. // unsigned long StartingSize [in] current buffer size
  1836. // HICON __RPC_FAR *hIcon [in] HICON to be marshaled
  1837. //
  1838. //
  1839. // Flags Layout
  1840. // ============
  1841. //
  1842. //----------------------------------------------------------------------
  1843. // Bits Flag Value
  1844. //----------------------------------------------------------------------
  1845. // 31-24 Floating-point representation 0 = IEEE
  1846. // 1 = VAX
  1847. // 2 = Cray
  1848. // 3 = IBM
  1849. //----------------------------------------------------------------------
  1850. // 23-20 Integer and floating-point byte
  1851. // order 0 = Big-endian
  1852. // 1 = Little-endian
  1853. //----------------------------------------------------------------------
  1854. // 19-16 Character representation 0 = ASCII
  1855. // 1 = EBCDIC
  1856. //----------------------------------------------------------------------
  1857. // 15-0 Marshaling context flag 0 = MSHCTX_LOCAL
  1858. // 1 = MSHCTX_NOSHAREDMEM
  1859. // 2 = MSHCTX_DIFFERENTMSCHINE
  1860. // 3 = MSHCTX_INPROC
  1861. //----------------------------------------------------------------------
  1862. //
  1863. // Output:
  1864. // New buffer size after adding amount needed for HICON marshaled data
  1865. //
  1866. // Notes:
  1867. //
  1868. // Called from MIDL generated proxy to determine buffer size needed for
  1869. // marhaled data.
  1870. //
  1871. unsigned long __RPC_USER HICON_UserSize
  1872. (
  1873. unsigned long __RPC_FAR *pFlags,
  1874. unsigned long StartingSize,
  1875. HICON __RPC_FAR *hIcon
  1876. )
  1877. {
  1878. if (NULL == hIcon)
  1879. {
  1880. return StartingSize;
  1881. }
  1882. // If marshaling context is to a different machine then we don't support
  1883. // that.
  1884. if ( DIFFERENT_MACHINE_CALL(*pFlags) )
  1885. {
  1886. RpcRaiseException( RPC_S_INVALID_TAG );
  1887. }
  1888. // Make sure that our data will fall at a long boundary
  1889. LENGTH_ALIGN( StartingSize, 3 );
  1890. //Add the length
  1891. return StartingSize + 8;
  1892. }
  1893. //=--------------------------------------------------------------------------=
  1894. // HICON_UserMarhsal
  1895. //=--------------------------------------------------------------------------=
  1896. //
  1897. // Parameters:
  1898. // unsigned long __RPC_FAR *pFlags [in] data format & context (see above)
  1899. // unsigned char __RPC_FAR *pBuffer [in] current buffer size
  1900. // HICON __RPC_FAR *hIcon [in] HICON to be marshaled
  1901. //
  1902. //
  1903. // Output:
  1904. // Pointer to buffer location following HICON's marshaling data
  1905. //
  1906. // Notes:
  1907. //
  1908. // Called from MIDL generated proxy to marshal an HICON
  1909. //
  1910. unsigned char __RPC_FAR * __RPC_USER HICON_UserMarshal
  1911. (
  1912. unsigned long __RPC_FAR *pFlags,
  1913. unsigned char __RPC_FAR *pBuffer,
  1914. HICON __RPC_FAR *hIcon
  1915. )
  1916. {
  1917. if (NULL == hIcon)
  1918. {
  1919. return pBuffer;
  1920. }
  1921. if ( DIFFERENT_MACHINE_CALL(*pFlags) )
  1922. {
  1923. RpcRaiseException( RPC_S_INVALID_TAG );
  1924. }
  1925. // Make sure that our data will fall at a long boundary
  1926. ALIGN( pBuffer, 3 );
  1927. *( PULONG_LV_CAST pBuffer)++ = WDT_HANDLE_MARKER;
  1928. *( PULONG_LV_CAST pBuffer)++ = *((long *)hIcon);
  1929. return pBuffer;
  1930. }
  1931. //=--------------------------------------------------------------------------=
  1932. // HICON_UserUnmarhsal
  1933. //=--------------------------------------------------------------------------=
  1934. //
  1935. // Parameters:
  1936. // unsigned long __RPC_FAR *pFlags [in] data format & context (see above)
  1937. // unsigned char __RPC_FAR *pBuffer [in] current buffer size
  1938. // HICON __RPC_FAR *hIcon [in] HICON to be marshaled
  1939. //
  1940. //
  1941. // Output:
  1942. // Pointer to buffer location following HICON's marshaling data
  1943. //
  1944. // Notes:
  1945. //
  1946. // Called from MIDL generated stub to unmarshal an HICON
  1947. //
  1948. unsigned char __RPC_FAR *__RPC_USER HICON_UserUnmarshal
  1949. (
  1950. unsigned long __RPC_FAR *pFlags,
  1951. unsigned char __RPC_FAR *pBuffer,
  1952. HICON __RPC_FAR *hIcon
  1953. )
  1954. {
  1955. unsigned long HandleMarker;
  1956. ALIGN( pBuffer, 3 );
  1957. HandleMarker = *( PULONG_LV_CAST pBuffer)++;
  1958. if ( HandleMarker == WDT_HANDLE_MARKER )
  1959. *((long *)hIcon) = *( PULONG_LV_CAST pBuffer)++;
  1960. else
  1961. RpcRaiseException( RPC_S_INVALID_TAG );
  1962. return pBuffer;
  1963. }
  1964. //=--------------------------------------------------------------------------=
  1965. // HICON_UserUnmarhsal
  1966. //=--------------------------------------------------------------------------=
  1967. //
  1968. // Parameters:
  1969. // unsigned long __RPC_FAR *pFlags [in] data format & context (see above)
  1970. // HICON __RPC_FAR *hIcon [in] HICON that was unmarshaled
  1971. //
  1972. //
  1973. // Output:
  1974. // None
  1975. //
  1976. // Notes:
  1977. //
  1978. // Called from MIDL generated stub to free any associated marshaling data
  1979. // allocated during unmarshaling for embedded pointers. Not used for HICON.
  1980. //
  1981. void __RPC_USER HICON_UserFree
  1982. (
  1983. unsigned long __RPC_FAR *pFlags,
  1984. HICON __RPC_FAR *hIcon
  1985. )
  1986. {
  1987. }
  1988. //=--------------------------------------------------------------------------=
  1989. //
  1990. // IImageList Marshaling
  1991. //
  1992. //
  1993. //=--------------------------------------------------------------------------=
  1994. // These methods needed call_as because the HICON and HBITMAP parameters are
  1995. // specified as long pointers in the original IDL.
  1996. //=--------------------------------------------------------------------------=
  1997. HRESULT STDMETHODCALLTYPE IImageList_ImageListSetIcon_Proxy
  1998. (
  1999. IImageList __RPC_FAR *This,
  2000. LONG_PTR __RPC_FAR *pIcon,
  2001. long nLoc
  2002. )
  2003. {
  2004. return IImageList_RemImageListSetIcon_Proxy(This, (HICON)pIcon, nLoc);
  2005. }
  2006. HRESULT STDMETHODCALLTYPE IImageList_ImageListSetIcon_Stub
  2007. (
  2008. IImageList __RPC_FAR *This,
  2009. HICON hIcon,
  2010. long nLoc
  2011. )
  2012. {
  2013. return This->lpVtbl->ImageListSetIcon(This, (LONG_PTR __RPC_FAR*)hIcon, nLoc);
  2014. }
  2015. HRESULT STDMETHODCALLTYPE IImageList_ImageListSetStrip_Proxy
  2016. (
  2017. IImageList __RPC_FAR *This,
  2018. LONG_PTR __RPC_FAR *pBMapSm,
  2019. LONG_PTR __RPC_FAR *pBMapLg,
  2020. long nStartLoc,
  2021. COLORREF cMask
  2022. )
  2023. {
  2024. return IImageList_RemImageListSetStrip_Proxy(This,
  2025. (HBITMAP)pBMapSm,
  2026. (HBITMAP)pBMapLg,
  2027. nStartLoc,
  2028. cMask);
  2029. }
  2030. HRESULT STDMETHODCALLTYPE IImageList_ImageListSetStrip_Stub
  2031. (
  2032. IImageList __RPC_FAR *This,
  2033. HBITMAP hbmSmall,
  2034. HBITMAP hbmLarge,
  2035. long nStartLoc,
  2036. COLORREF cMask
  2037. )
  2038. {
  2039. return This->lpVtbl->ImageListSetStrip(This,
  2040. (LONG_PTR __RPC_FAR*)hbmSmall,
  2041. (LONG_PTR __RPC_FAR*)hbmLarge,
  2042. nStartLoc,
  2043. cMask);
  2044. }
  2045. HRESULT STDMETHODCALLTYPE IExtendPropertySheet_CreatePropertyPages_Proxy
  2046. (
  2047. IExtendPropertySheet __RPC_FAR *This,
  2048. LPPROPERTYSHEETCALLBACK lpProvider,
  2049. LONG_PTR handle,
  2050. LPDATAOBJECT lpIDataObject
  2051. )
  2052. {
  2053. HRESULT hr = S_OK;
  2054. WIRE_PROPERTYPAGES *pPages = NULL;
  2055. WIRE_PROPERTYPAGE *pPage = NULL;
  2056. ULONG i = 0;
  2057. ULONG j = 0;
  2058. IExtendPropertySheetRemote *piExtendPropertySheetRemote = NULL;
  2059. IRemotePropertySheetManager *piRemotePropertySheetManager = NULL;
  2060. // Make sure the snap-in knows we are remoted. We do this here because
  2061. // this is the first opportunity for the proxy to inform a property page
  2062. // extension that it is remote and pass it data such as the MMC.exe path
  2063. // and the MMC command line.
  2064. hr = SetRemote((IUnknown *)This);
  2065. if (FAILED(hr))
  2066. {
  2067. goto Cleanup;
  2068. }
  2069. // Call the IExtendPropertySheetRemote method which will return a filled in
  2070. // WIRE_PROPERTYPAGES from the remoted snap-in.
  2071. hr = This->lpVtbl->QueryInterface(This, &IID_IExtendPropertySheetRemote,
  2072. (void **)&piExtendPropertySheetRemote);
  2073. if (FAILED(hr))
  2074. {
  2075. goto Cleanup;
  2076. }
  2077. hr = piExtendPropertySheetRemote->lpVtbl->CreatePropertyPageDefs(
  2078. piExtendPropertySheetRemote, lpIDataObject, &pPages);
  2079. if (FAILED(hr))
  2080. {
  2081. goto Cleanup;
  2082. }
  2083. // If there are pages (snap-in might not have added any) then
  2084. // CoCreateInstance the remote property sheet manager using the clsid
  2085. // returned in WIRE_PROPERTYPAGES. This object will be created in-proc here
  2086. // on the MMC side.
  2087. if (0 == pPages->cPages)
  2088. {
  2089. goto Cleanup;
  2090. }
  2091. hr = CoCreateInstance(&pPages->clsidRemotePropertySheetManager,
  2092. NULL, // no aggregation,
  2093. CLSCTX_INPROC_SERVER,
  2094. &IID_IRemotePropertySheetManager,
  2095. (void **)&piRemotePropertySheetManager);
  2096. if (FAILED(hr))
  2097. {
  2098. goto Cleanup;
  2099. }
  2100. // Pass the remote property sheet manager the WIRE_PROPERTYPAGES and let it
  2101. // actually create the property pages and add them to the sheet here on the
  2102. // MMC side.
  2103. hr = piRemotePropertySheetManager->lpVtbl->CreateRemotePages(
  2104. piRemotePropertySheetManager,
  2105. lpProvider,
  2106. handle,
  2107. lpIDataObject,
  2108. pPages);
  2109. Cleanup:
  2110. if (NULL != piRemotePropertySheetManager)
  2111. {
  2112. piRemotePropertySheetManager->lpVtbl->Release(piRemotePropertySheetManager);
  2113. }
  2114. if (NULL != piExtendPropertySheetRemote)
  2115. {
  2116. piExtendPropertySheetRemote->lpVtbl->Release(piExtendPropertySheetRemote);
  2117. }
  2118. // Free the WIRE_PROPERTYPAGES and all of its contents.
  2119. if (NULL != pPages)
  2120. {
  2121. // Release the object and free the title for each individual page
  2122. for (i = 0, pPage = &pPages->aPages[0]; i < pPages->cPages; i++, pPage++)
  2123. {
  2124. if (NULL != pPage->apunkObjects)
  2125. {
  2126. for (j = 0; j < pPage->cObjects; j++)
  2127. {
  2128. if (NULL != pPage->apunkObjects[j])
  2129. {
  2130. pPage->apunkObjects[j]->lpVtbl->Release(pPage->apunkObjects[j]);
  2131. }
  2132. }
  2133. CoTaskMemFree(pPage->apunkObjects);
  2134. }
  2135. if (NULL != pPage->pwszTitle)
  2136. {
  2137. CoTaskMemFree(pPage->pwszTitle);
  2138. }
  2139. }
  2140. // Free the ProgID prefix
  2141. if (NULL != pPages->pwszProgIDStart)
  2142. {
  2143. CoTaskMemFree(pPages->pwszProgIDStart);
  2144. }
  2145. // Free all of the snap-in's property page info
  2146. if (NULL != pPages->pPageInfos)
  2147. {
  2148. for (i = 0; i < pPages->pPageInfos->cPages; i++)
  2149. {
  2150. if (NULL != pPages->pPageInfos->aPageInfo[i].pwszTitle)
  2151. {
  2152. CoTaskMemFree(pPages->pPageInfos->aPageInfo[i].pwszTitle);
  2153. }
  2154. if (NULL != pPages->pPageInfos->aPageInfo[i].pwszProgID)
  2155. {
  2156. CoTaskMemFree(pPages->pPageInfos->aPageInfo[i].pwszProgID);
  2157. }
  2158. }
  2159. CoTaskMemFree(pPages->pPageInfos);
  2160. }
  2161. // Free all of the objects associated with the sheet
  2162. if (NULL != pPages->apunkObjects)
  2163. {
  2164. for (i = 0; i < pPages->cObjects; i++)
  2165. {
  2166. if (NULL != pPages->apunkObjects[i])
  2167. {
  2168. pPages->apunkObjects[i]->lpVtbl->Release(pPages->apunkObjects[i]);
  2169. }
  2170. }
  2171. CoTaskMemFree(pPages->apunkObjects);
  2172. }
  2173. // Release the extra object and the WIRE_PROPERTYPAGES struct itself
  2174. if (NULL != pPages->punkExtra)
  2175. {
  2176. pPages->punkExtra->lpVtbl->Release(pPages->punkExtra);
  2177. }
  2178. CoTaskMemFree(pPages);
  2179. }
  2180. return hr;
  2181. }
  2182. //=--------------------------------------------------------------------------=
  2183. // IExtendPropertySheet_CreatePropertyPages_Stub
  2184. //=--------------------------------------------------------------------------=
  2185. //
  2186. // Parameters:
  2187. // IExtendPropertySheet __RPC_FAR *This [in] this pointer
  2188. //
  2189. // Output:
  2190. //
  2191. // Notes:
  2192. //
  2193. // This stub is never called because
  2194. // IExtendPropertySheet_CreatePropertyPages_Proxy() (see above) reroutes the
  2195. // call to IExtendPropertySheetRemote::CreatePropertyPageDefs().
  2196. //
  2197. HRESULT STDMETHODCALLTYPE IExtendPropertySheet_CreatePropertyPages_Stub
  2198. (
  2199. IExtendPropertySheet __RPC_FAR *This
  2200. )
  2201. {
  2202. return S_OK;
  2203. }
  2204. HRESULT STDMETHODCALLTYPE IExtendPropertySheet_QueryPagesFor_Proxy
  2205. (
  2206. IExtendPropertySheet __RPC_FAR *This,
  2207. IDataObject *piDataObject
  2208. )
  2209. {
  2210. HRESULT hr = S_OK;
  2211. BOOL fIsMultiSelect = FALSE;
  2212. long cDataObjects = 1L;
  2213. IDataObject **ppiDataObjects = NULL;
  2214. BOOL fSpecialDataObject = FALSE;
  2215. long lSpecialDataObject = 0;
  2216. // Check for special data objects such DOBJ_CUSTOMWEB etc.
  2217. CheckForSpecialDataObjects(&piDataObject, &fSpecialDataObject, &lSpecialDataObject);
  2218. // If this is a mutliple selection then we need to extract the data
  2219. // objects in the HGLOBAL
  2220. if (!fSpecialDataObject)
  2221. {
  2222. hr = IsMultiSelect(piDataObject, &fIsMultiSelect);
  2223. if (FAILED(hr))
  2224. {
  2225. goto Cleanup;
  2226. }
  2227. }
  2228. if (fIsMultiSelect)
  2229. {
  2230. hr = InterpretMultiSelect(piDataObject, &cDataObjects, &ppiDataObjects);
  2231. if (FAILED(hr))
  2232. {
  2233. goto Cleanup;
  2234. }
  2235. }
  2236. else
  2237. {
  2238. ppiDataObjects = &piDataObject;
  2239. }
  2240. hr = IExtendPropertySheet_RemQueryPagesFor_Proxy(This,
  2241. cDataObjects,
  2242. ppiDataObjects,
  2243. fSpecialDataObject,
  2244. lSpecialDataObject);
  2245. Cleanup:
  2246. if ( fIsMultiSelect && (NULL != ppiDataObjects) )
  2247. {
  2248. (void)GlobalFree(ppiDataObjects);
  2249. }
  2250. return hr;
  2251. }
  2252. HRESULT STDMETHODCALLTYPE IExtendPropertySheet_QueryPagesFor_Stub
  2253. (
  2254. IExtendPropertySheet __RPC_FAR *This,
  2255. long cDataObjects,
  2256. IDataObject __RPC_FAR *__RPC_FAR ppiDataObjects[ ],
  2257. BOOL fSpecialDataObject,
  2258. long lSpecialDataObject
  2259. )
  2260. {
  2261. HRESULT hr = S_OK;
  2262. IDataObject *piDataObject = NULL; // Not AddRef()ed
  2263. IDataObject *piMultiSelDataObject = NULL;
  2264. // If there is more than one data object then we need to pack them into a
  2265. // a separate data object that appears as a multi-select data object.
  2266. if (cDataObjects > 1L)
  2267. {
  2268. hr = CreateMultiSelDataObject(ppiDataObjects, cDataObjects,
  2269. &piMultiSelDataObject);
  2270. if (FAILED(hr))
  2271. {
  2272. goto Cleanup;
  2273. }
  2274. piDataObject = piMultiSelDataObject;
  2275. }
  2276. else if (fSpecialDataObject)
  2277. {
  2278. piDataObject = (IDataObject *)lSpecialDataObject;
  2279. }
  2280. else
  2281. {
  2282. piDataObject = ppiDataObjects[0];
  2283. }
  2284. // Call the snap-in
  2285. hr = This->lpVtbl->QueryPagesFor(This, piDataObject);
  2286. Cleanup:
  2287. if (NULL != piMultiSelDataObject)
  2288. {
  2289. piMultiSelDataObject->lpVtbl->Release(piMultiSelDataObject);
  2290. }
  2291. return hr;
  2292. }
  2293. HRESULT STDMETHODCALLTYPE IExtendPropertySheet2_GetWatermarks_Proxy
  2294. (
  2295. IExtendPropertySheet2 __RPC_FAR *This,
  2296. IDataObject *piDataObject,
  2297. HBITMAP *lphWatermark,
  2298. HBITMAP *lphHeader,
  2299. HPALETTE *lphPalette,
  2300. BOOL *bStretch
  2301. )
  2302. {
  2303. HRESULT hr = S_OK;
  2304. BOOL fIsMultiSelect = FALSE;
  2305. long cDataObjects = 1L;
  2306. IDataObject **ppiDataObjects = NULL;
  2307. BOOL fSpecialDataObject = FALSE;
  2308. long lSpecialDataObject = 0;
  2309. // Check for special data objects such DOBJ_CUSTOMWEB etc.
  2310. CheckForSpecialDataObjects(&piDataObject, &fSpecialDataObject, &lSpecialDataObject);
  2311. // If this is a mutliple selection then we need to extract the data
  2312. // objects in the HGLOBAL
  2313. if (!fSpecialDataObject)
  2314. {
  2315. hr = IsMultiSelect(piDataObject, &fIsMultiSelect);
  2316. if (FAILED(hr))
  2317. {
  2318. goto Cleanup;
  2319. }
  2320. }
  2321. if (fIsMultiSelect)
  2322. {
  2323. hr = InterpretMultiSelect(piDataObject, &cDataObjects, &ppiDataObjects);
  2324. if (FAILED(hr))
  2325. {
  2326. goto Cleanup;
  2327. }
  2328. }
  2329. else
  2330. {
  2331. ppiDataObjects = &piDataObject;
  2332. }
  2333. hr = IExtendPropertySheet2_RemGetWatermarks_Proxy(This,
  2334. cDataObjects,
  2335. ppiDataObjects,
  2336. fSpecialDataObject,
  2337. lSpecialDataObject,
  2338. lphWatermark,
  2339. lphHeader,
  2340. lphPalette,
  2341. bStretch);
  2342. Cleanup:
  2343. if ( fIsMultiSelect && (NULL != ppiDataObjects) )
  2344. {
  2345. (void)GlobalFree(ppiDataObjects);
  2346. }
  2347. return hr;
  2348. }
  2349. HRESULT STDMETHODCALLTYPE IExtendPropertySheet2_GetWatermarks_Stub
  2350. (
  2351. IExtendPropertySheet2 __RPC_FAR *This,
  2352. long cDataObjects,
  2353. IDataObject __RPC_FAR *__RPC_FAR ppiDataObjects[ ],
  2354. BOOL fSpecialDataObject,
  2355. long lSpecialDataObject,
  2356. HBITMAP *lphWatermark,
  2357. HBITMAP *lphHeader,
  2358. HPALETTE *lphPalette,
  2359. BOOL *bStretch
  2360. )
  2361. {
  2362. HRESULT hr = S_OK;
  2363. IDataObject *piDataObject = NULL; // Not AddRef()ed
  2364. IDataObject *piMultiSelDataObject = NULL;
  2365. // If there is more than one data object then we need to pack them into a
  2366. // a separate data object that appears as a multi-select data object.
  2367. if (cDataObjects > 1L)
  2368. {
  2369. hr = CreateMultiSelDataObject(ppiDataObjects, cDataObjects,
  2370. &piMultiSelDataObject);
  2371. if (FAILED(hr))
  2372. {
  2373. goto Cleanup;
  2374. }
  2375. piDataObject = piMultiSelDataObject;
  2376. }
  2377. else if (fSpecialDataObject)
  2378. {
  2379. piDataObject = (IDataObject *)lSpecialDataObject;
  2380. }
  2381. else
  2382. {
  2383. piDataObject = ppiDataObjects[0];
  2384. }
  2385. // Call the snap-in
  2386. hr = This->lpVtbl->GetWatermarks(This,
  2387. piDataObject,
  2388. lphWatermark,
  2389. lphHeader,
  2390. lphPalette,
  2391. bStretch);
  2392. Cleanup:
  2393. if (NULL != piMultiSelDataObject)
  2394. {
  2395. piMultiSelDataObject->lpVtbl->Release(piMultiSelDataObject);
  2396. }
  2397. return hr;
  2398. }
  2399. HRESULT STDMETHODCALLTYPE IExtendPropertySheetRemote_CreatePropertyPageDefs_Proxy
  2400. (
  2401. IExtendPropertySheetRemote __RPC_FAR *This,
  2402. IDataObject *piDataObject,
  2403. WIRE_PROPERTYPAGES **ppPages
  2404. )
  2405. {
  2406. HRESULT hr = S_OK;
  2407. BOOL fIsMultiSelect = FALSE;
  2408. long cDataObjects = 1L;
  2409. IDataObject **ppiDataObjects = NULL;
  2410. BOOL fSpecialDataObject = FALSE;
  2411. long lSpecialDataObject = 0;
  2412. // Check for special data objects such DOBJ_CUSTOMWEB etc.
  2413. CheckForSpecialDataObjects(&piDataObject, &fSpecialDataObject, &lSpecialDataObject);
  2414. // If this is a mutliple selection then we need to extract the data
  2415. // objects in the HGLOBAL
  2416. if (!fSpecialDataObject)
  2417. {
  2418. hr = IsMultiSelect(piDataObject, &fIsMultiSelect);
  2419. if (FAILED(hr))
  2420. {
  2421. goto Cleanup;
  2422. }
  2423. }
  2424. if (fIsMultiSelect)
  2425. {
  2426. hr = InterpretMultiSelect(piDataObject, &cDataObjects, &ppiDataObjects);
  2427. if (FAILED(hr))
  2428. {
  2429. goto Cleanup;
  2430. }
  2431. }
  2432. else
  2433. {
  2434. ppiDataObjects = &piDataObject;
  2435. }
  2436. hr = IExtendPropertySheetRemote_RemCreatePropertyPageDefs_Proxy(
  2437. This,
  2438. cDataObjects,
  2439. ppiDataObjects,
  2440. fSpecialDataObject,
  2441. lSpecialDataObject,
  2442. ppPages);
  2443. Cleanup:
  2444. if ( fIsMultiSelect && (NULL != ppiDataObjects) )
  2445. {
  2446. (void)GlobalFree(ppiDataObjects);
  2447. }
  2448. return hr;
  2449. }
  2450. HRESULT STDMETHODCALLTYPE IExtendPropertySheetRemote_CreatePropertyPageDefs_Stub
  2451. (
  2452. IExtendPropertySheetRemote __RPC_FAR *This,
  2453. long cDataObjects,
  2454. IDataObject __RPC_FAR *__RPC_FAR ppiDataObjects[ ],
  2455. BOOL fSpecialDataObject,
  2456. long lSpecialDataObject,
  2457. WIRE_PROPERTYPAGES **ppPages
  2458. )
  2459. {
  2460. HRESULT hr = S_OK;
  2461. IDataObject *piDataObject = NULL; // Not AddRef()ed
  2462. IDataObject *piMultiSelDataObject = NULL;
  2463. // If there is more than one data object then we need to pack them into a
  2464. // a separate data object that appears as a multi-select data object.
  2465. if (cDataObjects > 1L)
  2466. {
  2467. hr = CreateMultiSelDataObject(ppiDataObjects, cDataObjects,
  2468. &piMultiSelDataObject);
  2469. if (FAILED(hr))
  2470. {
  2471. goto Cleanup;
  2472. }
  2473. piDataObject = piMultiSelDataObject;
  2474. }
  2475. else if (fSpecialDataObject)
  2476. {
  2477. piDataObject = (IDataObject *)lSpecialDataObject;
  2478. }
  2479. else
  2480. {
  2481. piDataObject = ppiDataObjects[0];
  2482. }
  2483. // Call the snap-in
  2484. hr = This->lpVtbl->CreatePropertyPageDefs(This, piDataObject, ppPages);
  2485. Cleanup:
  2486. if (NULL != piMultiSelDataObject)
  2487. {
  2488. piMultiSelDataObject->lpVtbl->Release(piMultiSelDataObject);
  2489. }
  2490. return hr;
  2491. }
  2492. HRESULT STDMETHODCALLTYPE IPropertySheetProvider_CreatePropertySheet_Proxy
  2493. (
  2494. IPropertySheetProvider __RPC_FAR *This,
  2495. LPCWSTR title,
  2496. boolean type,
  2497. MMC_COOKIE cookie,
  2498. IDataObject *piDataObject,
  2499. DWORD dwOptions
  2500. )
  2501. {
  2502. HRESULT hr = S_OK;
  2503. BOOL fIsMultiSelect = FALSE;
  2504. long cDataObjects = 1L;
  2505. IDataObject **ppiDataObjects = NULL;
  2506. BOOL fSpecialDataObject = FALSE;
  2507. long lSpecialDataObject = 0;
  2508. // Check for special data objects such DOBJ_CUSTOMWEB etc.
  2509. CheckForSpecialDataObjects(&piDataObject, &fSpecialDataObject, &lSpecialDataObject);
  2510. // If this is a mutliple selection then we need to extract the data
  2511. // objects in the HGLOBAL
  2512. if (!fSpecialDataObject)
  2513. {
  2514. hr = IsMultiSelect(piDataObject, &fIsMultiSelect);
  2515. if (FAILED(hr))
  2516. {
  2517. goto Cleanup;
  2518. }
  2519. }
  2520. if (fIsMultiSelect)
  2521. {
  2522. hr = InterpretMultiSelect(piDataObject, &cDataObjects, &ppiDataObjects);
  2523. if (FAILED(hr))
  2524. {
  2525. goto Cleanup;
  2526. }
  2527. }
  2528. else
  2529. {
  2530. ppiDataObjects = &piDataObject;
  2531. }
  2532. hr = IPropertySheetProvider_RemCreatePropertySheet_Proxy(This,
  2533. title,
  2534. type,
  2535. cookie,
  2536. cDataObjects,
  2537. ppiDataObjects,
  2538. fSpecialDataObject,
  2539. lSpecialDataObject,
  2540. dwOptions);
  2541. Cleanup:
  2542. if ( fIsMultiSelect && (NULL != ppiDataObjects) )
  2543. {
  2544. (void)GlobalFree(ppiDataObjects);
  2545. }
  2546. return hr;
  2547. }
  2548. HRESULT STDMETHODCALLTYPE IPropertySheetProvider_CreatePropertySheet_Stub
  2549. (
  2550. IPropertySheetProvider __RPC_FAR *This,
  2551. LPCWSTR title,
  2552. boolean type,
  2553. MMC_COOKIE cookie,
  2554. long cDataObjects,
  2555. IDataObject __RPC_FAR *__RPC_FAR ppiDataObjects[ ],
  2556. BOOL fSpecialDataObject,
  2557. long lSpecialDataObject,
  2558. DWORD dwOptions
  2559. )
  2560. {
  2561. HRESULT hr = S_OK;
  2562. IDataObject *piDataObject = NULL; // Not AddRef()ed
  2563. IDataObject *piMultiSelDataObject = NULL;
  2564. // If there is more than one data object then we need to pack them into a
  2565. // a separate data object that appears as a multi-select data object.
  2566. if (cDataObjects > 1L)
  2567. {
  2568. hr = CreateMultiSelDataObject(ppiDataObjects, cDataObjects,
  2569. &piMultiSelDataObject);
  2570. if (FAILED(hr))
  2571. {
  2572. goto Cleanup;
  2573. }
  2574. piDataObject = piMultiSelDataObject;
  2575. }
  2576. else if (fSpecialDataObject)
  2577. {
  2578. piDataObject = (IDataObject *)lSpecialDataObject;
  2579. }
  2580. else
  2581. {
  2582. piDataObject = ppiDataObjects[0];
  2583. }
  2584. // Call the snap-in
  2585. hr = This->lpVtbl->CreatePropertySheet(This, title, type, cookie, piDataObject, dwOptions);
  2586. Cleanup:
  2587. if (NULL != piMultiSelDataObject)
  2588. {
  2589. piMultiSelDataObject->lpVtbl->Release(piMultiSelDataObject);
  2590. }
  2591. return hr;
  2592. }
  2593. HRESULT STDMETHODCALLTYPE IPropertySheetProvider_FindPropertySheet_Proxy
  2594. (
  2595. IPropertySheetProvider __RPC_FAR *This,
  2596. MMC_COOKIE cookie,
  2597. IComponent *piComponent,
  2598. IDataObject *piDataObject
  2599. )
  2600. {
  2601. HRESULT hr = S_OK;
  2602. BOOL fIsMultiSelect = FALSE;
  2603. long cDataObjects = 1L;
  2604. IDataObject **ppiDataObjects = NULL;
  2605. BOOL fSpecialDataObject = FALSE;
  2606. long lSpecialDataObject = 0;
  2607. // Check for special data objects such DOBJ_CUSTOMWEB etc.
  2608. CheckForSpecialDataObjects(&piDataObject, &fSpecialDataObject, &lSpecialDataObject);
  2609. // If this is a mutliple selection then we need to extract the data
  2610. // objects in the HGLOBAL
  2611. if (!fSpecialDataObject)
  2612. {
  2613. hr = IsMultiSelect(piDataObject, &fIsMultiSelect);
  2614. if (FAILED(hr))
  2615. {
  2616. goto Cleanup;
  2617. }
  2618. }
  2619. if (fIsMultiSelect)
  2620. {
  2621. hr = InterpretMultiSelect(piDataObject, &cDataObjects, &ppiDataObjects);
  2622. if (FAILED(hr))
  2623. {
  2624. goto Cleanup;
  2625. }
  2626. }
  2627. else
  2628. {
  2629. ppiDataObjects = &piDataObject;
  2630. }
  2631. hr = IPropertySheetProvider_RemFindPropertySheet_Proxy(This,
  2632. cookie,
  2633. piComponent,
  2634. cDataObjects,
  2635. ppiDataObjects,
  2636. fSpecialDataObject,
  2637. lSpecialDataObject);
  2638. Cleanup:
  2639. if ( fIsMultiSelect && (NULL != ppiDataObjects) )
  2640. {
  2641. (void)GlobalFree(ppiDataObjects);
  2642. }
  2643. return hr;
  2644. }
  2645. HRESULT STDMETHODCALLTYPE IPropertySheetProvider_FindPropertySheet_Stub
  2646. (
  2647. IPropertySheetProvider __RPC_FAR *This,
  2648. MMC_COOKIE cookie,
  2649. IComponent *piComponent,
  2650. long cDataObjects,
  2651. IDataObject __RPC_FAR *__RPC_FAR ppiDataObjects[ ],
  2652. BOOL fSpecialDataObject,
  2653. long lSpecialDataObject
  2654. )
  2655. {
  2656. HRESULT hr = S_OK;
  2657. IDataObject *piDataObject = NULL; // Not AddRef()ed
  2658. IDataObject *piMultiSelDataObject = NULL;
  2659. // If there is more than one data object then we need to pack them into a
  2660. // a separate data object that appears as a multi-select data object.
  2661. if (cDataObjects > 1L)
  2662. {
  2663. hr = CreateMultiSelDataObject(ppiDataObjects, cDataObjects,
  2664. &piMultiSelDataObject);
  2665. if (FAILED(hr))
  2666. {
  2667. goto Cleanup;
  2668. }
  2669. piDataObject = piMultiSelDataObject;
  2670. }
  2671. else if (fSpecialDataObject)
  2672. {
  2673. piDataObject = (IDataObject *)lSpecialDataObject;
  2674. }
  2675. else
  2676. {
  2677. piDataObject = ppiDataObjects[0];
  2678. }
  2679. // Call the snap-in
  2680. hr = This->lpVtbl->FindPropertySheet(This, cookie, piComponent, piDataObject);
  2681. Cleanup:
  2682. if (NULL != piMultiSelDataObject)
  2683. {
  2684. piMultiSelDataObject->lpVtbl->Release(piMultiSelDataObject);
  2685. }
  2686. return hr;
  2687. }
  2688. HRESULT STDMETHODCALLTYPE IExtendContextMenu_AddMenuItems_Proxy
  2689. (
  2690. IExtendContextMenu __RPC_FAR *This,
  2691. LPDATAOBJECT piDataObject,
  2692. LPCONTEXTMENUCALLBACK piCallback,
  2693. long __RPC_FAR *pInsertionAllowed
  2694. )
  2695. {
  2696. HRESULT hr = S_OK;
  2697. BOOL fIsMultiSelect = FALSE;
  2698. long cDataObjects = 1L;
  2699. IDataObject **ppiDataObjects = NULL;
  2700. BOOL fSpecialDataObject = FALSE;
  2701. long lSpecialDataObject = 0;
  2702. // Make sure the snap-in knows we are remoted. We do this here because
  2703. // this is the first opportunity for the proxy to inform a context menu
  2704. // extension that it is remote.
  2705. hr = SetRemote((IUnknown *)This);
  2706. if (FAILED(hr))
  2707. {
  2708. goto Cleanup;
  2709. }
  2710. // Check for special data objects such DOBJ_CUSTOMWEB etc.
  2711. CheckForSpecialDataObjects(&piDataObject, &fSpecialDataObject, &lSpecialDataObject);
  2712. // If this is a mutliple selection then we need to extract the data
  2713. // objects in the HGLOBAL
  2714. if (!fSpecialDataObject)
  2715. {
  2716. hr = IsMultiSelect(piDataObject, &fIsMultiSelect);
  2717. if (FAILED(hr))
  2718. {
  2719. goto Cleanup;
  2720. }
  2721. }
  2722. if (fIsMultiSelect)
  2723. {
  2724. hr = InterpretMultiSelect(piDataObject, &cDataObjects, &ppiDataObjects);
  2725. if (FAILED(hr))
  2726. {
  2727. goto Cleanup;
  2728. }
  2729. }
  2730. else
  2731. {
  2732. ppiDataObjects = &piDataObject;
  2733. }
  2734. hr = IExtendContextMenu_RemAddMenuItems_Proxy(This,
  2735. cDataObjects,
  2736. ppiDataObjects,
  2737. fSpecialDataObject,
  2738. lSpecialDataObject,
  2739. piCallback,
  2740. pInsertionAllowed);
  2741. Cleanup:
  2742. if ( fIsMultiSelect && (NULL != ppiDataObjects) )
  2743. {
  2744. (void)GlobalFree(ppiDataObjects);
  2745. }
  2746. return hr;
  2747. }
  2748. HRESULT STDMETHODCALLTYPE IExtendContextMenu_AddMenuItems_Stub
  2749. (
  2750. IExtendContextMenu __RPC_FAR *This,
  2751. long cDataObjects,
  2752. IDataObject __RPC_FAR *__RPC_FAR ppiDataObjects[ ],
  2753. BOOL fSpecialDataObject,
  2754. long lSpecialDataObject,
  2755. LPCONTEXTMENUCALLBACK piCallback,
  2756. long __RPC_FAR *pInsertionAllowed
  2757. )
  2758. {
  2759. HRESULT hr = S_OK;
  2760. IDataObject *piDataObject = NULL; // Not AddRef()ed
  2761. IDataObject *piMultiSelDataObject = NULL;
  2762. // If there is more than one data object then we need to pack them into a
  2763. // a separate data object that appears as a multi-select data object.
  2764. if (cDataObjects > 1L)
  2765. {
  2766. hr = CreateMultiSelDataObject(ppiDataObjects, cDataObjects,
  2767. &piMultiSelDataObject);
  2768. if (FAILED(hr))
  2769. {
  2770. goto Cleanup;
  2771. }
  2772. piDataObject = piMultiSelDataObject;
  2773. }
  2774. else if (fSpecialDataObject)
  2775. {
  2776. piDataObject = (IDataObject *)lSpecialDataObject;
  2777. }
  2778. else
  2779. {
  2780. piDataObject = ppiDataObjects[0];
  2781. }
  2782. // Call the snap-in
  2783. hr = This->lpVtbl->AddMenuItems(This, piDataObject,
  2784. piCallback, pInsertionAllowed);
  2785. Cleanup:
  2786. if (NULL != piMultiSelDataObject)
  2787. {
  2788. piMultiSelDataObject->lpVtbl->Release(piMultiSelDataObject);
  2789. }
  2790. return hr;
  2791. }
  2792. HRESULT STDMETHODCALLTYPE IExtendContextMenu_Command_Proxy
  2793. (
  2794. IExtendContextMenu __RPC_FAR *This,
  2795. long lCommandID,
  2796. LPDATAOBJECT piDataObject
  2797. )
  2798. {
  2799. HRESULT hr = S_OK;
  2800. BOOL fIsMultiSelect = FALSE;
  2801. long cDataObjects = 1L;
  2802. IDataObject **ppiDataObjects = NULL;
  2803. BOOL fSpecialDataObject = FALSE;
  2804. long lSpecialDataObject = 0;
  2805. // Check for special data objects such DOBJ_CUSTOMWEB etc.
  2806. CheckForSpecialDataObjects(&piDataObject, &fSpecialDataObject, &lSpecialDataObject);
  2807. // If this is a mutliple selection then we need to extract the data
  2808. // objects in the HGLOBAL
  2809. if (!fSpecialDataObject)
  2810. {
  2811. hr = IsMultiSelect(piDataObject, &fIsMultiSelect);
  2812. if (FAILED(hr))
  2813. {
  2814. goto Cleanup;
  2815. }
  2816. }
  2817. if (fIsMultiSelect)
  2818. {
  2819. hr = InterpretMultiSelect(piDataObject, &cDataObjects, &ppiDataObjects);
  2820. if (FAILED(hr))
  2821. {
  2822. goto Cleanup;
  2823. }
  2824. }
  2825. else
  2826. {
  2827. ppiDataObjects = &piDataObject;
  2828. }
  2829. hr = IExtendContextMenu_RemCommand_Proxy(This,
  2830. cDataObjects,
  2831. ppiDataObjects,
  2832. fSpecialDataObject,
  2833. lSpecialDataObject,
  2834. lCommandID);
  2835. Cleanup:
  2836. if ( fIsMultiSelect && (NULL != ppiDataObjects) )
  2837. {
  2838. (void)GlobalFree(ppiDataObjects);
  2839. }
  2840. return hr;
  2841. }
  2842. HRESULT STDMETHODCALLTYPE IExtendContextMenu_Command_Stub
  2843. (
  2844. IExtendContextMenu __RPC_FAR *This,
  2845. long cDataObjects,
  2846. IDataObject __RPC_FAR *__RPC_FAR ppiDataObjects[ ],
  2847. BOOL fSpecialDataObject,
  2848. long lSpecialDataObject,
  2849. long lCommandID
  2850. )
  2851. {
  2852. HRESULT hr = S_OK;
  2853. IDataObject *piDataObject = NULL; // Not AddRef()ed
  2854. IDataObject *piMultiSelDataObject = NULL;
  2855. // If there is more than one data object then we need to pack them into a
  2856. // a separate data object that appears as a multi-select data object.
  2857. if (cDataObjects > 1L)
  2858. {
  2859. hr = CreateMultiSelDataObject(ppiDataObjects, cDataObjects,
  2860. &piMultiSelDataObject);
  2861. if (FAILED(hr))
  2862. {
  2863. goto Cleanup;
  2864. }
  2865. piDataObject = piMultiSelDataObject;
  2866. }
  2867. else if (fSpecialDataObject)
  2868. {
  2869. piDataObject = (IDataObject *)lSpecialDataObject;
  2870. }
  2871. else
  2872. {
  2873. piDataObject = ppiDataObjects[0];
  2874. }
  2875. // Call the snap-in
  2876. hr = This->lpVtbl->Command(This, lCommandID, piDataObject);
  2877. Cleanup:
  2878. if (NULL != piMultiSelDataObject)
  2879. {
  2880. piMultiSelDataObject->lpVtbl->Release(piMultiSelDataObject);
  2881. }
  2882. return hr;
  2883. }
  2884. HRESULT STDMETHODCALLTYPE IColumnData_GetColumnConfigData_Proxy
  2885. (
  2886. IColumnData __RPC_FAR *This,
  2887. SColumnSetID __RPC_FAR *pColID,
  2888. MMC_COLUMN_SET_DATA __RPC_FAR *__RPC_FAR *ppColSetData
  2889. )
  2890. {
  2891. HRESULT hr = S_OK;
  2892. size_t cbColData = 0;
  2893. MMC_COLUMN_SET_DATA *pColSetData = NULL;
  2894. // Call the proxy and get the returned data from MMC
  2895. hr = IColumnData_RemGetColumnConfigData_Proxy(This, pColID, ppColSetData);
  2896. if (FAILED(hr))
  2897. {
  2898. goto Cleanup;
  2899. }
  2900. // If no data was returned then there is nothing to do
  2901. if (NULL == *ppColSetData)
  2902. {
  2903. goto Cleanup;
  2904. }
  2905. if (NULL == (*ppColSetData)->pColData)
  2906. {
  2907. goto Cleanup;
  2908. }
  2909. // At this point the MIDL-generated proxy has returned an MMC_COLUMN_SET_DATA
  2910. // in which the embedded pointer pColData points to a separate block of
  2911. // memory which must be freed independently. The snap-in thinks that
  2912. // pColData points into the same block of memory so it will only call
  2913. // CoTaskMemFree for the MMC_COLUMN_SET_DATA. We need to allocate a new single
  2914. // block in the format the snap-in is expecting and free the memory returned
  2915. // from the proxy.
  2916. cbColData = sizeof(MMC_COLUMN_DATA) * (*ppColSetData)->nNumCols;
  2917. pColSetData = (MMC_COLUMN_SET_DATA *)CoTaskMemAlloc(
  2918. sizeof(MMC_COLUMN_SET_DATA) + cbColData);
  2919. if (NULL == pColSetData)
  2920. {
  2921. CoTaskMemFree((*ppColSetData)->pColData);
  2922. CoTaskMemFree(*ppColSetData);
  2923. *ppColSetData = NULL;
  2924. hr = E_OUTOFMEMORY;
  2925. }
  2926. else
  2927. {
  2928. // Copy the column set data
  2929. memcpy(pColSetData, (*ppColSetData), sizeof(MMC_COLUMN_SET_DATA));
  2930. // Set the embedded pointer to point immediately following the
  2931. // MMC_COLUMN_SET_DATA
  2932. pColSetData->pColData = (MMC_COLUMN_DATA *)(pColSetData + 1);
  2933. // Copy the column data
  2934. memcpy(pColSetData->pColData, (*ppColSetData)->pColData, cbColData);
  2935. // Free the data returned from the proxy
  2936. CoTaskMemFree((*ppColSetData)->pColData);
  2937. CoTaskMemFree(*ppColSetData);
  2938. // Return the new single block pointer to the snap-in
  2939. *ppColSetData = pColSetData;
  2940. }
  2941. Cleanup:
  2942. return hr;
  2943. }
  2944. HRESULT STDMETHODCALLTYPE IColumnData_GetColumnConfigData_Stub
  2945. (
  2946. IColumnData __RPC_FAR *This,
  2947. SColumnSetID __RPC_FAR *pColID,
  2948. MMC_COLUMN_SET_DATA __RPC_FAR *__RPC_FAR *ppColSetData
  2949. )
  2950. {
  2951. HRESULT hr = S_OK;
  2952. size_t cbColData = 0;
  2953. MMC_COLUMN_DATA *pColData = NULL;
  2954. // Call into MMC and get the returned data
  2955. hr = This->lpVtbl->GetColumnConfigData(This, pColID, ppColSetData);
  2956. if (FAILED(hr))
  2957. {
  2958. goto Cleanup;
  2959. }
  2960. // If no data was returned then there is nothing to do
  2961. if (NULL == *ppColSetData)
  2962. {
  2963. goto Cleanup;
  2964. }
  2965. if (NULL == (*ppColSetData)->pColData)
  2966. {
  2967. goto Cleanup;
  2968. }
  2969. // At this point MMC has returned a pointer to an MMC_COLUMN_SET_DATA
  2970. // that contains an embedded pointer into the same block of memory (pColData).
  2971. // MMC expects that the caller will make a single call to CoTaskMemFree().
  2972. // The MIDL-generated stub thinks the embedded pointer needs to be freed
  2973. // separately so we need to reconstruct the output to use two separate
  2974. // blocks.
  2975. // Allocate a new MMC_COLUMN_DATA array
  2976. cbColData = sizeof(MMC_COLUMN_DATA) * (*ppColSetData)->nNumCols;
  2977. pColData = (MMC_COLUMN_DATA *)CoTaskMemAlloc(cbColData);
  2978. if (NULL == pColData)
  2979. {
  2980. CoTaskMemFree(*ppColSetData);
  2981. *ppColSetData = NULL;
  2982. hr = E_OUTOFMEMORY;
  2983. }
  2984. else
  2985. {
  2986. // Copy the column data
  2987. memcpy(pColData, (*ppColSetData)->pColData, cbColData);
  2988. // Overwrite the existing embedded pointer. There will be no memory leak
  2989. // because that pointer pointed into the same block as the
  2990. // MMC_COLUMN_SET_DATA and the stub will free the MMC_COLUMN_SET_DATA pointer.
  2991. // Now both pointers can be freed independently as the stub expects.
  2992. (*ppColSetData)->pColData = pColData;
  2993. }
  2994. Cleanup:
  2995. return hr;
  2996. }
  2997. HRESULT STDMETHODCALLTYPE IColumnData_GetColumnSortData_Proxy
  2998. (
  2999. IColumnData __RPC_FAR *This,
  3000. SColumnSetID __RPC_FAR *pColID,
  3001. MMC_SORT_SET_DATA __RPC_FAR *__RPC_FAR *ppColSortData
  3002. )
  3003. {
  3004. HRESULT hr = S_OK;
  3005. size_t cbSortData = 0;
  3006. MMC_SORT_SET_DATA *pColSortData = NULL;
  3007. // Call the proxy and get the returned data from MMC
  3008. hr = IColumnData_RemGetColumnSortData_Proxy(This, pColID, ppColSortData);
  3009. if (FAILED(hr))
  3010. {
  3011. goto Cleanup;
  3012. }
  3013. // If no data was returned then there is nothing to do
  3014. if (NULL == *ppColSortData)
  3015. {
  3016. goto Cleanup;
  3017. }
  3018. if (NULL == (*ppColSortData)->pSortData)
  3019. {
  3020. goto Cleanup;
  3021. }
  3022. // At this point the MIDL-generated proxy has returned an MMC_SORT_SET_DATA
  3023. // in which the embedded pointer pSortData points to a separate block of
  3024. // memory which must be freed independently. The snap-in thinks that
  3025. // pSortData points into the same block of memory so it will only call
  3026. // CoTaskMemFree for the MMC_SORT_SET_DATA. We need to allocate a new single
  3027. // block in the format the snap-in is expecting and free the memory returned
  3028. // from the proxy.
  3029. cbSortData = sizeof(MMC_SORT_DATA) * (*ppColSortData)->nNumItems;
  3030. pColSortData = (MMC_SORT_SET_DATA *)CoTaskMemAlloc(
  3031. sizeof(MMC_SORT_SET_DATA) + cbSortData);
  3032. if (NULL == pColSortData)
  3033. {
  3034. CoTaskMemFree((*ppColSortData)->pSortData);
  3035. CoTaskMemFree(*ppColSortData);
  3036. *ppColSortData = NULL;
  3037. hr = E_OUTOFMEMORY;
  3038. }
  3039. else
  3040. {
  3041. // Copy the sort set data
  3042. memcpy(pColSortData, (*ppColSortData), sizeof(MMC_SORT_SET_DATA));
  3043. // Set the embedded pointer to point immediately following the
  3044. // MMC_SORT_SET_DATA
  3045. pColSortData->pSortData = (MMC_SORT_DATA *)(pColSortData + 1);
  3046. // Copy the sort data
  3047. memcpy(pColSortData->pSortData, (*ppColSortData)->pSortData, cbSortData);
  3048. // Free the data returned from the proxy
  3049. CoTaskMemFree((*ppColSortData)->pSortData);
  3050. CoTaskMemFree(*ppColSortData);
  3051. // Return the new single block pointer to the snap-in
  3052. *ppColSortData = pColSortData;
  3053. }
  3054. Cleanup:
  3055. return hr;
  3056. }
  3057. HRESULT STDMETHODCALLTYPE IColumnData_GetColumnSortData_Stub
  3058. (
  3059. IColumnData __RPC_FAR *This,
  3060. SColumnSetID __RPC_FAR *pColID,
  3061. MMC_SORT_SET_DATA __RPC_FAR *__RPC_FAR *ppColSortData
  3062. )
  3063. {
  3064. HRESULT hr = S_OK;
  3065. size_t cbSortData = 0;
  3066. MMC_SORT_DATA *pSortData = NULL;
  3067. // Call into MMC and get the returned data
  3068. hr = This->lpVtbl->GetColumnSortData(This, pColID, ppColSortData);
  3069. if (FAILED(hr))
  3070. {
  3071. goto Cleanup;
  3072. }
  3073. // If no data was returned then there is nothing to do
  3074. if (NULL == *ppColSortData)
  3075. {
  3076. goto Cleanup;
  3077. }
  3078. if (NULL == (*ppColSortData)->pSortData)
  3079. {
  3080. goto Cleanup;
  3081. }
  3082. // At this point MMC has returned a pointer to an MMC_SORT_SET_DATA
  3083. // that contains an embedded pointer into the same block of memory (pSortData).
  3084. // MMC expects that the caller will make a single call to CoTaskMemFree().
  3085. // The MIDL-generated stub thinks the embedded pointer needs to be freed
  3086. // separately so we need to reconstruct the output to use two separate
  3087. // blocks.
  3088. // Allocate a new MMC_SORT_DATA array
  3089. cbSortData = sizeof(MMC_SORT_DATA) * (*ppColSortData)->nNumItems;
  3090. pSortData = (MMC_SORT_DATA *)CoTaskMemAlloc(cbSortData);
  3091. if (NULL == pSortData)
  3092. {
  3093. CoTaskMemFree(*ppColSortData);
  3094. *ppColSortData = NULL;
  3095. hr = E_OUTOFMEMORY;
  3096. }
  3097. else
  3098. {
  3099. // Copy the column data
  3100. memcpy(pSortData, (*ppColSortData)->pSortData, cbSortData);
  3101. // Overwrite the existing embedded pointer. There will be no memory leak
  3102. // because that pointer pointed into the same block as the
  3103. // MMC_SORT_SET_DATA and the stub will free the MMC_SORT_SET_DATA pointer.
  3104. // Now both pointers can be freed independently as the stub expects.
  3105. (*ppColSortData)->pSortData = pSortData;
  3106. }
  3107. Cleanup:
  3108. return hr;
  3109. }