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.

236 lines
5.8 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= {0};
  64. BOOL bRet;
  65. INT i;
  66. mbp.cbSize = sizeof(mbp);
  67. mbp.hwndOwner = hParent;
  68. mbp.hInstance = g_hInst;
  69. mbp.lpszText = MAKEINTRESOURCE(idMessage);
  70. mbp.lpszCaption = MAKEINTRESOURCE(idCaption);
  71. mbp.dwStyle = MB_OK | MB_APPLMODAL;
  72. i = MessageBoxIndirect (&mbp);
  73. bRet = (IDOK==i);
  74. return bRet;
  75. }
  76. /*****************************************************************************
  77. CreateDeviceFromID
  78. Utility for attaching to WIA and getting a root IWiaItem interface
  79. *****************************************************************************/
  80. HRESULT
  81. CreateDeviceFromId (LPWSTR szDeviceId, IWiaItem **ppItem)
  82. {
  83. IWiaDevMgr *pDevMgr;
  84. HRESULT hr = CoCreateInstance (CLSID_WiaDevMgr,
  85. NULL,
  86. CLSCTX_LOCAL_SERVER,
  87. IID_IWiaDevMgr,
  88. reinterpret_cast<LPVOID*>(&pDevMgr));
  89. if (SUCCEEDED(hr))
  90. {
  91. BSTR strId = SysAllocString (szDeviceId);
  92. if (strId)
  93. {
  94. hr = pDevMgr->CreateDevice (strId, ppItem);
  95. SysFreeString (strId);
  96. }
  97. else
  98. {
  99. hr = E_OUTOFMEMORY;
  100. }
  101. pDevMgr->Release ();
  102. }
  103. return hr;
  104. }
  105. /*****************************************************************************\
  106. GetNamesFromDataObject
  107. Return the list of selected item identifiers. Each identifier is of the form
  108. "<DEVICEID>::<FULL PATH NAME>". the list is double-null terminated
  109. *****************************************************************************/
  110. LPWSTR
  111. GetNamesFromDataObject (IDataObject *lpdobj, UINT *puItems)
  112. {
  113. FORMATETC fmt;
  114. STGMEDIUM stg;
  115. LPWSTR szRet = NULL;
  116. LPWSTR szCurrent;
  117. UINT nItems;
  118. size_t size;
  119. if (puItems)
  120. {
  121. *puItems = 0;
  122. }
  123. fmt.cfFormat = (CLIPFORMAT) RegisterClipboardFormat (TEXT("WIAItemNames"));
  124. fmt.dwAspect = DVASPECT_CONTENT;
  125. fmt.lindex = -1;
  126. fmt.ptd = NULL;
  127. fmt.tymed = TYMED_HGLOBAL;
  128. if (lpdobj && puItems && SUCCEEDED(lpdobj->GetData (&fmt, &stg)))
  129. {
  130. szCurrent = reinterpret_cast<LPWSTR>(GlobalLock (stg.hGlobal));
  131. // count the number of items in the double-null terminated string
  132. szRet = szCurrent;
  133. nItems = 0;
  134. while (*szRet)
  135. {
  136. nItems++;
  137. while (*szRet)
  138. {
  139. szRet++;
  140. }
  141. szRet++;
  142. }
  143. size = (szRet-szCurrent+1)*sizeof(WCHAR);
  144. szRet = new WCHAR[size];
  145. if (szRet)
  146. {
  147. CopyMemory (szRet, szCurrent, size);
  148. *puItems = nItems;
  149. }
  150. GlobalUnlock (stg.hGlobal);
  151. GlobalFree (stg.hGlobal);
  152. }
  153. return szRet;
  154. }
  155. CWiaUIExtension::CWiaUIExtension(void)
  156. {
  157. }
  158. CWiaUIExtension::~CWiaUIExtension(void)
  159. {
  160. }
  161. //
  162. // IWiaUIExtension
  163. //
  164. STDMETHODIMP CWiaUIExtension::DeviceDialog( PDEVICEDIALOGDATA pDeviceDialogData )
  165. {
  166. //
  167. // We are not going to implement an actual device dialog here. Just say "hi" and return.
  168. //
  169. MessageBox( NULL, TEXT("CWiaUIExtension::DeviceDialog is being called"), TEXT("DEBUG"), 0 );
  170. return E_NOTIMPL;
  171. }
  172. STDMETHODIMP CWiaUIExtension::GetDeviceIcon( BSTR bstrDeviceId, HICON *phIcon, ULONG nSize )
  173. {
  174. //
  175. // Load an icon, and copy it, using CopyIcon, so it will still be valid if our interface is freed
  176. //
  177. HICON hIcon = reinterpret_cast<HICON>(LoadImage( _Module.m_hInst, MAKEINTRESOURCE(IDI_TESTDEVICE), IMAGE_ICON, nSize, nSize, LR_DEFAULTCOLOR ));
  178. if (hIcon)
  179. {
  180. *phIcon = CopyIcon(hIcon);
  181. DestroyIcon(hIcon);
  182. return S_OK;
  183. }
  184. return E_NOTIMPL;
  185. }
  186. STDMETHODIMP CWiaUIExtension::GetDeviceBitmapLogo( BSTR bstrDeviceId, HBITMAP *phBitmap, ULONG nMaxWidth, ULONG nMaxHeight )
  187. {
  188. //
  189. // This method is never actually called currently. It is only here for future use.
  190. //
  191. MessageBox( NULL, TEXT("CWiaUIExtension::GetDeviceBitmapLogo is being called"), TEXT("DEBUG"), 0 );
  192. return E_NOTIMPL;
  193. }