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.

424 lines
15 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: C F P I D L . H
  7. //
  8. // Contents: ConFoldPidl structures, classes, and prototypes
  9. //
  10. // Author: jeffspr 11 Nov 1997
  11. //
  12. //----------------------------------------------------------------------------
  13. #pragma once
  14. #undef DBG_VALIDATE_PIDLS
  15. #ifdef DBG
  16. // #define DBG_VALIDATE_PIDLS 1
  17. #endif
  18. // #define VERYSTRICTCOMPILE
  19. // VERYSTRICTCOMPILE doesn't actually compile - However, it makes us check for things like using references
  20. // from places other than STL etc.
  21. // This defines the version number of the ConFoldPidl structure. When this
  22. // changes, we'll need to invalidate the entries.
  23. //
  24. enum CONFOLDPIDLTYPE
  25. {
  26. PIDL_TYPE_UNKNOWN = 0,
  27. PIDL_TYPE_V1 = 1,
  28. PIDL_TYPE_V2 = 2,
  29. PIDL_TYPE_98 = 98,
  30. PIDL_TYPE_FOLDER = 0xf01de
  31. };
  32. enum WIZARD
  33. {
  34. WIZARD_NOT_WIZARD = 0,
  35. WIZARD_MNC = 1,
  36. WIZARD_HNW = 2
  37. };
  38. // {44086B2D-BAA3-4fce-949F-53FF664C4AD8}
  39. DEFINE_GUID(GUID_MNC_WIZARD, 0x44086b2d, 0xbaa3, 0x4fce, 0x94, 0x9f, 0x53, 0xff, 0x66, 0x4c, 0x4a, 0xd8);
  40. // {44086B2E-BAA3-4fce-949F-53FF664C4AD8}
  41. DEFINE_GUID(GUID_HNW_WIZARD, 0x44086b2e, 0xbaa3, 0x4fce, 0x94, 0x9f, 0x53, 0xff, 0x66, 0x4c, 0x4a, 0xd8);
  42. class CConFoldEntry;
  43. class ConFoldPidlBase
  44. {
  45. public:
  46. WORD iCB;
  47. USHORT uLeadId;
  48. const DWORD dwVersion;
  49. USHORT uTrailId;
  50. WIZARD wizWizard; // 0 - not a wizard, 1 - MNC, 2 - HNW
  51. CLSID clsid;
  52. GUID guidId;
  53. DWORD dwCharacteristics;
  54. NETCON_MEDIATYPE ncm;
  55. NETCON_STATUS ncs;
  56. // Order of the rest of the non-static-sized data
  57. ULONG ulPersistBufPos;
  58. ULONG ulPersistBufSize;
  59. ULONG ulStrNamePos;
  60. ULONG ulStrNameSize;
  61. ULONG ulStrDeviceNamePos;
  62. ULONG ulStrDeviceNameSize;
  63. protected:
  64. ConFoldPidlBase(DWORD Version) : dwVersion(Version) {};
  65. };
  66. class ConFoldPidl_v1 : public ConFoldPidlBase // CONFOLDPIDLTYPE = PIDL_TYPE_V1
  67. {
  68. public:
  69. enum tagConstants
  70. {
  71. CONNECTIONS_FOLDER_IDL_VERSION = PIDL_TYPE_V1
  72. };
  73. BOOL IsPidlOfThisType() const throw();
  74. HRESULT ConvertToConFoldEntry(OUT CConFoldEntry& cfe) const;
  75. inline LPBYTE PbGetPersistBufPointer() { return reinterpret_cast<LPBYTE>(bData + ulPersistBufPos); }
  76. inline LPWSTR PszGetNamePointer() { return reinterpret_cast<LPWSTR>(bData + ulStrNamePos); }
  77. inline LPWSTR PszGetDeviceNamePointer() { return reinterpret_cast<LPWSTR>(bData + ulStrDeviceNamePos); }
  78. inline const BYTE * PbGetPersistBufPointer() const { return reinterpret_cast<const BYTE *>(bData + ulPersistBufPos); }
  79. inline LPCWSTR PszGetNamePointer() const { return reinterpret_cast<LPCWSTR>(bData + ulStrNamePos); }
  80. inline LPCWSTR PszGetDeviceNamePointer() const { return reinterpret_cast<LPCWSTR>(bData + ulStrDeviceNamePos); }
  81. // The rest of the non-static-sized data
  82. BYTE bData[1];
  83. ConFoldPidl_v1() : ConFoldPidlBase(CONNECTIONS_FOLDER_IDL_VERSION) {};
  84. };
  85. class ConFoldPidl_v2 : public ConFoldPidlBase // CONFOLDPIDLTYPE = PIDL_TYPE_V2
  86. {
  87. public:
  88. enum tagConstants
  89. {
  90. CONNECTIONS_FOLDER_IDL_VERSION = PIDL_TYPE_V2
  91. };
  92. ConFoldPidl_v2() : ConFoldPidlBase(CONNECTIONS_FOLDER_IDL_VERSION) {};
  93. BOOL IsPidlOfThisType() const throw();
  94. HRESULT ConvertToConFoldEntry(OUT CConFoldEntry& cfe) const;
  95. inline LPBYTE PbGetPersistBufPointer() { return reinterpret_cast<LPBYTE>(bData + ulPersistBufPos); }
  96. inline LPWSTR PszGetNamePointer() { return reinterpret_cast<LPWSTR>(bData + ulStrNamePos); }
  97. inline LPWSTR PszGetDeviceNamePointer() { return reinterpret_cast<LPWSTR>(bData + ulStrDeviceNamePos); }
  98. inline LPWSTR PszGetPhoneOrHostAddressPointer() { return reinterpret_cast<LPWSTR>(bData + ulStrPhoneOrHostAddressPos); }
  99. inline const BYTE * PbGetPersistBufPointer() const { return reinterpret_cast<const BYTE *>(bData + ulPersistBufPos); }
  100. inline LPCWSTR PszGetNamePointer() const { return reinterpret_cast<LPCWSTR>(bData + ulStrNamePos); }
  101. inline LPCWSTR PszGetDeviceNamePointer() const { return reinterpret_cast<LPCWSTR>(bData + ulStrDeviceNamePos); }
  102. inline LPCWSTR PszGetPhoneOrHostAddressPointer() const { return reinterpret_cast<LPCWSTR>(bData + ulStrPhoneOrHostAddressPos); }
  103. // PIDL version 2 members
  104. NETCON_SUBMEDIATYPE ncsm;
  105. ULONG ulStrPhoneOrHostAddressPos;
  106. ULONG ulStrPhoneOrHostAddressSize;
  107. // The rest of the non-static-sized data
  108. BYTE bData[1];
  109. };
  110. // This structure is used as the LPITEMIDLIST that
  111. // the shell uses to identify objects in a folder. The
  112. // first two bytes are required to indicate the size,
  113. // the rest of the data is opaque to the shell.
  114. struct ConFoldPidl98 // CONFOLDPIDLTYPE = PIDL_TYPE_98
  115. {
  116. enum tagConstants
  117. {
  118. CONNECTIONS_FOLDER_IDL_VERSION = PIDL_TYPE_98
  119. };
  120. BOOL IsPidlOfThisType(OUT BOOL * pReserved = NULL) const throw();
  121. HRESULT ConvertToConFoldEntry(OUT CConFoldEntry& cfe) const { AssertSz(FALSE, "I don't know how to do that"); return E_UNEXPECTED; };;
  122. USHORT cbSize; // Size of this struct
  123. UINT uFlags; // One of SOF_ values
  124. int nIconIndex; // Icon index (in resource)
  125. struct ConFoldPidl98 * psoNext;
  126. char szaName[1]; // Display name
  127. };
  128. class ConFoldPidlFolder // CONFOLDPIDLTYPE = PIDL_TYPE_FOLDER
  129. {
  130. public:
  131. enum tagConstants
  132. {
  133. CONNECTIONS_FOLDER_IDL_VERSION = PIDL_TYPE_FOLDER
  134. };
  135. inline LPBYTE PbGetPersistBufPointer() { AssertSz(FALSE, "Folders dont have this info"); return NULL; }
  136. inline LPWSTR PszGetNamePointer() { AssertSz(FALSE, "Folders dont have this info"); return NULL; }
  137. inline LPWSTR PszGetDeviceNamePointer() { AssertSz(FALSE, "Folders dont have this info"); return NULL; }
  138. ConFoldPidlFolder() {}
  139. BOOL IsPidlOfThisType() const throw();
  140. // This is an internal structure used for debugging. Do NOT rely on this.
  141. WORD dwLength; // Should be 0x14 for Whistler
  142. BYTE dwId; // Should be 0x1f for Whistler
  143. BYTE bOrder; // used internall by shell
  144. CLSID clsid;
  145. HRESULT ConvertToConFoldEntry(OUT CConFoldEntry& cfe) const { AssertSz(FALSE, "I don't do that"); return E_UNEXPECTED; };
  146. };
  147. template <class T>
  148. class CPConFoldPidl
  149. {
  150. public:
  151. enum tagConstants
  152. {
  153. PIDL_VERSION = T::CONNECTIONS_FOLDER_IDL_VERSION
  154. };
  155. CPConFoldPidl();
  156. CPConFoldPidl(IN const CPConFoldPidl<T>& PConFoldPidl) throw (HRESULT); // Copy constructor
  157. ~CPConFoldPidl();
  158. CPConFoldPidl<T>& operator =(IN const CPConFoldPidl<T>& PConFoldPidl) throw (HRESULT);
  159. T& operator *();
  160. inline UNALIGNED T* operator->();
  161. inline const UNALIGNED T* operator->() const;
  162. HRESULT ILCreate(IN const DWORD dwSize);
  163. HRESULT ILClone(IN const CPConFoldPidl<T>& PConFoldPidl);
  164. HRESULT SHAlloc(IN const SIZE_T cb);
  165. HRESULT Clear();
  166. HRESULT InitializeFromItemIDList(IN LPCITEMIDLIST pItemIdList);
  167. LPITEMIDLIST Detach();
  168. LPITEMIDLIST TearOffItemIdList() const;
  169. inline LPCITEMIDLIST GetItemIdList() const;
  170. #ifdef DBG_VALIDATE_PIDLS
  171. inline BOOL IsValidConFoldPIDL() const;
  172. #endif
  173. inline BOOL empty() const;
  174. inline HRESULT ConvertToConFoldEntry(OUT CConFoldEntry& cfe) const;
  175. inline HRESULT Swop(IN OUT CPConFoldPidl<T>& cfe);
  176. private:
  177. HRESULT FreePIDLIfRequired();
  178. #ifdef VERYSTRICTCOMPILE
  179. CPConFoldPidl<T>* operator &();
  180. #endif
  181. UNALIGNED T* m_pConFoldPidl;
  182. friend HRESULT ConvertToPidl( OUT T& pidl);
  183. };
  184. //typedef ConFoldPidl CONFOLDPIDL;
  185. typedef struct ConFoldPidl98 CONFOLDPIDL98;
  186. typedef CPConFoldPidl<ConFoldPidl_v2> PCONFOLDPIDL;
  187. typedef CPConFoldPidl<ConFoldPidlFolder> PCONFOLDPIDLFOLDER;
  188. typedef CPConFoldPidl<ConFoldPidl98> PCONFOLDPIDL98;
  189. typedef vector<PCONFOLDPIDL> PCONFOLDPIDLVEC;
  190. #define PCONFOLDPIDLDEFINED
  191. // One of our pidls must be at least this size, it will likely be bigger.
  192. //
  193. #define CBCONFOLDPIDLV1_MIN sizeof(ConFoldPidl_v1)
  194. #define CBCONFOLDPIDLV1_MAX 2048
  195. #define CBCONFOLDPIDLV2_MIN sizeof(ConFoldPidl_v2)
  196. #define CBCONFOLDPIDLV2_MAX 2048
  197. // More versioning info. This will help me identify PIDLs as being mine
  198. //
  199. #define CONFOLDPIDL_LEADID 0x4EFF
  200. #define CONFOLDPIDL_TRAILID 0x5EFF
  201. // Define the Types of data which can changed via CConFoldEntry::HrUpdateData
  202. //
  203. #define CCFE_CHANGE_MEDIATYPE 0x0001
  204. #define CCFE_CHANGE_STATUS 0x0002
  205. #define CCFE_CHANGE_CHARACTERISTICS 0x0004
  206. #define CCFE_CHANGE_NAME 0x0008
  207. #define CCFE_CHANGE_DEVICENAME 0x0010
  208. #define CCFE_CHANGE_PHONEORHOSTADDRESS 0x0020
  209. #define CCFE_CHANGE_SUBMEDIATYPE 0x0040
  210. #define CBCONFOLDPIDL98_MIN sizeof(CONFOLDPIDL98)
  211. #define CBCONFOLDPIDL98_MAX 2048
  212. #define TAKEOWNERSHIP
  213. #define SHALLOCATED
  214. // ConFoldPidl98 flags
  215. //
  216. #define SOF_REMOTE 0x0000 // Remote connectoid
  217. #define SOF_NEWREMOTE 0x0001 // New connection
  218. #define SOF_MEMBER 0x0002 // Subobject is part of object space
  219. // ****************************************************************************
  220. BOOL fIsConnectedStatus(IN const NETCON_STATUS ncs);
  221. class CConFoldEntry : CNetCfgDebug<CConFoldEntry>
  222. {
  223. public:
  224. CConFoldEntry() throw();
  225. ~CConFoldEntry() throw();
  226. private:
  227. explicit CConFoldEntry(IN const CConFoldEntry& ConFoldEntry) throw(); // NULL on failure
  228. WIZARD m_wizWizard;
  229. NETCON_MEDIATYPE m_ncm;
  230. NETCON_SUBMEDIATYPE m_ncsm;
  231. NETCON_STATUS m_ncs;
  232. CLSID m_clsid;
  233. GUID m_guidId;
  234. DWORD m_dwCharacteristics;
  235. PWSTR m_pszName;
  236. PWSTR m_pszDeviceName;
  237. BYTE * m_pbPersistData;
  238. ULONG m_ulPersistSize;
  239. PWSTR m_pszPhoneOrHostAddress;
  240. const CConFoldEntry* operator &() const;
  241. mutable BOOL m_bDirty;
  242. mutable CPConFoldPidl<ConFoldPidl_v1> m_CachedV1Pidl;
  243. mutable CPConFoldPidl<ConFoldPidl_v2> m_CachedV2Pidl;
  244. public:
  245. inline const DWORD GetCharacteristics() const throw();
  246. HRESULT SetCharacteristics(IN const DWORD dwCharacteristics);
  247. inline const GUID GetGuidID() const throw();
  248. HRESULT SetGuidID(IN const GUID guidId);
  249. inline const CLSID GetCLSID() const throw();
  250. HRESULT SetCLSID(IN const CLSID clsid);
  251. inline PCWSTR GetName() const throw();
  252. HRESULT SetPName(IN TAKEOWNERSHIP SHALLOCATED PWSTR pszName);
  253. HRESULT SetName(IN LPCWSTR pszName);
  254. inline PCWSTR GetDeviceName() const throw();
  255. HRESULT SetPDeviceName(IN TAKEOWNERSHIP SHALLOCATED PWSTR pszDeviceName);
  256. HRESULT SetDeviceName(IN LPCWSTR pszDeviceName);
  257. inline PCWSTR GetPhoneOrHostAddress() const throw();
  258. HRESULT SetPPhoneOrHostAddress(IN TAKEOWNERSHIP SHALLOCATED PWSTR pszPhoneOrHostAddress);
  259. HRESULT SetPhoneOrHostAddress(IN LPCWSTR pszPhoneOrHostAddress);
  260. inline const NETCON_STATUS GetNetConStatus() const throw();
  261. HRESULT SetNetConStatus(IN const NETCON_STATUS);
  262. inline const BOOL IsConnected() const throw();
  263. inline const NETCON_MEDIATYPE GetNetConMediaType() const throw();
  264. HRESULT SetNetConMediaType(IN const NETCON_MEDIATYPE);
  265. inline const NETCON_SUBMEDIATYPE GetNetConSubMediaType() const throw();
  266. HRESULT SetNetConSubMediaType(IN const NETCON_SUBMEDIATYPE);
  267. inline const WIZARD GetWizard() const throw();
  268. HRESULT SetWizard(IN const WIZARD);
  269. inline const BYTE * GetPersistData() const throw();
  270. inline const ULONG GetPersistSize() const throw();
  271. HRESULT SetPersistData(IN BYTE* TAKEOWNERSHIP SHALLOCATED pbPersistData, IN const ULONG ulPersistSize);
  272. public:
  273. BOOL empty() const throw();
  274. void clear() throw();
  275. CConFoldEntry& operator =(IN const CConFoldEntry& ConFoldEntry); // NULL on failure
  276. HRESULT InitializeFromItemIdList(IN LPCITEMIDLIST lpItemIdList);
  277. LPITEMIDLIST TearOffItemIdList() const throw();
  278. HRESULT ConvertToPidl( OUT CPConFoldPidl<ConFoldPidl_v1>& pidl) const;
  279. HRESULT ConvertToPidl( OUT CPConFoldPidl<ConFoldPidl_v2>& pidl) const;
  280. HRESULT HrInitData(
  281. IN const WIZARD wizWizard,
  282. IN const NETCON_MEDIATYPE ncm,
  283. IN const NETCON_SUBMEDIATYPE ncsm,
  284. IN const NETCON_STATUS ncs,
  285. IN const CLSID * pclsid,
  286. IN LPCGUID pguidId,
  287. IN const DWORD dwCharacteristics,
  288. IN const BYTE * pbPersistData,
  289. IN const ULONG ulPersistSize,
  290. IN LPCWSTR pszName,
  291. IN LPCWSTR pszDeviceName,
  292. IN LPCWSTR pszPhoneOrHostAddress);
  293. HRESULT UpdateData(IN const DWORD dwChangeFlags,
  294. IN const NETCON_MEDIATYPE,
  295. IN const NETCON_SUBMEDIATYPE,
  296. IN const NETCON_STATUS,
  297. IN const DWORD dwChar,
  298. IN PCWSTR pszName,
  299. IN PCWSTR pszDeviceName,
  300. IN PCWSTR pszPhoneOrHostAddress);
  301. HRESULT HrGetNetCon(IN REFIID riid, OUT VOID** ppv) const;
  302. HRESULT HrDupFolderEntry(IN const CConFoldEntry& pccfe);
  303. BOOL FShouldHaveTrayIconDisplayed() const throw();
  304. #ifdef NCDBGEXT
  305. IMPORT_NCDBG_FRIENDS
  306. #endif
  307. };
  308. #define PCONFOLDENTRY_DEFINED
  309. HRESULT PConfoldPidlVecFromItemIdListArray(
  310. IN LPCITEMIDLIST * apidl,
  311. IN const DWORD dwPidlCount,
  312. OUT PCONFOLDPIDLVEC& vecConfoldPidl);
  313. HRESULT HrNetConFromPidl(
  314. IN const PCONFOLDPIDL & pidl,
  315. OUT INetConnection ** ppNetCon);
  316. HRESULT HrCreateConFoldPidl(
  317. IN const WIZARD wizWizard,
  318. IN INetConnection * pNetCon,
  319. OUT PCONFOLDPIDL & ppidl);
  320. HRESULT HrCreateConFoldPidl(
  321. IN const NETCON_PROPERTIES_EX& PropsEx,
  322. OUT PCONFOLDPIDL & ppidl);
  323. HRESULT HrCreateConFoldPidlInternal(
  324. IN const NETCON_PROPERTIES * pProps,
  325. IN const BYTE * pbBuf,
  326. IN ULONG ulBufSize,
  327. IN LPCWSTR szPhoneOrHostAddress,
  328. OUT PCONFOLDPIDL & ppidl);
  329. #ifdef DBG_VALIDATE_PIDLS
  330. BOOL IsValidPIDL(IN LPCITEMIDLIST pidl) throw();
  331. #endif
  332. CONFOLDPIDLTYPE GetPidlType(IN LPCITEMIDLIST pidl) throw();
  333. typedef CConFoldEntry CONFOLDENTRY;
  334. // ****************************************************************************