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.

255 lines
6.0 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1999
  3. Module Name:
  4. DfsShell.cpp
  5. Abstract:
  6. This is the implementation file for Dfs Shell Extension object which implements
  7. IShellIExtInit and IShellPropSheetExt.
  8. Author:
  9. Constancio Fernandes (ferns@qspl.stpp.soft.net) 12-Jan-1998
  10. Environment:
  11. NT only.
  12. */
  13. #include "stdafx.h"
  14. #include <dsclient.h>
  15. #include "ctshlext.h"
  16. #include "wiz.h"
  17. #include "genpage.h"
  18. #define ByteOffset(base, offset) (((LPBYTE)base)+offset)
  19. /*----------------------------------------------------------------------
  20. IShellExtInit Implementation.
  21. ------------------------------------------------------------------------*/
  22. STDMETHODIMP CCertTypeShlExt::Initialize
  23. (
  24. IN LPCITEMIDLIST pidlFolder, // Points to an ITEMIDLIST structure
  25. IN LPDATAOBJECT pDataObj, // Points to an IDataObject interface
  26. IN HKEY hkeyProgID // Registry key for the file object or folder type
  27. )
  28. {
  29. HRESULT hr = 0;
  30. FORMATETC fmte = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  31. STGMEDIUM medium = { TYMED_NULL };
  32. LPDSOBJECTNAMES pDsObjects;
  33. CString csClass, csPath;
  34. USES_CONVERSION;
  35. LPWSTR wszTypeDN = NULL, wszType = NULL;
  36. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  37. // if we have a pDataObj then try and get the first name from it
  38. if ( pDataObj )
  39. {
  40. // get path and class
  41. fmte.cfFormat = (CLIPFORMAT) RegisterClipboardFormat(CFSTR_DSOBJECTNAMES);
  42. if ( SUCCEEDED(pDataObj->GetData(&fmte, &medium)) )
  43. {
  44. pDsObjects = (LPDSOBJECTNAMES)medium.hGlobal;
  45. m_Count = pDsObjects->cItems;
  46. if(m_Count > 0)
  47. {
  48. m_ahCertTemplates = (HCERTTYPE *)LocalAlloc(LMEM_FIXED, sizeof(HCERTTYPE)*m_Count);
  49. if(m_ahCertTemplates == NULL)
  50. {
  51. hr = E_OUTOFMEMORY;
  52. goto error;
  53. }
  54. ZeroMemory(m_ahCertTemplates, sizeof(HCERTTYPE)*m_Count);
  55. for (UINT index = 0; index < m_Count ; index++)
  56. {
  57. LPWSTR wszEnd = NULL;
  58. wszTypeDN = (LPWSTR)ByteOffset(pDsObjects, pDsObjects->aObjects[index].offsetName);
  59. if(wszTypeDN == NULL)
  60. {
  61. continue;
  62. }
  63. wszTypeDN = wcsstr(wszTypeDN, L"CN=");
  64. if(wszTypeDN == NULL)
  65. {
  66. continue;
  67. }
  68. wszTypeDN += 3;
  69. wszType = (LPWSTR)LocalAlloc(LMEM_FIXED, sizeof(WCHAR)*(wcslen(wszTypeDN)+1));
  70. if(wszType == NULL)
  71. {
  72. hr = E_OUTOFMEMORY;
  73. goto error;
  74. }
  75. wcscpy(wszType, wszTypeDN);
  76. wszEnd = wcschr(wszType, L',');
  77. if(wszEnd)
  78. {
  79. *wszEnd = 0;
  80. }
  81. hr = CAFindCertTypeByName(wszType, NULL, CT_ENUM_MACHINE_TYPES |
  82. CT_ENUM_USER_TYPES |
  83. CT_FLAG_NO_CACHE_LOOKUP,
  84. &m_ahCertTemplates[index]);
  85. LocalFree(wszType);
  86. wszType = NULL;
  87. }
  88. }
  89. ReleaseStgMedium(&medium);
  90. }
  91. }
  92. hr = S_OK; // success
  93. error:
  94. return hr;
  95. }
  96. STDMETHODIMP CCertTypeShlExt::AddPages
  97. (
  98. IN LPFNADDPROPSHEETPAGE lpfnAddPage,
  99. IN LPARAM lParam
  100. )
  101. {
  102. PropertyPage* pBasePage;
  103. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  104. if(m_ahCertTemplates[0] == NULL)
  105. {
  106. return E_UNEXPECTED;
  107. }
  108. CCertTemplateGeneralPage* pControlPage = new CCertTemplateGeneralPage(m_ahCertTemplates[0]);
  109. if(pControlPage)
  110. {
  111. pBasePage = pControlPage;
  112. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&pBasePage->m_psp);
  113. if (hPage == NULL)
  114. {
  115. delete (pControlPage);
  116. return E_UNEXPECTED;
  117. }
  118. lpfnAddPage(hPage, lParam);
  119. }
  120. return S_OK;
  121. }
  122. STDMETHODIMP CCertTypeShlExt::ReplacePage
  123. (
  124. IN UINT uPageID,
  125. IN LPFNADDPROPSHEETPAGE lpfnReplaceWith,
  126. IN LPARAM lParam
  127. )
  128. {
  129. return E_FAIL;
  130. }
  131. // IContextMenu methods
  132. STDMETHODIMP CCertTypeShlExt::GetCommandString
  133. (
  134. UINT_PTR idCmd,
  135. UINT uFlags,
  136. UINT *pwReserved,
  137. LPSTR pszName,
  138. UINT cchMax
  139. )
  140. {
  141. if((idCmd == m_uiEditId) && (m_uiEditId != 0))
  142. {
  143. if (uFlags == GCS_HELPTEXT)
  144. {
  145. LoadString(AfxGetResourceHandle( ), IDS_EDIT_HINT, (LPTSTR)pszName, cchMax);
  146. return S_OK;
  147. }
  148. }
  149. return E_NOTIMPL;
  150. }
  151. STDMETHODIMP CCertTypeShlExt::InvokeCommand
  152. (
  153. LPCMINVOKECOMMANDINFO lpici
  154. )
  155. {
  156. if (!HIWORD(lpici->lpVerb))
  157. {
  158. UINT idCmd = LOWORD(lpici->lpVerb);
  159. switch(idCmd)
  160. {
  161. case 0: // Edit
  162. InvokeCertTypeWizard(m_ahCertTemplates[0],
  163. lpici->hwnd);
  164. return S_OK;
  165. }
  166. }
  167. return E_NOTIMPL;
  168. }
  169. STDMETHODIMP CCertTypeShlExt::QueryContextMenu
  170. (
  171. HMENU hmenu,
  172. UINT indexMenu,
  173. UINT idCmdFirst,
  174. UINT idCmdLast,
  175. UINT uFlags
  176. )
  177. {
  178. CString szEdit;
  179. MENUITEMINFO mii;
  180. UINT idLastUsedCmd = idCmdFirst;
  181. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  182. ZeroMemory(&mii, sizeof(mii));
  183. if(IsCerttypeEditingAllowed())
  184. {
  185. mii.cbSize = sizeof(mii);
  186. mii.fMask = MIIM_TYPE | MIIM_ID;
  187. mii.fType = MFT_STRING;
  188. mii.wID = idCmdFirst;
  189. szEdit.LoadString(IDS_EDIT);
  190. mii.dwTypeData = (LPTSTR)(LPCTSTR)szEdit;
  191. mii.cch = szEdit.GetLength();
  192. // Add new menu items to the context menu. //
  193. ::InsertMenuItem(hmenu,
  194. indexMenu++,
  195. TRUE,
  196. &mii);
  197. }
  198. return ResultFromScode (MAKE_SCODE (SEVERITY_SUCCESS, 0,
  199. USHORT (idLastUsedCmd + 1)));
  200. }