Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

241 lines
13 KiB

  1. //
  2. // This file contains the DllGetClassObject for the shell32.dll COM objects
  3. //
  4. #include "shellprv.h"
  5. #pragma hdrstop
  6. #include <shguidp.h> // get the CLSID definitions, the bits are built into shguidp.lib
  7. #include <shlguid.h>
  8. #include <shldisp.h>
  9. #include "actdesk.h"
  10. #include "ovrlaymn.h"
  11. #include "treewalk.h"
  12. #include "openwith.h"
  13. #include "clsobj.h"
  14. #define DllAddRef() // once we implement DllCanUnloadNow we need these
  15. #define DllRelease()
  16. // static class factory (no allocs!)
  17. typedef struct {
  18. const IClassFactoryVtbl *cf;
  19. REFCLSID rclsid;
  20. HRESULT (*pfnCreate)(IUnknown *, REFIID, void **);
  21. ULONG flags;
  22. } OBJ_ENTRY;
  23. // flags:
  24. #define OBJ_AGGREGATABLE 1
  25. extern const IClassFactoryVtbl c_CFVtbl; // forward
  26. //
  27. // we always do a linear search here so put your most often used things first
  28. //
  29. // we save code by checking aggregation on our side (have a bit in this const table)
  30. // instead of having each CreateInstance function do it (since most are not aggregatable)
  31. //
  32. const OBJ_ENTRY c_clsmap[] = {
  33. { &c_CFVtbl, &CLSID_QueryAssociations, CQueryAssociations_CreateInstance, 0},
  34. { &c_CFVtbl, &CLSID_MyDocuments, CMyDocsFolder_CreateInstance, 0 },
  35. { &c_CFVtbl, &CLSID_ShellDesktop, CDesktop_CreateInstance, 0 },
  36. { &c_CFVtbl, &CLSID_ShellFSFolder, CFSFolder_CreateInstance, OBJ_AGGREGATABLE },
  37. { &c_CFVtbl, &CLSID_MyComputer, CDrives_CreateInstance, 0 },
  38. { &c_CFVtbl, &CLSID_NetworkPlaces, CNetwork_CreateInstance, 0 },
  39. { &c_CFVtbl, &CLSID_ShellFileDefExt, CShellFileDefExt_CreateInstance, OBJ_AGGREGATABLE },
  40. { &c_CFVtbl, &CLSID_ShellItem, CShellItem_CreateInstance, 0},
  41. { &c_CFVtbl, &CLSID_OpenWithMenu, COpenWithMenu_CreateInstance, 0},
  42. { &c_CFVtbl, &CLSID_ShellLink, CShellLink_CreateInstance, 0 },
  43. { &c_CFVtbl, &CLSID_ShellDrvDefExt, CShellDrvDefExt_CreateInstance, OBJ_AGGREGATABLE },
  44. { &c_CFVtbl, &CLSID_ShellNetDefExt, CShellDrvDefExt_CreateInstance, OBJ_AGGREGATABLE },
  45. { &c_CFVtbl, &CLSID_ShellCopyHook, CCopyHook_CreateInstance, 0 },
  46. { &c_CFVtbl, &CLSID_ControlPanel, CControlPanel_CreateInstance, 0 },
  47. { &c_CFVtbl, &CLSID_Printers, CPrinters_CreateInstance, 0 },
  48. { &c_CFVtbl, &CLSID_RecycleBin, CBitBucket_CreateInstance, 0 },
  49. { &c_CFVtbl, &CLSID_CFSIconOverlayManager, CFSIconOverlayManager_CreateInstance, 0 },
  50. { &c_CFVtbl, &CLSID_RecycleBinCleaner, CRecycleBinCleaner_CreateInstance, 0 },
  51. { &c_CFVtbl, &CLSID_DocFindFolder, CDocFindFolder_CreateInstance, 0 },
  52. { &c_CFVtbl, &CLSID_DocFindPersistHistory, CFindPersistHistory_CreateInstance, 0 },
  53. { &c_CFVtbl, &CLSID_DefViewPersistHistory, CDefViewPersistHistory_CreateInstance, 0 },
  54. { &c_CFVtbl, &CLSID_ComputerFindFolder, CComputerFindFolder_CreateInstance, 0 },
  55. { &c_CFVtbl, &CLSID_DocFindCommand, CDocFindCommand_CreateInstance, 0 },
  56. { &c_CFVtbl, &CLSID_CShellTreeWalker, CShellTreeWalker_CreateInstance, 0 },
  57. { &c_CFVtbl, &CLSID_BriefcaseFolder, CFSBrfFolder_CreateInstance, 0 },
  58. { &c_CFVtbl, &CLSID_DocFileColumnProvider, CDocFileColumns_CreateInstance, 0 },
  59. { &c_CFVtbl, &CLSID_LinkColumnProvider, CLinkColumnProvider_CreateInstance, 0 },
  60. { &c_CFVtbl, &CLSID_FileSysColumnProvider, CFileSysColumnProvider_CreateInstance, 0 },
  61. { &c_CFVtbl, &CLSID_FileSearchBand, CFileSearchBand_CreateInstance, OBJ_AGGREGATABLE },
  62. { &c_CFVtbl, &CLSID_FolderShortcut, CFolderShortcut_CreateInstance, 0 },
  63. { &c_CFVtbl, &CLSID_MountedVolume, CMountedVolume_CreateInstance, 0 },
  64. // menuband objects
  65. { &c_CFVtbl, &CLSID_MenuBand, CMenuBand_CreateInstance, 0 },
  66. { &c_CFVtbl, &CLSID_ISFBand, CISFBand_CreateInstance, 0 },
  67. { &c_CFVtbl, &CLSID_QuickLinks, CQuickLinks_CreateInstance, 0 },
  68. { &c_CFVtbl, &CLSID_TrackShellMenu, CTrackShellMenu_CreateInstance, 0},
  69. { &c_CFVtbl, &CLSID_MenuBandSite, CMenuBandSite_CreateInstance, 0},
  70. { &c_CFVtbl, &CLSID_MenuDeskBar, CMenuDeskBar_CreateInstance, 0},
  71. { &c_CFVtbl, &CLSID_ActiveDesktop, CActiveDesktop_CreateInstance, 0 },
  72. { &c_CFVtbl, &CLSID_DeskMovr, CDeskMovr_CreateInstance, OBJ_AGGREGATABLE },
  73. { &c_CFVtbl, &CLSID_CopyToMenu, CCopyToMenu_CreateInstance, 0 },
  74. { &c_CFVtbl, &CLSID_MoveToMenu, CMoveToMenu_CreateInstance, 0 },
  75. { &c_CFVtbl, &CLSID_CDeskHtmlProp, CDeskHtmlProp_CreateInstance, 0 },
  76. { &c_CFVtbl, &CLSID_ShellFldSetExt, CFolderOptionsPsx_CreateInstance, 0 },
  77. { &c_CFVtbl, &CLSID_Shell, CShellDispatch_CreateInstance, 0 },
  78. { &c_CFVtbl, &CLSID_ShellFolderView, CShellFolderView_CreateInstance, 0 },
  79. { &c_CFVtbl, &CLSID_ShellFolderViewOC, CShellFolderViewOC_CreateInstance, OBJ_AGGREGATABLE },
  80. { &c_CFVtbl, &CLSID_WebViewFolderContents, CWebViewFolderContents_CreateInstance, OBJ_AGGREGATABLE },
  81. { &c_CFVtbl, &CLSID_StartMenu, CStartMenu_CreateInstance, 0 },
  82. { &c_CFVtbl, &CLSID_CmdFileIcon, CShellCmdFileIcon_CreateInstance, 0 },
  83. { &c_CFVtbl, &CLSID_NewMenu, CNewMenu_CreateInstance, 0},
  84. { &c_CFVtbl, &CLSID_SendToMenu, CSendToMenu_CreateInstance, 0},
  85. { &c_CFVtbl, &CLSID_FileTypes, CFileTypes_CreateInstance, 0 },
  86. { &c_CFVtbl, &CLSID_MIMEFileTypesHook, CFileTypes_CreateInstance, 0 },
  87. { &c_CFVtbl, &CLSID_DragDropHelper, CDragImages_CreateInstance, 0},
  88. { &c_CFVtbl, &CLSID_ExeDropTarget, CExeDropTarget_CreateInstance, 0},
  89. { &c_CFVtbl, &CLSID_FolderItem, CFolderItem_CreateInstance, 0},
  90. { &c_CFVtbl, &CLSID_FolderItemsFDF, CFolderItemsFDF_CreateInstance, 0},
  91. { &c_CFVtbl, &CLSID_NetCrawler, CNetCrawler_CreateInstance, 0},
  92. { &c_CFVtbl, &CLSID_WorkgroupNetCrawler, CWorkgroupCrawler_CreateInstance, 0},
  93. { &c_CFVtbl, &CLSID_EncryptionContextMenuHandler, CEncryptionContextMenuHandler_CreateInstance, 0},
  94. { &c_CFVtbl, &CLSID_PropertiesUI, CPropertyUI_CreateInstance, 0},
  95. { &c_CFVtbl, &CLSID_TimeCategorizer, CTimeCategorizer_CreateInstance, 0},
  96. { &c_CFVtbl, &CLSID_SizeCategorizer, CSizeCategorizer_CreateInstance, 0},
  97. { &c_CFVtbl, &CLSID_DriveSizeCategorizer, CDriveSizeCategorizer_CreateInstance, 0},
  98. { &c_CFVtbl, &CLSID_DriveTypeCategorizer, CDriveTypeCategorizer_CreateInstance, 0},
  99. { &c_CFVtbl, &CLSID_FreeSpaceCategorizer, CFreeSpaceCategorizer_CreateInstance, 0},
  100. { &c_CFVtbl, &CLSID_MergedCategorizer, CMergedCategorizer_CreateInstance, 0},
  101. { &c_CFVtbl, &CLSID_DynamicStorage, CDynamicStorage_CreateInstance, 0},
  102. { &c_CFVtbl, &CLSID_CDBurn, CCDBurn_CreateInstance, 0},
  103. { &c_CFVtbl, &CLSID_BurnAudioCDExtension, CBurnAudioCDExtension_CreateInstance, 0},
  104. { &c_CFVtbl, &CLSID_LocalCopyHelper, CLocalCopyHelper_CreateInstance, 0},
  105. { &c_CFVtbl, &CLSID_MergedFolder, CMergedFolder_CreateInstance, 0},
  106. { &c_CFVtbl, &CLSID_CDBurnFolder, CCDBurnFolder_CreateInstance, 0},
  107. // { &c_CFVtbl, &CLSID_TripleD, CTripleD_CreateInstance, 0},
  108. { &c_CFVtbl, &CLSID_CompositeFolder, CCompositeFolder_CreateInstance, 0},
  109. { &c_CFVtbl, &CLSID_StartMenuFolder, CStartMenuFolder_CreateInstance, 0},
  110. { &c_CFVtbl, &CLSID_ProgramsFolder, CProgramsFolder_CreateInstance, 0},
  111. // { &c_CFVtbl, &CLSID_SyreCleaner, CSystemRestoreCleaner_CreateInstance, 0},
  112. { &c_CFVtbl, &CLSID_VersionColProvider, CVerColProvider_CreateInstance, 0},
  113. { &c_CFVtbl, &CLSID_HWShellExecute, CHWShellExecute_CreateInstance, 0},
  114. { &c_CFVtbl, &CLSID_ShellAutoplay, CDeviceEventHandler_CreateInstance, 0},
  115. { &c_CFVtbl, &CLSID_AutoPlayVerb, CAutoPlayVerb_CreateInstance, 0},
  116. { &c_CFVtbl, &CLSID_UserNotification, CUserNotification_CreateInstance, 0},
  117. { &c_CFVtbl, &CLSID_UserEventTimer, CUserEventTimer_CreateInstance, 0},
  118. { &c_CFVtbl, &CLSID_StorageProcessor, CStorageProcessor_CreateInstance, 0},
  119. { &c_CFVtbl, &CLSID_TransferConfirmationUI, CTransferConfirmation_CreateInstance, 0},
  120. { &c_CFVtbl, &CLSID_AutomationCM, CAutomationCM_CreateInstance, 0},
  121. { &c_CFVtbl, &CLSID_ShellThumbnailDiskCache, CThumbStore_CreateInstance, 0},
  122. { &c_CFVtbl, &CLSID_DefCategoryProvider, CCategoryProvider_CreateInstance, 0},
  123. { &c_CFVtbl, &CLSID_SharedDocuments, CSharedDocFolder_CreateInstance, 0},
  124. { &c_CFVtbl, &CLSID_PostBootReminder, CPostBootReminder_CreateInstance, 0},
  125. { &c_CFVtbl, &CLSID_Thumbnail, CThumbnail_CreateInstance, 0},
  126. { &c_CFVtbl, &CLSID_StartMenuPin, CStartMenuPin_CreateInstance, 0},
  127. { &c_CFVtbl, &CLSID_ClientExtractIcon, CClientExtractIcon_CreateInstance, 0 },
  128. { &c_CFVtbl, &CLSID_FolderCustomize, CFolderCustomize_CreateInstance, 0},
  129. { &c_CFVtbl, &CLSID_CWebViewMimeFilter, CWebViewMimeFilter_CreateInstance, 0 },
  130. { &c_CFVtbl, &CLSID_WebViewRegTreeItem, CWebViewRegTreeItem_CreateInstance, 0},
  131. { &c_CFVtbl, &CLSID_ThemesRegTreeItem, CThemesRegTreeItem_CreateInstance, 0},
  132. // { &c_CFVtbl, &CLSID_WirelessDevices, CWirelessDevices_CreateInstance, 0 },
  133. { &c_CFVtbl, &CLSID_NamespaceWalker, CNamespaceWalk_CreateInstance, 0 },
  134. { &c_CFVtbl, &CLSID_WebWizardHost, CWebWizardPage_CreateInstance, 0 },
  135. { &c_CFVtbl, &CLSID_PersonalStartMenu, CPersonalStartMenu_CreateInstance, 0 },
  136. { &c_CFVtbl, &CLSID_FadeTask, CFadeTask_CreateInstance, 0 },
  137. { &c_CFVtbl, &CLSID_FolderViewHost, CFolderViewHost_CreateInstance, 0 },
  138. #ifdef _X86_
  139. { &c_CFVtbl, &CLSID_PifProperties, CProxyPage_CreateInstance, 0 },
  140. #endif
  141. { NULL, NULL, NULL }
  142. };
  143. STDMETHODIMP CCF_QueryInterface(IClassFactory *pcf, REFIID riid, void **ppvObj)
  144. {
  145. // OBJ_ENTRY *this = IToClass(OBJ_ENTRY, cf, pcf);
  146. if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
  147. {
  148. *ppvObj = (void *)pcf;
  149. DllAddRef();
  150. return NOERROR;
  151. }
  152. *ppvObj = NULL;
  153. return E_NOINTERFACE;
  154. }
  155. STDMETHODIMP_(ULONG) CCF_AddRef(IClassFactory *pcf)
  156. {
  157. DllAddRef();
  158. return 2;
  159. }
  160. STDMETHODIMP_(ULONG) CCF_Release(IClassFactory *pcf)
  161. {
  162. DllRelease();
  163. return 1;
  164. }
  165. STDMETHODIMP CCF_CreateInstance(IClassFactory *pcf, IUnknown *punkOuter, REFIID riid, void **ppvObject)
  166. {
  167. OBJ_ENTRY *this = IToClass(OBJ_ENTRY, cf, pcf);
  168. *ppvObject = NULL; // to avoid nulling it out in every create function...
  169. if (punkOuter && !(this->flags & OBJ_AGGREGATABLE))
  170. return CLASS_E_NOAGGREGATION;
  171. return this->pfnCreate(punkOuter, riid, ppvObject);
  172. }
  173. STDMETHODIMP CCF_LockServer(IClassFactory *pcf, BOOL fLock)
  174. {
  175. /* SHELL32.DLL does not implement DllCanUnloadNow, thus does not have a DLL refcount
  176. This means we can never unload!
  177. if (fLock)
  178. DllAddRef();
  179. else
  180. DllRelease();
  181. */
  182. return S_OK;
  183. }
  184. const IClassFactoryVtbl c_CFVtbl = {
  185. CCF_QueryInterface, CCF_AddRef, CCF_Release,
  186. CCF_CreateInstance,
  187. CCF_LockServer
  188. };
  189. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
  190. {
  191. if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
  192. {
  193. const OBJ_ENTRY *pcls;
  194. for (pcls = c_clsmap; pcls->rclsid; pcls++)
  195. {
  196. if (IsEqualIID(rclsid, pcls->rclsid))
  197. {
  198. *ppv = (void *)&(pcls->cf);
  199. DllAddRef();
  200. return NOERROR;
  201. }
  202. }
  203. #ifdef DEBUG
  204. {
  205. TCHAR szClass[GUIDSTR_MAX];
  206. SHStringFromGUID(rclsid, szClass, ARRAYSIZE(szClass));
  207. AssertMsg(TF_ERROR,
  208. TEXT("DllGetClassObject !!! %s not in shell32; ")
  209. TEXT("corrupted registry?"), szClass);
  210. }
  211. #endif
  212. }
  213. *ppv = NULL;
  214. return CLASS_E_CLASSNOTAVAILABLE;
  215. }