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.

257 lines
6.2 KiB

  1. ////////////////////////////////////
  2. // (C) COPYRIGHT MICROSOFT CORP., 1998-1999
  3. //
  4. // FILE: EXTEND.CPP
  5. //
  6. // DESCRIPTION: Implements core DLL routines as well as web view extensions.
  7. //
  8. #include "precomp.h"
  9. #pragma hdrstop
  10. #include <string.h>
  11. #include <tchar.h>
  12. #include "resource.h"
  13. #include "extidl_i.c"
  14. CComModule _Module;
  15. BEGIN_OBJECT_MAP(ObjectMap)
  16. OBJECT_ENTRY(CLSID_TestShellExt, CShellExt)
  17. OBJECT_ENTRY(CLSID_TestUIExtension, CWiaUIExtension)
  18. END_OBJECT_MAP()
  19. STDAPI DllRegisterServer(void)
  20. {
  21. // registers object, typelib and all interfaces in typelib
  22. return _Module.RegisterServer(TRUE);
  23. }
  24. STDAPI DllUnregisterServer(void)
  25. {
  26. return _Module.UnregisterServer();
  27. }
  28. EXTERN_C
  29. BOOL
  30. DllMain(
  31. HINSTANCE hinst,
  32. DWORD dwReason,
  33. LPVOID lpReserved)
  34. {
  35. switch (dwReason) {
  36. case DLL_PROCESS_ATTACH:
  37. _Module.Init (ObjectMap, hinst);
  38. DisableThreadLibraryCalls(hinst);
  39. break;
  40. case DLL_PROCESS_DETACH:
  41. _Module.Term();
  42. break;
  43. }
  44. return TRUE;
  45. }
  46. extern "C" STDMETHODIMP DllCanUnloadNow(void)
  47. {
  48. return _Module.GetLockCount()==0 ? S_OK : S_FALSE;
  49. }
  50. extern "C" STDAPI DllGetClassObject(
  51. REFCLSID rclsid,
  52. REFIID riid,
  53. LPVOID *ppv)
  54. {
  55. return _Module.GetClassObject(rclsid, riid, ppv);
  56. }
  57. /*****************************************************************************
  58. ShowMessage
  59. Utility function for displaying messageboxes
  60. ******************************************************************************/
  61. BOOL ShowMessage (HWND hParent, INT idCaption, INT idMessage)
  62. {
  63. MSGBOXPARAMS mbp;
  64. BOOL bRet;
  65. INT i;
  66. ZeroMemory (&mbp, sizeof(mbp));
  67. mbp.cbSize = sizeof(mbp);
  68. mbp.hwndOwner = hParent;
  69. mbp.hInstance = g_hInst;
  70. mbp.lpszText = MAKEINTRESOURCE(idMessage);
  71. mbp.lpszCaption = MAKEINTRESOURCE(idCaption);
  72. mbp.dwStyle = MB_OK | MB_APPLMODAL;
  73. i = MessageBoxIndirect (&mbp);
  74. bRet = (IDOK==i);
  75. return bRet;
  76. }
  77. /*****************************************************************************
  78. FindLastID
  79. Utility for getting the last relative pidl from a full pidl
  80. ******************************************************************************/
  81. // unsafe macros
  82. #define _ILSkip(pidl, cb) ((LPITEMIDLIST)(((BYTE*)(pidl))+cb))
  83. #define ILNext(pidl) _ILSkip(pidl, (pidl)->mkid.cb)
  84. LPITEMIDLIST
  85. FindLastID(LPCITEMIDLIST pidl)
  86. {
  87. LPCITEMIDLIST pidlLast = pidl;
  88. LPCITEMIDLIST pidlNext = pidl;
  89. if (pidl == NULL)
  90. return NULL;
  91. // Find the last one
  92. while (pidlNext->mkid.cb)
  93. {
  94. pidlLast = pidlNext;
  95. pidlNext = ILNext(pidlLast);
  96. }
  97. return (LPITEMIDLIST)pidlLast;
  98. }
  99. /*****************************************************************************
  100. CreateDeviceFromID
  101. Utility for attaching to WIA and getting a root IWiaItem interface
  102. *****************************************************************************/
  103. HRESULT
  104. CreateDeviceFromId (LPWSTR szDeviceId, IWiaItem **ppItem)
  105. {
  106. IWiaDevMgr *pDevMgr;
  107. HRESULT hr = CoCreateInstance (CLSID_WiaDevMgr,
  108. NULL,
  109. CLSCTX_LOCAL_SERVER,
  110. IID_IWiaDevMgr,
  111. reinterpret_cast<LPVOID*>(&pDevMgr));
  112. if (SUCCEEDED(hr))
  113. {
  114. BSTR strId = SysAllocString (szDeviceId);
  115. hr = pDevMgr->CreateDevice (strId, ppItem);
  116. SysFreeString (strId);
  117. pDevMgr->Release ();
  118. }
  119. return hr;
  120. }
  121. /*****************************************************************************\
  122. GetNamesFromDataObject
  123. Return the list of selected item identifiers. Each identifier is of the form
  124. "<DEVICEID>::<FULL PATH NAME>". the list is double-null terminated
  125. *****************************************************************************/
  126. LPWSTR
  127. GetNamesFromDataObject (IDataObject *lpdobj, UINT *puItems)
  128. {
  129. FORMATETC fmt;
  130. STGMEDIUM stg;
  131. LPWSTR szRet = NULL;
  132. LPWSTR szCurrent;
  133. UINT nItems;
  134. size_t size;
  135. if (puItems)
  136. {
  137. *puItems = 0;
  138. }
  139. fmt.cfFormat = (CLIPFORMAT) RegisterClipboardFormat (TEXT("WIAItemNames"));
  140. fmt.dwAspect = DVASPECT_CONTENT;
  141. fmt.lindex = -1;
  142. fmt.ptd = NULL;
  143. fmt.tymed = TYMED_HGLOBAL;
  144. if (lpdobj && puItems && SUCCEEDED(lpdobj->GetData (&fmt, &stg)))
  145. {
  146. szCurrent = reinterpret_cast<LPWSTR>(GlobalLock (stg.hGlobal));
  147. // count the number of items in the double-null terminated string
  148. szRet = szCurrent;
  149. nItems = 0;
  150. while (*szRet)
  151. {
  152. nItems++;
  153. while (*szRet)
  154. {
  155. szRet++;
  156. }
  157. szRet++;
  158. }
  159. *puItems = nItems;
  160. size = (szRet-szCurrent+1)*sizeof(WCHAR);
  161. szRet = new WCHAR[size];
  162. CopyMemory (szRet, szCurrent, size);
  163. GlobalUnlock (stg.hGlobal);
  164. GlobalFree (stg.hGlobal);
  165. }
  166. return szRet;
  167. }
  168. CWiaUIExtension::CWiaUIExtension(void)
  169. {
  170. }
  171. CWiaUIExtension::~CWiaUIExtension(void)
  172. {
  173. }
  174. //
  175. // IWiaUIExtension
  176. //
  177. STDMETHODIMP CWiaUIExtension::DeviceDialog( PDEVICEDIALOGDATA pDeviceDialogData )
  178. {
  179. //
  180. // We are not going to implement an actual device dialog here. Just say "hi" and return.
  181. //
  182. MessageBox( NULL, TEXT("CWiaUIExtension::DeviceDialog is being called"), TEXT("DEBUG"), 0 );
  183. return E_NOTIMPL;
  184. }
  185. STDMETHODIMP CWiaUIExtension::GetDeviceIcon( BSTR bstrDeviceId, HICON *phIcon, ULONG nSize )
  186. {
  187. //
  188. // Load an icon, and copy it, using CopyIcon, so it will still be valid if our interface is freed
  189. //
  190. HICON hIcon = reinterpret_cast<HICON>(LoadImage( _Module.m_hInst, MAKEINTRESOURCE(IDI_TESTDEVICE), IMAGE_ICON, nSize, nSize, LR_DEFAULTCOLOR ));
  191. if (hIcon)
  192. {
  193. *phIcon = CopyIcon(hIcon);
  194. DestroyIcon(hIcon);
  195. return S_OK;
  196. }
  197. return E_NOTIMPL;
  198. }
  199. STDMETHODIMP CWiaUIExtension::GetDeviceBitmapLogo( BSTR bstrDeviceId, HBITMAP *phBitmap, ULONG nMaxWidth, ULONG nMaxHeight )
  200. {
  201. //
  202. // This method is never actually called currently. It is only here for future use.
  203. //
  204. MessageBox( NULL, TEXT("CWiaUIExtension::GetDeviceBitmapLogo is being called"), TEXT("DEBUG"), 0 );
  205. return E_NOTIMPL;
  206. }