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.

284 lines
5.1 KiB

  1. //
  2. // Copyright (c) 2001 Microsoft Corporation
  3. //
  4. //
  5. #include "shcut.h"
  6. // {b95ec110-5c3e-433c-b969-701c10521ef2}
  7. static const GUID CLSID_FusionShortcut =
  8. { 0xb95ec110, 0x5c3e, 0x433c, { 0xb9, 0x69, 0x70, 0x1c, 0x10, 0x52, 0x1e, 0xf2 } };
  9. extern ULONG DllAddRef(void);
  10. extern ULONG DllRelease(void);
  11. // ----------------------------------------------------------------------------
  12. // ----------------------------------------------------------------------------
  13. CFusionShortcutClassFactory::CFusionShortcutClassFactory()
  14. {
  15. _cRef = 1;
  16. }
  17. // ----------------------------------------------------------------------------
  18. HRESULT
  19. CFusionShortcutClassFactory::QueryInterface(REFIID iid, void **ppv)
  20. {
  21. HRESULT hr = S_OK;
  22. *ppv = NULL;
  23. if (iid == IID_IUnknown || iid == IID_IClassFactory)
  24. {
  25. *ppv = (IClassFactory *)this;
  26. }
  27. else
  28. {
  29. hr = E_NOINTERFACE;
  30. goto exit;
  31. }
  32. ((IUnknown *)*ppv)->AddRef();
  33. exit:
  34. return hr;
  35. }
  36. // ----------------------------------------------------------------------------
  37. ULONG
  38. CFusionShortcutClassFactory::AddRef()
  39. {
  40. return (ULONG) InterlockedIncrement(&_cRef);
  41. }
  42. ULONG
  43. CFusionShortcutClassFactory::Release()
  44. {
  45. LONG ulCount = InterlockedDecrement(&_cRef);
  46. if (ulCount <= 0)
  47. {
  48. delete this;
  49. }
  50. return (ULONG) ulCount;
  51. }
  52. HRESULT
  53. CFusionShortcutClassFactory::LockServer(BOOL lock)
  54. {
  55. return (lock ?
  56. DllAddRef() :
  57. DllRelease());
  58. }
  59. // ----------------------------------------------------------------------------
  60. HRESULT
  61. CFusionShortcutClassFactory::CreateInstance(IUnknown* pUnkOuter, REFIID iid, void** ppv)
  62. {
  63. HRESULT hr = S_OK;
  64. CFusionShortcut *pFusionShortcut = NULL;
  65. *ppv = NULL;
  66. if (pUnkOuter && iid != IID_IUnknown)
  67. {
  68. hr = CLASS_E_NOAGGREGATION;
  69. goto exit;
  70. }
  71. pFusionShortcut = new CFusionShortcut();
  72. if (pFusionShortcut == NULL)
  73. {
  74. hr = E_OUTOFMEMORY;
  75. goto exit;
  76. }
  77. if (iid == IID_IUnknown)
  78. {
  79. *ppv = (IShellLink *)pFusionShortcut;
  80. pFusionShortcut->AddRef();
  81. }
  82. else
  83. {
  84. hr = pFusionShortcut->QueryInterface(iid, ppv);
  85. if (FAILED(hr))
  86. goto exit;
  87. }
  88. exit:
  89. if (pFusionShortcut)
  90. pFusionShortcut->Release();
  91. return hr;
  92. }
  93. // ----------------------------------------------------------------------------
  94. // ----------------------------------------------------------------------------
  95. CFusionShortcut::CFusionShortcut()
  96. : RefCount()
  97. {
  98. // Don't validate this until after construction.
  99. m_dwFlags = FUSSHCUT_FL_NOTDIRTY;
  100. m_pwzShortcutFile = NULL;
  101. m_pwzPath = NULL;
  102. m_pwzDesc = NULL;
  103. m_pwzIconFile = NULL;
  104. m_niIcon = 0;
  105. m_pwzWorkingDirectory = NULL;
  106. m_nShowCmd = DEFAULTSHOWCMD;
  107. m_wHotkey = 0;
  108. m_pwzCodebase = NULL;
  109. m_pIdentity = NULL;
  110. return;
  111. }
  112. CFusionShortcut::~CFusionShortcut(void)
  113. {
  114. if (m_pwzShortcutFile)
  115. {
  116. delete [] m_pwzShortcutFile;
  117. m_pwzShortcutFile = NULL;
  118. }
  119. if (m_pwzPath)
  120. {
  121. delete [] m_pwzPath;
  122. m_pwzPath = NULL;
  123. }
  124. if (m_pwzDesc)
  125. {
  126. delete [] m_pwzDesc;
  127. m_pwzDesc = NULL;
  128. }
  129. if (m_pwzIconFile)
  130. {
  131. delete [] m_pwzIconFile;
  132. m_pwzIconFile = NULL;
  133. m_niIcon = 0;
  134. }
  135. if (m_pwzWorkingDirectory)
  136. {
  137. delete [] m_pwzWorkingDirectory;
  138. m_pwzWorkingDirectory = NULL;
  139. }
  140. if (m_pwzCodebase)
  141. {
  142. delete [] m_pwzCodebase;
  143. m_pwzCodebase = NULL;
  144. }
  145. if (m_pIdentity)
  146. {
  147. m_pIdentity->Release();
  148. }
  149. RefCount::~RefCount();
  150. return;
  151. }
  152. HRESULT CFusionShortcut::GetAssemblyIdentity(LPASSEMBLY_IDENTITY* ppAsmId)
  153. {
  154. HRESULT hr = S_OK;
  155. if (ppAsmId == NULL)
  156. {
  157. hr = E_INVALIDARG;
  158. goto exit;
  159. }
  160. if (m_pIdentity)
  161. {
  162. m_pIdentity->AddRef();
  163. *ppAsmId = m_pIdentity;
  164. }
  165. else
  166. *ppAsmId = NULL;
  167. exit:
  168. return hr;
  169. }
  170. ULONG STDMETHODCALLTYPE CFusionShortcut::AddRef(void)
  171. {
  172. ULONG ulcRef;
  173. ulcRef = RefCount::AddRef();
  174. return(ulcRef);
  175. }
  176. ULONG STDMETHODCALLTYPE CFusionShortcut::Release(void)
  177. {
  178. ULONG ulcRef;
  179. ulcRef = RefCount::Release();
  180. return(ulcRef);
  181. }
  182. HRESULT STDMETHODCALLTYPE CFusionShortcut::QueryInterface(REFIID riid,
  183. PVOID *ppvObject)
  184. {
  185. HRESULT hr = S_OK;
  186. if (riid == IID_IExtractIcon)
  187. {
  188. *ppvObject = (IExtractIcon*)this;
  189. }
  190. else if (riid == IID_IPersist)
  191. {
  192. *ppvObject = (IPersist*)(IPersistFile*)this;
  193. }
  194. else if (riid == IID_IPersistFile)
  195. {
  196. *ppvObject = (IPersistFile*)this;
  197. }
  198. else if (riid == IID_IShellExtInit)
  199. {
  200. *ppvObject = (IShellExtInit*)this;
  201. }
  202. else if (riid == IID_IShellLink)
  203. {
  204. *ppvObject = (IShellLink*)this;
  205. }
  206. else if (riid == IID_IShellPropSheetExt)
  207. {
  208. *ppvObject = (IShellPropSheetExt*)this;
  209. }
  210. else if (riid == IID_IQueryInfo)
  211. {
  212. *ppvObject = (IQueryInfo*)this;
  213. }
  214. else if (riid == IID_IUnknown)
  215. {
  216. *ppvObject = (IUnknown*)(IShellLink*)this;
  217. }
  218. else
  219. {
  220. *ppvObject = NULL;
  221. hr = E_NOINTERFACE;
  222. }
  223. if (hr == S_OK)
  224. AddRef();
  225. return(hr);
  226. }