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.

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