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.

261 lines
8.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: common.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _COMMON_ADSIEDIT_H
  11. #define _COMMON_ADSIEDIT_H
  12. #include <shfusion.h>
  13. class CConnectionData;
  14. class CCredentialObject;
  15. //////////////////////////////////////////////
  16. // TODO: use correct letter case for a variable (vs. MACRO style)
  17. const unsigned int MAX_PASSWORD_LENGTH = 127; // not counting NULL terminator
  18. //////////////////////////////////////////////
  19. // Global API
  20. HRESULT OpenObjectWithCredentials(
  21. CConnectionData* pConnectData,
  22. const BOOL bUseCredentials,
  23. LPCWSTR lpszPath,
  24. const IID& iid,
  25. LPVOID* ppObject,
  26. HWND hWnd,
  27. HRESULT& hResult
  28. );
  29. HRESULT OpenObjectWithCredentials(
  30. CCredentialObject* pCredObject,
  31. LPCWSTR lpszPath,
  32. const IID& iid,
  33. LPVOID* ppObject
  34. );
  35. HRESULT CALLBACK BindingCallbackFunction(LPCWSTR lpszPathName,
  36. DWORD dwReserved,
  37. REFIID riid,
  38. void FAR * FAR * ppObject,
  39. LPARAM lParam);
  40. //////////////////////////////////////////////////////////////////////////
  41. // Commonly used utilities
  42. //
  43. inline void CopyStringList(CStringList *dest, const CStringList *src)
  44. {
  45. dest->RemoveAll();
  46. dest->AddTail(const_cast<CStringList*>(src));
  47. }
  48. HRESULT VariantToStringList( VARIANT& refvar, CStringList& refstringlist);
  49. HRESULT StringListToVariant( VARIANT& refvar, const CStringList& refstringlist);
  50. VARTYPE VariantTypeFromSyntax(LPCWSTR lpszProp );
  51. HRESULT GetItemFromRootDSE(LPCWSTR lpszRootDSEItem, CString& sItem, CConnectionData* pConnectData);
  52. HRESULT GetRootDSEObject(CConnectionData* pConnectData, IADs** ppDirObject);
  53. ///////////////////////////////////////////////////////////////////////////
  54. // Formats Error Messages
  55. //
  56. BOOL GetErrorMessage(HRESULT hr, CString& szErrorString, BOOL bTryADsIErrors = TRUE);
  57. ///////////////////////////////////////////////////////////////////////////
  58. // Converts ADSTYPE to/from String
  59. //
  60. void GetStringFromADsValue(const PADSVALUE pADsValue, CString& szValue, DWORD dwMaxCharCount = 0);
  61. void GetStringFromADs(const ADS_ATTR_INFO* pInfo, CStringList& sList, DWORD dwMaxCharCount = 0);
  62. ADSTYPE GetADsTypeFromString(LPCWSTR lps, CString& szSyntax);
  63. CString GetStringValueFromSystemTime(const SYSTEMTIME* pTime);
  64. ////////////////////////////////////////////////////////////////////////////
  65. // type conversions
  66. //
  67. void wtoli(LPCWSTR lpsz, LARGE_INTEGER& liOut);
  68. void litow(LARGE_INTEGER& li, CString& sResult);
  69. void ultow(ULONG ul, CString& sResult);
  70. ///////////////////////////////////////////////////////////////////////////
  71. // IO to/from Streams
  72. //
  73. HRESULT SaveStringToStream(IStream* pStm, const CString& sString);
  74. HRESULT SaveStringListToStream(IStream* pStm, CStringList& sList);
  75. HRESULT LoadStringFromStream(IStream* pStm, CString& sString);
  76. HRESULT LoadStringListFromStream(IStream* pStm, CStringList& sList);
  77. ////////////////////////////////////////////////////////////////////////////
  78. // Message Boxes
  79. int ADSIEditMessageBox(LPCTSTR lpszText, UINT nType);
  80. int ADSIEditMessageBox(UINT nIDPrompt, UINT nType);
  81. void ADSIEditErrorMessage(PCWSTR pszMessage);
  82. void ADSIEditErrorMessage(HRESULT hr);
  83. void ADSIEditErrorMessage(HRESULT hr, UINT nIDPrompt, UINT nType);
  84. ///////////////////////////////////////////////////////////////////////////
  85. // Other utils
  86. BOOL LoadStringsToComboBox(HINSTANCE hInstance, CComboBox* pCombo,
  87. UINT nStringID, UINT nMaxLen, UINT nMaxAddCount);
  88. void ParseNewLineSeparatedString(LPWSTR lpsz, LPWSTR* lpszArr, int* pnArrEntries);
  89. void LoadStringArrayFromResource(LPWSTR* lpszArr,
  90. UINT* nStringIDs,
  91. int nArrEntries,
  92. int* pnSuccessEntries);
  93. /////////////////////////////////////////////////////////////////////////////
  94. #define ByteOffset(base, offset) (((LPBYTE)base)+offset)
  95. void GetStringArrayFromStringList(CStringList& sList, LPWSTR** ppStrArr, UINT* nCount);
  96. //////////////////////////////////////////////////////////////////////////////
  97. // UI helper classes
  98. // Fwd declaration
  99. class CByteArrayDisplay;
  100. #define BYTE_ARRAY_DISPLAY_HEX 0x00000001
  101. #define BYTE_ARRAY_DISPLAY_DEC 0x00000002
  102. #define BYTE_ARRAY_DISPLAY_BIN 0x00000004
  103. #define BYTE_ARRAY_DISPLAY_OCT 0x00000008
  104. class CByteArrayComboBox : public CComboBox
  105. {
  106. public:
  107. BOOL Initialize(CByteArrayDisplay* pDisplay, DWORD dwDisplayFlags);
  108. DWORD GetCurrentDisplay();
  109. void SetCurrentDisplay(DWORD dwCurrentDisplayFlag);
  110. protected:
  111. afx_msg void OnSelChange();
  112. private:
  113. CByteArrayDisplay* m_pDisplay;
  114. DECLARE_MESSAGE_MAP()
  115. };
  116. class CByteArrayEdit : public CEdit
  117. {
  118. public:
  119. CByteArrayEdit();
  120. ~CByteArrayEdit();
  121. BOOL Initialize(CByteArrayDisplay* pDisplay);
  122. DWORD GetLength();
  123. BYTE* GetDataPtr();
  124. DWORD GetDataCopy(BYTE** ppData);
  125. void SetData(BYTE* pData, DWORD dwLength);
  126. void OnChangeDisplay();
  127. afx_msg void OnChange();
  128. private:
  129. CByteArrayDisplay* m_pDisplay;
  130. BYTE* m_pData;
  131. DWORD m_dwLength;
  132. DECLARE_MESSAGE_MAP()
  133. };
  134. class CByteArrayDisplay
  135. {
  136. public:
  137. CByteArrayDisplay()
  138. : m_dwPreviousDisplay(0),
  139. m_dwCurrentDisplay(0),
  140. m_dwMaxSizeBytes(0),
  141. m_nMaxSizeMessage(0)
  142. {}
  143. ~CByteArrayDisplay() {}
  144. BOOL Initialize(UINT nEditCtrl,
  145. UINT nComboCtrl,
  146. DWORD dwDisplayFlags,
  147. DWORD dwDefaultDisplay,
  148. CWnd* pParent,
  149. DWORD dwMaxSizeBytes,
  150. UINT nMaxSizeMessage);
  151. void ClearData();
  152. void SetData(BYTE* pData, DWORD dwLength);
  153. DWORD GetData(BYTE** ppData);
  154. void OnEditChange();
  155. void OnTypeChange(DWORD dwCurrentDisplayFlag);
  156. DWORD GetCurrentDisplay() { return m_dwCurrentDisplay; }
  157. void SetCurrentDisplay(DWORD dwCurrentDisplay);
  158. DWORD GetPreviousDisplay() { return m_dwPreviousDisplay; }
  159. private:
  160. CByteArrayEdit m_edit;
  161. CByteArrayComboBox m_combo;
  162. DWORD m_dwPreviousDisplay;
  163. DWORD m_dwCurrentDisplay;
  164. DWORD m_dwMaxSizeBytes; // The maximum number of bytes that will be shown in the edit box
  165. UINT m_nMaxSizeMessage; // The message that is put in the edit box when the max size is reached
  166. };
  167. ////////////////////////////////////////////////////////////////////////////////
  168. // String to byte array conversion routines
  169. HRESULT HexStringToByteArray_0x(PCWSTR pszHexString, BYTE** ppByte, DWORD& nCount);
  170. DWORD HexStringToByteArray(PCWSTR pszHexString, BYTE** ppByte);
  171. void ByteArrayToHexString(BYTE* pByte, DWORD dwLength, CString& szHexString);
  172. DWORD OctalStringToByteArray(PCWSTR pszHexString, BYTE** ppByte);
  173. void ByteArrayToOctalString(BYTE* pByte, DWORD dwLength, CString& szHexString);
  174. DWORD DecimalStringToByteArray(PCWSTR pszDecString, BYTE** ppByte);
  175. void ByteArrayToDecimalString(BYTE* pByte, DWORD dwLength, CString& szDecString);
  176. DWORD BinaryStringToByteArray(PCWSTR pszBinString, BYTE** ppByte);
  177. void ByteArrayToBinaryString(BYTE* pByte, DWORD dwLength, CString& szBinString);
  178. /////////////////////////////////////////////////////////////////////////////////
  179. BOOL LoadFileAsByteArray(PCWSTR pszPath, LPBYTE* ppByteArray, DWORD* pdwSize);
  180. /////////////////////////////////////////////////////////////////////////////////
  181. BOOL ConvertToFixedPitchFont(HWND hwnd);
  182. ////////////////////////////////////////////////////////////////////////////////////
  183. // Theme support
  184. class CThemeContextActivator
  185. {
  186. public:
  187. CThemeContextActivator() : m_ulActivationCookie(0)
  188. { SHActivateContext (&m_ulActivationCookie); }
  189. ~CThemeContextActivator()
  190. { SHDeactivateContext (m_ulActivationCookie); }
  191. private:
  192. ULONG_PTR m_ulActivationCookie;
  193. };
  194. #ifdef UNICODE
  195. #define PROPSHEETPAGE_V3 PROPSHEETPAGEW_V3
  196. #else
  197. #define PROPSHEETPAGE_V3 PROPSHEETPAGEA_V3
  198. #endif
  199. HPROPSHEETPAGE MyCreatePropertySheetPage(AFX_OLDPROPSHEETPAGE* psp);
  200. #endif _COMMON_ADSIEDIT_H