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.

372 lines
11 KiB

  1. /**************************************************************************
  2. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  3. ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  4. THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  5. PARTICULAR PURPOSE.
  6. Copyright 1998 Microsoft Corporation. All Rights Reserved.
  7. **************************************************************************/
  8. /**************************************************************************
  9. File: SampView.cpp
  10. Description: Contains DLLMain and standard OLE COM object creation stuff.
  11. **************************************************************************/
  12. /**************************************************************************
  13. #include statements
  14. **************************************************************************/
  15. #include "ShlView.h"
  16. #include "ClsFact.h"
  17. #include "ViewList.h"
  18. #include "Utility.h"
  19. #include <olectl.h>
  20. #include "ParseXML.h"
  21. /**************************************************************************
  22. GUID stuff
  23. **************************************************************************/
  24. //this part is only done once
  25. //if you need to use the GUID in another file, just include Guid.h
  26. #pragma data_seg(".text")
  27. #define INITGUID
  28. #include <initguid.h>
  29. #include <shlguid.h>
  30. #include "Guid.h"
  31. #pragma data_seg()
  32. /**************************************************************************
  33. private function prototypes
  34. **************************************************************************/
  35. extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID);
  36. /**************************************************************************
  37. global variables
  38. **************************************************************************/
  39. HINSTANCE g_hInst;
  40. UINT g_DllRefCount;
  41. HIMAGELIST g_himlLarge = NULL;
  42. HIMAGELIST g_himlSmall = NULL;
  43. TCHAR g_szStoragePath[MAX_PATH];
  44. TCHAR g_szExtTitle[TITLE_SIZE];
  45. const TCHAR c_szDataFile[] = TEXT("items.ini\0");
  46. const TCHAR c_szSection[] = TEXT("Items\0");
  47. int g_nColumn = INITIAL_COLUMN_SIZE;
  48. CViewList *g_pViewList;
  49. IXMLDocument *g_pXMLDoc = NULL;
  50. const TCHAR g_szXMLUrl[] = TEXT("http://a-yurip1/test/test.xml");
  51. /**************************************************************************
  52. DllMain
  53. **************************************************************************/
  54. extern "C" BOOL WINAPI DllMain( HINSTANCE hInstance,
  55. DWORD dwReason,
  56. LPVOID lpReserved)
  57. {
  58. HRESULT hr;
  59. PSTR pszErr = NULL;
  60. switch(dwReason)
  61. {
  62. case DLL_PROCESS_ATTACH:
  63. g_hInst = hInstance;
  64. g_DllRefCount = 0;
  65. // Open the sourse XML
  66. // For now we are using global XML object because we have only one file
  67. // In the future we have to associate the file with the folder and put the object in IDL
  68. if (g_pXMLDoc == NULL)
  69. {
  70. hr = GetSourceXML(&g_pXMLDoc, TEXT("http://a-yurip1/test/test.xml"));
  71. if (!SUCCEEDED(hr) || !g_pXMLDoc)
  72. {
  73. SAFERELEASE(g_pXMLDoc);
  74. return FALSE;
  75. }
  76. BSTR bstrVal;
  77. hr = g_pXMLDoc->get_version(&bstrVal);
  78. // Check if the version is correct ???????
  79. //
  80. SysFreeString(bstrVal);
  81. bstrVal = NULL;
  82. }
  83. GetGlobalSettings();
  84. //create the global image lists
  85. CreateImageLists();
  86. g_pViewList = new CViewList();
  87. break;
  88. case DLL_PROCESS_DETACH:
  89. SaveGlobalSettings();
  90. //destroy the global image lists
  91. DestroyImageLists();
  92. if(g_pViewList)
  93. delete g_pViewList;
  94. if (g_pXMLDoc)
  95. SAFERELEASE(g_pXMLDoc);
  96. break;
  97. }
  98. return TRUE;
  99. }
  100. /**************************************************************************
  101. DllCanUnloadNow
  102. **************************************************************************/
  103. STDAPI DllCanUnloadNow(VOID)
  104. {
  105. return (g_DllRefCount ? S_FALSE : S_OK);
  106. }
  107. /**************************************************************************
  108. DllGetClassObject
  109. **************************************************************************/
  110. STDAPI DllGetClassObject( REFCLSID rclsid,
  111. REFIID riid,
  112. LPVOID *ppReturn)
  113. {
  114. *ppReturn = NULL;
  115. //if we don't support this classid, return the proper error code
  116. if(!IsEqualCLSID(rclsid, CLSID_SampleNameSpace))
  117. return CLASS_E_CLASSNOTAVAILABLE;
  118. //create a CClassFactory object and check it for validity
  119. CClassFactory *pClassFactory = new CClassFactory();
  120. if(NULL == pClassFactory)
  121. return E_OUTOFMEMORY;
  122. //get the QueryInterface return for our return value
  123. HRESULT hResult = pClassFactory->QueryInterface(riid, ppReturn);
  124. //call Release to decrement the ref count - creating the object set it to one
  125. //and QueryInterface incremented it - since its being used externally (not by
  126. //us), we only want the ref count to be 1
  127. pClassFactory->Release();
  128. //return the result from QueryInterface
  129. return hResult;
  130. }
  131. /**************************************************************************
  132. DllRegisterServer
  133. **************************************************************************/
  134. typedef struct{
  135. HKEY hRootKey;
  136. LPTSTR lpszSubKey;
  137. LPTSTR lpszValueName;
  138. LPTSTR lpszData;
  139. }REGSTRUCT, *LPREGSTRUCT;
  140. STDAPI DllRegisterServer(VOID)
  141. {
  142. int i;
  143. HKEY hKey;
  144. LRESULT lResult;
  145. DWORD dwDisp;
  146. TCHAR szSubKey[MAX_PATH];
  147. TCHAR szCLSID[MAX_PATH];
  148. TCHAR szModule[MAX_PATH];
  149. LPWSTR pwsz;
  150. //get the CLSID in string form
  151. StringFromIID(CLSID_SampleNameSpace, &pwsz);
  152. if(pwsz)
  153. {
  154. WideCharToLocal(szCLSID, pwsz, ARRAYSIZE(szCLSID));
  155. //free the string
  156. LPMALLOC pMalloc;
  157. CoGetMalloc(1, &pMalloc);
  158. if(pMalloc)
  159. {
  160. pMalloc->Free(pwsz);
  161. pMalloc->Release();
  162. }
  163. }
  164. //get this DLL's path and file name
  165. GetModuleFileName(g_hInst, szModule, ARRAYSIZE(szModule));
  166. //register the CLSID entries
  167. REGSTRUCT ClsidEntries[] = { HKEY_CLASSES_ROOT, TEXT("CLSID\\%s"), NULL, g_szExtTitle,
  168. HKEY_CLASSES_ROOT, TEXT("CLSID\\%s\\InprocServer32"), NULL, TEXT("%s"),
  169. HKEY_CLASSES_ROOT, TEXT("CLSID\\%s\\InprocServer32"), TEXT("ThreadingModel"), TEXT("Apartment"),
  170. HKEY_CLASSES_ROOT, TEXT("CLSID\\%s\\DefaultIcon"), NULL, TEXT("%s,0"),
  171. NULL, NULL, NULL, NULL};
  172. for(i = 0; ClsidEntries[i].hRootKey; i++)
  173. {
  174. //Create the sub key string.
  175. wsprintf(szSubKey, ClsidEntries[i].lpszSubKey, szCLSID);
  176. lResult = RegCreateKeyEx( ClsidEntries[i].hRootKey,
  177. szSubKey,
  178. 0,
  179. NULL,
  180. REG_OPTION_NON_VOLATILE,
  181. KEY_WRITE,
  182. NULL,
  183. &hKey,
  184. &dwDisp);
  185. if(NOERROR == lResult)
  186. {
  187. TCHAR szData[MAX_PATH];
  188. //if necessary, create the value string
  189. wsprintf(szData, ClsidEntries[i].lpszData, szModule);
  190. lResult = RegSetValueEx( hKey,
  191. ClsidEntries[i].lpszValueName,
  192. 0,
  193. REG_SZ,
  194. (LPBYTE)szData,
  195. (lstrlen(szData) + 1) * sizeof(TCHAR));
  196. RegCloseKey(hKey);
  197. }
  198. else
  199. return SELFREG_E_CLASS;
  200. }
  201. //Register the default flags for the folder.
  202. wsprintf( szSubKey,
  203. TEXT("CLSID\\%s\\ShellFolder"),
  204. szCLSID);
  205. lResult = RegCreateKeyEx( HKEY_CLASSES_ROOT,
  206. szSubKey,
  207. 0,
  208. NULL,
  209. REG_OPTION_NON_VOLATILE,
  210. KEY_WRITE,
  211. NULL,
  212. &hKey,
  213. &dwDisp);
  214. if(NOERROR == lResult)
  215. {
  216. DWORD dwData = SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_BROWSABLE | SFGAO_DROPTARGET;
  217. lResult = RegSetValueEx( hKey,
  218. TEXT("Attributes"),
  219. 0,
  220. REG_BINARY,
  221. (LPBYTE)&dwData,
  222. sizeof(dwData));
  223. RegCloseKey(hKey);
  224. }
  225. else
  226. return SELFREG_E_CLASS;
  227. //Register the name space extension
  228. /*
  229. Create the sub key string. Change this from "...MyComputer..." to
  230. "...Desktop..." if desired.
  231. */
  232. wsprintf( szSubKey,
  233. TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MyComputer\\NameSpace\\%s"),
  234. //TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Desktop\\NameSpace\\%s"),
  235. szCLSID);
  236. lResult = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
  237. szSubKey,
  238. 0,
  239. NULL,
  240. REG_OPTION_NON_VOLATILE,
  241. KEY_WRITE,
  242. NULL,
  243. &hKey,
  244. &dwDisp);
  245. if(NOERROR == lResult)
  246. {
  247. TCHAR szData[MAX_PATH];
  248. //Create the value string.
  249. lstrcpy(szData, g_szExtTitle);
  250. lResult = RegSetValueEx( hKey,
  251. NULL,
  252. 0,
  253. REG_SZ,
  254. (LPBYTE)szData,
  255. (lstrlen(szData) + 1) * sizeof(TCHAR));
  256. RegCloseKey(hKey);
  257. }
  258. else
  259. return SELFREG_E_CLASS;
  260. //If running on NT, register the extension as approved.
  261. OSVERSIONINFO osvi;
  262. osvi.dwOSVersionInfoSize = sizeof(osvi);
  263. GetVersionEx(&osvi);
  264. if(VER_PLATFORM_WIN32_NT == osvi.dwPlatformId)
  265. {
  266. lstrcpy( szSubKey, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"));
  267. lResult = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
  268. szSubKey,
  269. 0,
  270. NULL,
  271. REG_OPTION_NON_VOLATILE,
  272. KEY_WRITE,
  273. NULL,
  274. &hKey,
  275. &dwDisp);
  276. if(NOERROR == lResult)
  277. {
  278. TCHAR szData[MAX_PATH];
  279. //Create the value string.
  280. lstrcpy(szData, g_szExtTitle);
  281. lResult = RegSetValueEx( hKey,
  282. szCLSID,
  283. 0,
  284. REG_SZ,
  285. (LPBYTE)szData,
  286. (lstrlen(szData) + 1) * sizeof(TCHAR));
  287. RegCloseKey(hKey);
  288. }
  289. else
  290. return SELFREG_E_CLASS;
  291. }
  292. return S_OK;
  293. }