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.

2042 lines
60 KiB

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #ifndef __AFX_H__
  11. #define __AFX_H__
  12. #ifndef __cplusplus
  13. #error MFC requires C++ compilation (use a .cpp suffix)
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. #ifdef _AFX_MINREBUILD
  17. #pragma component(minrebuild, off)
  18. #endif
  19. #ifndef _AFX_FULLTYPEINFO
  20. #pragma component(mintypeinfo, on)
  21. #endif
  22. #include <afxver_.h> // Target version control
  23. #ifndef _AFX_NOFORCE_LIBS
  24. /////////////////////////////////////////////////////////////////////////////
  25. // Win32 libraries
  26. #ifndef _AFXDLL
  27. #ifndef _UNICODE
  28. #ifdef _DEBUG
  29. #pragma comment(lib, "nafxcwd.lib")
  30. #else
  31. #pragma comment(lib, "nafxcw.lib")
  32. #endif
  33. #else
  34. #ifdef _DEBUG
  35. #pragma comment(lib, "uafxcwd.lib")
  36. #else
  37. #pragma comment(lib, "uafxcw.lib")
  38. #endif
  39. #endif
  40. #else
  41. #ifndef _UNICODE
  42. #ifdef _DEBUG
  43. #pragma comment(lib, "mfc42d.lib")
  44. #pragma comment(lib, "mfcs42d.lib")
  45. #else
  46. #pragma comment(lib, "mfc42.lib")
  47. #pragma comment(lib, "mfcs42.lib")
  48. #endif
  49. #else
  50. #ifdef _DEBUG
  51. #pragma comment(lib, "mfc42ud.lib")
  52. #pragma comment(lib, "mfcs42ud.lib")
  53. #else
  54. #pragma comment(lib, "mfc42u.lib")
  55. #pragma comment(lib, "mfcs42u.lib")
  56. #endif
  57. #endif
  58. #endif
  59. #ifdef _DLL
  60. #if !defined(_AFX_NO_DEBUG_CRT) && defined(_DEBUG)
  61. #pragma comment(lib, "msvcrtd.lib")
  62. #else
  63. #pragma comment(lib, "msvcrt.lib")
  64. #endif
  65. #else
  66. #ifdef _MT
  67. #if !defined(_AFX_NO_DEBUG_CRT) && defined(_DEBUG)
  68. #pragma comment(lib, "libcmtd.lib")
  69. #else
  70. #pragma comment(lib, "libcmt.lib")
  71. #endif
  72. #else
  73. #if !defined(_AFX_NO_DEBUG_CRT) && defined(_DEBUG)
  74. #pragma comment(lib, "libcd.lib")
  75. #else
  76. #pragma comment(lib, "libc.lib")
  77. #endif
  78. #endif
  79. #endif
  80. #pragma comment(lib, "kernel32.lib")
  81. #pragma comment(lib, "user32.lib")
  82. #pragma comment(lib, "gdi32.lib")
  83. #pragma comment(lib, "comdlg32.lib")
  84. #pragma comment(lib, "winspool.lib")
  85. #pragma comment(lib, "advapi32.lib")
  86. #pragma comment(lib, "shell32.lib")
  87. #pragma comment(lib, "comctl32.lib")
  88. // force inclusion of NOLIB.OBJ for /disallowlib directives
  89. #pragma comment(linker, "/include:__afxForceEXCLUDE")
  90. // force inclusion of DLLMODUL.OBJ for _USRDLL
  91. #ifdef _USRDLL
  92. #pragma comment(linker, "/include:__afxForceUSRDLL")
  93. #endif
  94. // force inclusion of STDAFX.OBJ for precompiled types
  95. #ifdef _AFXDLL
  96. #pragma comment(linker, "/include:__afxForceSTDAFX")
  97. #endif
  98. #endif //!_AFX_NOFORCE_LIBS
  99. /////////////////////////////////////////////////////////////////////////////
  100. // Classes declared in this file
  101. // in addition to standard primitive data types and various helper macros
  102. struct CRuntimeClass; // object type information
  103. class CObject; // the root of all objects classes
  104. class CException; // the root of all exceptions
  105. class CArchiveException; // archive exception
  106. class CFileException; // file exception
  107. class CSimpleException;
  108. class CMemoryException; // out-of-memory exception
  109. class CNotSupportedException; // feature not supported exception
  110. class CFile; // raw binary file
  111. class CStdioFile; // buffered stdio text/binary file
  112. class CMemFile; // memory based file
  113. // Non CObject classes
  114. class CString; // growable string type
  115. class CTimeSpan; // time/date difference
  116. class CTime; // absolute time/date
  117. struct CFileStatus; // file status information
  118. struct CMemoryState; // diagnostic memory support
  119. class CArchive; // object persistence tool
  120. class CDumpContext; // object diagnostic dumping
  121. /////////////////////////////////////////////////////////////////////////////
  122. // Other includes from standard "C" runtimes
  123. #ifndef _INC_STRING
  124. #include <string.h>
  125. #endif
  126. #ifndef _INC_STDIO
  127. #include <stdio.h>
  128. #endif
  129. #ifndef _INC_STDLIB
  130. #include <stdlib.h>
  131. #endif
  132. #ifndef _INC_TIME
  133. #include <time.h>
  134. #endif
  135. #ifndef _INC_LIMITS
  136. #include <limits.h>
  137. #endif
  138. #ifndef _INC_STDDEF
  139. #include <stddef.h>
  140. #endif
  141. #ifndef _INC_STDARG
  142. #include <stdarg.h>
  143. #endif
  144. #ifndef _AFX_NO_DEBUG_CRT
  145. #ifndef _INC_CRTDBG
  146. #include <crtdbg.h>
  147. #endif
  148. #endif // _AFX_NO_DEBUG_CRT
  149. #ifdef _AFX_OLD_EXCEPTIONS
  150. // use setjmp and helper functions instead of C++ keywords
  151. #ifndef _INC_SETJMP
  152. #pragma warning(disable: 4611)
  153. #include <setjmp.h>
  154. #endif
  155. #endif
  156. #ifdef _AFX_PACKING
  157. #pragma pack(push, _AFX_PACKING)
  158. #endif
  159. /////////////////////////////////////////////////////////////////////////////
  160. // Basic types
  161. // abstract iteration position
  162. struct __POSITION { };
  163. typedef __POSITION* POSITION;
  164. struct _AFX_DOUBLE { BYTE doubleBits[sizeof(double)]; };
  165. struct _AFX_FLOAT { BYTE floatBits[sizeof(float)]; };
  166. // Standard constants
  167. #undef FALSE
  168. #undef TRUE
  169. #undef NULL
  170. #define FALSE 0
  171. #define TRUE 1
  172. #define NULL 0
  173. /////////////////////////////////////////////////////////////////////////////
  174. // Diagnostic support
  175. #ifdef _DEBUG
  176. BOOL AFXAPI AfxAssertFailedLine(LPCSTR lpszFileName, int nLine);
  177. void AFX_CDECL AfxTrace(LPCTSTR lpszFormat, ...);
  178. // Note: file names are still ANSI strings (filenames rarely need UNICODE)
  179. void AFXAPI AfxAssertValidObject(const CObject* pOb,
  180. LPCSTR lpszFileName, int nLine);
  181. void AFXAPI AfxDump(const CObject* pOb); // Dump an object from CodeView
  182. #define TRACE ::AfxTrace
  183. #define THIS_FILE __FILE__
  184. #define ASSERT(f) \
  185. do \
  186. { \
  187. if (!(f) && AfxAssertFailedLine(THIS_FILE, __LINE__)) \
  188. AfxDebugBreak(); \
  189. } while (0) \
  190. #define VERIFY(f) ASSERT(f)
  191. #define ASSERT_VALID(pOb) (::AfxAssertValidObject(pOb, THIS_FILE, __LINE__))
  192. #define DEBUG_ONLY(f) (f)
  193. // The following trace macros are provided for backward compatiblity
  194. // (they also take a fixed number of parameters which provides
  195. // some amount of extra error checking)
  196. #define TRACE0(sz) ::AfxTrace(_T("%s"), _T(sz))
  197. #define TRACE1(sz, p1) ::AfxTrace(_T(sz), p1)
  198. #define TRACE2(sz, p1, p2) ::AfxTrace(_T(sz), p1, p2)
  199. #define TRACE3(sz, p1, p2, p3) ::AfxTrace(_T(sz), p1, p2, p3)
  200. // These AFX_DUMP macros also provided for backward compatibility
  201. #define AFX_DUMP0(dc, sz) dc << _T(sz)
  202. #define AFX_DUMP1(dc, sz, p1) dc << _T(sz) << p1
  203. #else // _DEBUG
  204. #define ASSERT(f) ((void)0)
  205. #define VERIFY(f) ((void)(f))
  206. #define ASSERT_VALID(pOb) ((void)0)
  207. #define DEBUG_ONLY(f) ((void)0)
  208. inline void AFX_CDECL AfxTrace(LPCTSTR, ...) { }
  209. #define TRACE 1 ? (void)0 : ::AfxTrace
  210. #define TRACE0(sz)
  211. #define TRACE1(sz, p1)
  212. #define TRACE2(sz, p1, p2)
  213. #define TRACE3(sz, p1, p2, p3)
  214. #endif // !_DEBUG
  215. #define ASSERT_POINTER(p, type) \
  216. ASSERT(((p) != NULL) && AfxIsValidAddress((p), sizeof(type), FALSE))
  217. #define ASSERT_NULL_OR_POINTER(p, type) \
  218. ASSERT(((p) == NULL) || AfxIsValidAddress((p), sizeof(type), FALSE))
  219. /////////////////////////////////////////////////////////////////////////////
  220. // Turn off warnings for /W4
  221. // To resume any of these warning: #pragma warning(default: 4xxx)
  222. // which should be placed after the AFX include files
  223. #ifndef ALL_WARNINGS
  224. // warnings generated with common MFC/Windows code
  225. #pragma warning(disable: 4127) // constant expression for TRACE/ASSERT
  226. #pragma warning(disable: 4134) // message map member fxn casts
  227. #pragma warning(disable: 4201) // nameless unions are part of C++
  228. #pragma warning(disable: 4511) // private copy constructors are good to have
  229. #pragma warning(disable: 4512) // private operator= are good to have
  230. #pragma warning(disable: 4514) // unreferenced inlines are common
  231. #pragma warning(disable: 4710) // private constructors are disallowed
  232. #pragma warning(disable: 4705) // statement has no effect in optimized code
  233. #pragma warning(disable: 4191) // pointer-to-function casting
  234. // warnings caused by normal optimizations
  235. #ifndef _DEBUG
  236. #pragma warning(disable: 4701) // local variable *may* be used without init
  237. #pragma warning(disable: 4702) // unreachable code caused by optimizations
  238. #pragma warning(disable: 4791) // loss of debugging info in release version
  239. #pragma warning(disable: 4189) // initialized but unused variable
  240. #pragma warning(disable: 4390) // empty controlled statement
  241. #endif
  242. // warnings specific to _AFXDLL version
  243. #ifdef _AFXDLL
  244. #pragma warning(disable: 4204) // non-constant aggregate initializer
  245. #endif
  246. #ifdef _AFXDLL
  247. #pragma warning(disable: 4275) // deriving exported class from non-exported
  248. #pragma warning(disable: 4251) // using non-exported as public in exported
  249. #endif
  250. #endif //!ALL_WARNINGS
  251. #ifdef _DEBUG
  252. #define UNUSED(x)
  253. #else
  254. #define UNUSED(x) x
  255. #endif
  256. #define UNUSED_ALWAYS(x) x
  257. /////////////////////////////////////////////////////////////////////////////
  258. // Other implementation helpers
  259. #define BEFORE_START_POSITION ((POSITION)-1L)
  260. /////////////////////////////////////////////////////////////////////////////
  261. // explicit initialization for general purpose classes
  262. BOOL AFXAPI AfxInitialize(BOOL bDLL = FALSE, DWORD dwVersion = _MFC_VER);
  263. #undef AFX_DATA
  264. #define AFX_DATA AFX_CORE_DATA
  265. /////////////////////////////////////////////////////////////////////////////
  266. // Basic object model
  267. struct CRuntimeClass
  268. {
  269. // Attributes
  270. LPCSTR m_lpszClassName;
  271. int m_nObjectSize;
  272. UINT m_wSchema; // schema number of the loaded class
  273. CObject* (PASCAL* m_pfnCreateObject)(); // NULL => abstract class
  274. #ifdef _AFXDLL
  275. CRuntimeClass* (PASCAL* m_pfnGetBaseClass)();
  276. #else
  277. CRuntimeClass* m_pBaseClass;
  278. #endif
  279. // Operations
  280. CObject* CreateObject();
  281. BOOL IsDerivedFrom(const CRuntimeClass* pBaseClass) const;
  282. // Implementation
  283. void Store(CArchive& ar) const;
  284. static CRuntimeClass* PASCAL Load(CArchive& ar, UINT* pwSchemaNum);
  285. // CRuntimeClass objects linked together in simple list
  286. CRuntimeClass* m_pNextClass; // linked list of registered classes
  287. };
  288. /////////////////////////////////////////////////////////////////////////////
  289. // Strings
  290. #ifndef _OLEAUTO_H_
  291. #ifdef OLE2ANSI
  292. typedef LPSTR BSTR;
  293. #else
  294. typedef LPWSTR BSTR;// must (semantically) match typedef in oleauto.h
  295. #endif
  296. #endif
  297. struct CStringData
  298. {
  299. long nRefs; // reference count
  300. int nDataLength; // length of data (including terminator)
  301. int nAllocLength; // length of allocation
  302. // TCHAR data[nAllocLength]
  303. TCHAR* data() // TCHAR* to managed data
  304. { return (TCHAR*)(this+1); }
  305. };
  306. class CString
  307. {
  308. public:
  309. // Constructors
  310. // constructs empty CString
  311. CString();
  312. // copy constructor
  313. CString(const CString& stringSrc);
  314. // from a single character
  315. CString(TCHAR ch, int nRepeat = 1);
  316. // from an ANSI string (converts to TCHAR)
  317. CString(LPCSTR lpsz);
  318. // from a UNICODE string (converts to TCHAR)
  319. CString(LPCWSTR lpsz);
  320. #if _MFC_VER >= 0x0600
  321. // subset of characters from an ANSI string (converts to TCHAR)
  322. CString(LPCSTR lpch, int nLength);
  323. // subset of characters from a UNICODE string (converts to TCHAR)
  324. CString(LPCWSTR lpch, int nLength);
  325. #else
  326. // subset of characters from a string (converts to TCHAR)
  327. CString(LPCTSTR lpch, int nLength);
  328. #endif
  329. // from unsigned characters
  330. CString(const unsigned char* psz);
  331. // Attributes & Operations
  332. // get data length
  333. int GetLength() const;
  334. // TRUE if zero length
  335. BOOL IsEmpty() const;
  336. // clear contents to empty
  337. void Empty();
  338. // return single character at zero-based index
  339. TCHAR GetAt(int nIndex) const;
  340. // return single character at zero-based index
  341. TCHAR operator[](int nIndex) const;
  342. // set a single character at zero-based index
  343. void SetAt(int nIndex, TCHAR ch);
  344. // return pointer to const string
  345. operator LPCTSTR() const;
  346. // overloaded assignment
  347. // ref-counted copy from another CString
  348. const CString& operator=(const CString& stringSrc);
  349. // set string content to single character
  350. const CString& operator=(TCHAR ch);
  351. #ifdef _UNICODE
  352. const CString& operator=(char ch);
  353. #endif
  354. // copy string content from ANSI string (converts to TCHAR)
  355. const CString& operator=(LPCSTR lpsz);
  356. // copy string content from UNICODE string (converts to TCHAR)
  357. const CString& operator=(LPCWSTR lpsz);
  358. // copy string content from unsigned chars
  359. const CString& operator=(const unsigned char* psz);
  360. // string concatenation
  361. // concatenate from another CString
  362. const CString& operator+=(const CString& string);
  363. // concatenate a single character
  364. const CString& operator+=(TCHAR ch);
  365. #ifdef _UNICODE
  366. // concatenate an ANSI character after converting it to TCHAR
  367. const CString& operator+=(char ch);
  368. #endif
  369. // concatenate a UNICODE character after converting it to TCHAR
  370. const CString& operator+=(LPCTSTR lpsz);
  371. friend CString AFXAPI operator+(const CString& string1,
  372. const CString& string2);
  373. friend CString AFXAPI operator+(const CString& string, TCHAR ch);
  374. friend CString AFXAPI operator+(TCHAR ch, const CString& string);
  375. #ifdef _UNICODE
  376. friend CString AFXAPI operator+(const CString& string, char ch);
  377. friend CString AFXAPI operator+(char ch, const CString& string);
  378. #endif
  379. friend CString AFXAPI operator+(const CString& string, LPCTSTR lpsz);
  380. friend CString AFXAPI operator+(LPCTSTR lpsz, const CString& string);
  381. // string comparison
  382. // straight character comparison
  383. int Compare(LPCTSTR lpsz) const;
  384. // compare ignoring case
  385. int CompareNoCase(LPCTSTR lpsz) const;
  386. // NLS aware comparison, case sensitive
  387. int Collate(LPCTSTR lpsz) const;
  388. #if _MFC_VER >= 0x0600
  389. // NLS aware comparison, case insensitive
  390. int CollateNoCase(LPCTSTR lpsz) const;
  391. #endif
  392. // simple sub-string extraction
  393. // return nCount characters starting at zero-based nFirst
  394. CString Mid(int nFirst, int nCount) const;
  395. // return all characters starting at zero-based nFirst
  396. CString Mid(int nFirst) const;
  397. // return first nCount characters in string
  398. CString Left(int nCount) const;
  399. // return nCount characters from end of string
  400. CString Right(int nCount) const;
  401. // characters from beginning that are also in passed string
  402. CString SpanIncluding(LPCTSTR lpszCharSet) const;
  403. // characters from beginning that are not also in passed string
  404. CString SpanExcluding(LPCTSTR lpszCharSet) const;
  405. // upper/lower/reverse conversion
  406. // NLS aware conversion to uppercase
  407. void MakeUpper();
  408. // NLS aware conversion to lowercase
  409. void MakeLower();
  410. // reverse string right-to-left
  411. void MakeReverse();
  412. // trimming whitespace (either side)
  413. // remove whitespace starting from right edge
  414. void TrimRight();
  415. // remove whitespace starting from left side
  416. void TrimLeft();
  417. #if _MFC_VER >= 0x0600
  418. // trimming anything (either side)
  419. // remove continuous occurrences of chTarget starting from right
  420. void TrimRight(TCHAR chTarget);
  421. // remove continuous occcurrences of characters in passed string,
  422. // starting from right
  423. void TrimRight(LPCTSTR lpszTargets);
  424. // remove continuous occurrences of chTarget starting from left
  425. void TrimLeft(TCHAR chTarget);
  426. // remove continuous occcurrences of characters in
  427. // passed string, starting from left
  428. void TrimLeft(LPCTSTR lpszTargets);
  429. // advanced manipulation
  430. // replace occurrences of chOld with chNew
  431. int Replace(TCHAR chOld, TCHAR chNew);
  432. // replace occurrences of substring lpszOld with lpszNew;
  433. // empty lpszNew removes instances of lpszOld
  434. int Replace(LPCTSTR lpszOld, LPCTSTR lpszNew);
  435. // remove occurrences of chRemove
  436. int Remove(TCHAR chRemove);
  437. // insert character at zero-based index; concatenates
  438. // if index is past end of string
  439. int Insert(int nIndex, TCHAR ch);
  440. // insert substring at zero-based index; concatenates
  441. // if index is past end of string
  442. int Insert(int nIndex, LPCTSTR pstr);
  443. // delete nCount characters starting at zero-based index
  444. int Delete(int nIndex, int nCount = 1);
  445. #endif
  446. // searching
  447. // find character starting at left, -1 if not found
  448. int Find(TCHAR ch) const;
  449. // find character starting at right
  450. int ReverseFind(TCHAR ch) const;
  451. #if _MFC_VER >= 0x0600
  452. // find character starting at zero-based index and going right
  453. int Find(TCHAR ch, int nStart) const;
  454. #endif
  455. // find first instance of any character in passed string
  456. int FindOneOf(LPCTSTR lpszCharSet) const;
  457. // find first instance of substring
  458. int Find(LPCTSTR lpszSub) const;
  459. #if _MFC_VER >= 0x0600
  460. // find first instance of substring starting at zero-based index
  461. int Find(LPCTSTR lpszSub, int nStart) const;
  462. #endif
  463. // simple formatting
  464. // printf-like formatting using passed string
  465. void AFX_CDECL Format(LPCTSTR lpszFormat, ...);
  466. // printf-like formatting using referenced string resource
  467. void AFX_CDECL Format(UINT nFormatID, ...);
  468. #if _MFC_VER < 0x0600
  469. protected:
  470. #endif
  471. // printf-like formatting using variable arguments parameter
  472. void FormatV(LPCTSTR lpszFormat, va_list argList);
  473. #if _MFC_VER < 0x0600
  474. public:
  475. #endif
  476. // formatting for localization (uses FormatMessage API)
  477. // format using FormatMessage API on passed string
  478. void AFX_CDECL FormatMessage(LPCTSTR lpszFormat, ...);
  479. // format using FormatMessage API on referenced string resource
  480. void AFX_CDECL FormatMessage(UINT nFormatID, ...);
  481. // input and output
  482. #ifdef _DEBUG
  483. friend CDumpContext& AFXAPI operator<<(CDumpContext& dc,
  484. const CString& string);
  485. #endif
  486. friend CArchive& AFXAPI operator<<(CArchive& ar, const CString& string);
  487. friend CArchive& AFXAPI operator>>(CArchive& ar, CString& string);
  488. // load from string resource
  489. BOOL LoadString(UINT nID);
  490. #ifndef _UNICODE
  491. // ANSI <-> OEM support (convert string in place)
  492. // convert string from ANSI to OEM in-place
  493. void AnsiToOem();
  494. // convert string from OEM to ANSI in-place
  495. void OemToAnsi();
  496. #endif
  497. #ifndef _AFX_NO_BSTR_SUPPORT
  498. // OLE BSTR support (use for OLE automation)
  499. // return a BSTR initialized with this CString's data
  500. BSTR AllocSysString() const;
  501. // reallocates the passed BSTR, copies content of this CString to it
  502. BSTR SetSysString(BSTR* pbstr) const;
  503. #endif
  504. // Access to string implementation buffer as "C" character array
  505. // get pointer to modifiable buffer at least as long as nMinBufLength
  506. LPTSTR GetBuffer(int nMinBufLength);
  507. // release buffer, setting length to nNewLength (or to first nul if -1)
  508. void ReleaseBuffer(int nNewLength = -1);
  509. // get pointer to modifiable buffer exactly as long as nNewLength
  510. LPTSTR GetBufferSetLength(int nNewLength);
  511. // release memory allocated to but unused by string
  512. void FreeExtra();
  513. // Use LockBuffer/UnlockBuffer to turn refcounting off
  514. // turn refcounting back on
  515. LPTSTR LockBuffer();
  516. // turn refcounting off
  517. void UnlockBuffer();
  518. // Implementation
  519. public:
  520. ~CString();
  521. int GetAllocLength() const;
  522. protected:
  523. LPTSTR m_pchData; // pointer to ref counted string data
  524. // implementation helpers
  525. CStringData* GetData() const;
  526. void Init();
  527. void AllocCopy(CString& dest, int nCopyLen, int nCopyIndex, int nExtraLen) const;
  528. void AllocBuffer(int nLen);
  529. void AssignCopy(int nSrcLen, LPCTSTR lpszSrcData);
  530. void ConcatCopy(int nSrc1Len, LPCTSTR lpszSrc1Data, int nSrc2Len, LPCTSTR lpszSrc2Data);
  531. void ConcatInPlace(int nSrcLen, LPCTSTR lpszSrcData);
  532. void CopyBeforeWrite();
  533. void AllocBeforeWrite(int nLen);
  534. void Release();
  535. static void PASCAL Release(CStringData* pData);
  536. static int PASCAL SafeStrlen(LPCTSTR lpsz);
  537. #if _MFC_VER >= 0x0600
  538. static void FASTCALL FreeData(CStringData* pData);
  539. #endif
  540. };
  541. // Compare helpers
  542. bool AFXAPI operator==(const CString& s1, const CString& s2);
  543. bool AFXAPI operator==(const CString& s1, LPCTSTR s2);
  544. bool AFXAPI operator==(LPCTSTR s1, const CString& s2);
  545. bool AFXAPI operator!=(const CString& s1, const CString& s2);
  546. bool AFXAPI operator!=(const CString& s1, LPCTSTR s2);
  547. bool AFXAPI operator!=(LPCTSTR s1, const CString& s2);
  548. bool AFXAPI operator<(const CString& s1, const CString& s2);
  549. bool AFXAPI operator<(const CString& s1, LPCTSTR s2);
  550. bool AFXAPI operator<(LPCTSTR s1, const CString& s2);
  551. bool AFXAPI operator>(const CString& s1, const CString& s2);
  552. bool AFXAPI operator>(const CString& s1, LPCTSTR s2);
  553. bool AFXAPI operator>(LPCTSTR s1, const CString& s2);
  554. bool AFXAPI operator<=(const CString& s1, const CString& s2);
  555. bool AFXAPI operator<=(const CString& s1, LPCTSTR s2);
  556. bool AFXAPI operator<=(LPCTSTR s1, const CString& s2);
  557. bool AFXAPI operator>=(const CString& s1, const CString& s2);
  558. bool AFXAPI operator>=(const CString& s1, LPCTSTR s2);
  559. bool AFXAPI operator>=(LPCTSTR s1, const CString& s2);
  560. // conversion helpers
  561. int AFX_CDECL _wcstombsz(char* mbstr, const wchar_t* wcstr, UINT count);
  562. int AFX_CDECL _mbstowcsz(wchar_t* wcstr, const char* mbstr, UINT count);
  563. // Globals
  564. extern AFX_DATA TCHAR afxChNil;
  565. #if _MFC_VER >= 0x0600
  566. #ifdef _AFXDLL
  567. const CString& AFXAPI AfxGetEmptyString();
  568. #define afxEmptyString AfxGetEmptyString()
  569. #else
  570. extern LPCTSTR _afxPchNil;
  571. #define afxEmptyString ((CString&)*(CString*)&_afxPchNil)
  572. #endif
  573. #else // _MFC_VER
  574. const CString& AFXAPI AfxGetEmptyString();
  575. #define afxEmptyString AfxGetEmptyString()
  576. #endif // _MFC_VER
  577. /////////////////////////////////////////////////////////////////////////////
  578. // class CObject is the root of all compliant objects
  579. #ifdef _AFXDLL
  580. class CObject
  581. #else
  582. class AFX_NOVTABLE CObject
  583. #endif
  584. {
  585. public:
  586. // Object model (types, destruction, allocation)
  587. virtual CRuntimeClass* GetRuntimeClass() const;
  588. virtual ~CObject(); // virtual destructors are necessary
  589. // Diagnostic allocations
  590. void* PASCAL operator new(size_t nSize);
  591. void* PASCAL operator new(size_t, void* p);
  592. void PASCAL operator delete(void* p);
  593. #if _MSC_VER >= 1200
  594. void PASCAL operator delete(void* p, void* pPlace);
  595. #endif
  596. #if defined(_DEBUG) && !defined(_AFX_NO_DEBUG_CRT)
  597. // for file name/line number tracking using DEBUG_NEW
  598. void* PASCAL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
  599. #if (_MFC_VER >= 0x0600) && (_MSC_VER >= 1200)
  600. void PASCAL operator delete(void *p, LPCSTR lpszFileName, int nLine);
  601. #endif
  602. #endif
  603. // Disable the copy constructor and assignment by default so you will get
  604. // compiler errors instead of unexpected behaviour if you pass objects
  605. // by value or assign objects.
  606. protected:
  607. CObject();
  608. private:
  609. CObject(const CObject& objectSrc); // no implementation
  610. void operator=(const CObject& objectSrc); // no implementation
  611. // Attributes
  612. public:
  613. BOOL IsSerializable() const;
  614. BOOL IsKindOf(const CRuntimeClass* pClass) const;
  615. // Overridables
  616. virtual void Serialize(CArchive& ar);
  617. #if _MFC_VER < 0x0600 || defined(_DEBUG) || defined(_AFXDLL)
  618. // Diagnostic Support
  619. virtual void AssertValid() const;
  620. virtual void Dump(CDumpContext& dc) const;
  621. #endif
  622. // Implementation
  623. public:
  624. static const AFX_DATA CRuntimeClass classCObject;
  625. #ifdef _AFXDLL
  626. static CRuntimeClass* PASCAL _GetBaseClass();
  627. #endif
  628. };
  629. // Helper macros
  630. #define RUNTIME_CLASS(class_name) ((CRuntimeClass*)(&class_name::class##class_name))
  631. #define ASSERT_KINDOF(class_name, object) \
  632. ASSERT((object)->IsKindOf(RUNTIME_CLASS(class_name)))
  633. // RTTI helper macros/functions
  634. const CObject* AFX_CDECL AfxDynamicDownCast(CRuntimeClass* pClass, const CObject* pObject);
  635. CObject* AFX_CDECL AfxDynamicDownCast(CRuntimeClass* pClass, CObject* pObject);
  636. #define DYNAMIC_DOWNCAST(class_name, object) \
  637. (class_name*)AfxDynamicDownCast(RUNTIME_CLASS(class_name), object)
  638. #ifdef _DEBUG
  639. const CObject* AFX_CDECL AfxStaticDownCast(CRuntimeClass* pClass, const CObject* pObject);
  640. CObject* AFX_CDECL AfxStaticDownCast(CRuntimeClass* pClass, CObject* pObject);
  641. #define STATIC_DOWNCAST(class_name, object) \
  642. ((class_name*)AfxStaticDownCast(RUNTIME_CLASS(class_name), object))
  643. #else
  644. #define STATIC_DOWNCAST(class_name, object) ((class_name*)object)
  645. #endif
  646. //////////////////////////////////////////////////////////////////////////////
  647. // Helper macros for declaring CRuntimeClass compatible classes
  648. #ifdef _AFXDLL
  649. #define DECLARE_DYNAMIC(class_name) \
  650. protected: \
  651. static CRuntimeClass* PASCAL _GetBaseClass(); \
  652. public: \
  653. static const AFX_DATA CRuntimeClass class##class_name; \
  654. virtual CRuntimeClass* GetRuntimeClass() const; \
  655. #define _DECLARE_DYNAMIC(class_name) \
  656. protected: \
  657. static CRuntimeClass* PASCAL _GetBaseClass(); \
  658. public: \
  659. static AFX_DATA CRuntimeClass class##class_name; \
  660. virtual CRuntimeClass* GetRuntimeClass() const; \
  661. #else
  662. #define DECLARE_DYNAMIC(class_name) \
  663. public: \
  664. static const AFX_DATA CRuntimeClass class##class_name; \
  665. virtual CRuntimeClass* GetRuntimeClass() const; \
  666. #define _DECLARE_DYNAMIC(class_name) \
  667. public: \
  668. static AFX_DATA CRuntimeClass class##class_name; \
  669. virtual CRuntimeClass* GetRuntimeClass() const; \
  670. #endif
  671. // not serializable, but dynamically constructable
  672. #define DECLARE_DYNCREATE(class_name) \
  673. DECLARE_DYNAMIC(class_name) \
  674. static CObject* PASCAL CreateObject();
  675. #define _DECLARE_DYNCREATE(class_name) \
  676. _DECLARE_DYNAMIC(class_name) \
  677. static CObject* PASCAL CreateObject();
  678. #define DECLARE_SERIAL(class_name) \
  679. _DECLARE_DYNCREATE(class_name) \
  680. AFX_API friend CArchive& AFXAPI operator>>(CArchive& ar, class_name* &pOb);
  681. // generate static object constructor for class registration
  682. #if _MFC_VER >= 0x600
  683. void AFXAPI AfxClassInit(CRuntimeClass* pNewClass);
  684. struct AFX_CLASSINIT
  685. { AFX_CLASSINIT(CRuntimeClass* pNewClass) { AfxClassInit(pNewClass); } };
  686. struct AFX_CLASSINIT_COMPAT
  687. { AFX_CLASSINIT_COMPAT(CRuntimeClass* pNewClass); };
  688. #else
  689. struct AFX_CLASSINIT
  690. { AFX_CLASSINIT(CRuntimeClass* pNewClass); };
  691. #endif
  692. #ifdef _AFXDLL
  693. #define IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew) \
  694. CRuntimeClass* PASCAL class_name::_GetBaseClass() \
  695. { return RUNTIME_CLASS(base_class_name); } \
  696. AFX_COMDAT const AFX_DATADEF CRuntimeClass class_name::class##class_name = { \
  697. #class_name, sizeof(class class_name), wSchema, pfnNew, \
  698. &class_name::_GetBaseClass, NULL }; \
  699. CRuntimeClass* class_name::GetRuntimeClass() const \
  700. { return RUNTIME_CLASS(class_name); } \
  701. #define _IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew) \
  702. CRuntimeClass* PASCAL class_name::_GetBaseClass() \
  703. { return RUNTIME_CLASS(base_class_name); } \
  704. AFX_COMDAT AFX_DATADEF CRuntimeClass class_name::class##class_name = { \
  705. #class_name, sizeof(class class_name), wSchema, pfnNew, \
  706. &class_name::_GetBaseClass, NULL }; \
  707. CRuntimeClass* class_name::GetRuntimeClass() const \
  708. { return RUNTIME_CLASS(class_name); } \
  709. #else
  710. #define IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew) \
  711. AFX_COMDAT const AFX_DATADEF CRuntimeClass class_name::class##class_name = { \
  712. #class_name, sizeof(class class_name), wSchema, pfnNew, \
  713. RUNTIME_CLASS(base_class_name), NULL }; \
  714. CRuntimeClass* class_name::GetRuntimeClass() const \
  715. { return RUNTIME_CLASS(class_name); } \
  716. #define _IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew) \
  717. AFX_DATADEF CRuntimeClass class_name::class##class_name = { \
  718. #class_name, sizeof(class class_name), wSchema, pfnNew, \
  719. RUNTIME_CLASS(base_class_name), NULL }; \
  720. CRuntimeClass* class_name::GetRuntimeClass() const \
  721. { return RUNTIME_CLASS(class_name); } \
  722. #endif
  723. #define IMPLEMENT_DYNAMIC(class_name, base_class_name) \
  724. IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, 0xFFFF, NULL)
  725. #define IMPLEMENT_DYNCREATE(class_name, base_class_name) \
  726. CObject* PASCAL class_name::CreateObject() \
  727. { return new class_name; } \
  728. IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, 0xFFFF, \
  729. class_name::CreateObject)
  730. #if _MFC_VER >= 0x0600
  731. #define IMPLEMENT_SERIAL(class_name, base_class_name, wSchema) \
  732. CObject* PASCAL class_name::CreateObject() \
  733. { return new class_name; } \
  734. _IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, \
  735. class_name::CreateObject) \
  736. AFX_CLASSINIT _init_##class_name(RUNTIME_CLASS(class_name)); \
  737. CArchive& AFXAPI operator>>(CArchive& ar, class_name* &pOb) \
  738. { pOb = (class_name*) ar.ReadObject(RUNTIME_CLASS(class_name)); \
  739. return ar; } \
  740. #else
  741. #define IMPLEMENT_SERIAL(class_name, base_class_name, wSchema) \
  742. CObject* PASCAL class_name::CreateObject() \
  743. { return new class_name; } \
  744. _IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, \
  745. class_name::CreateObject) \
  746. static const AFX_CLASSINIT _init_##class_name(RUNTIME_CLASS(class_name)); \
  747. CArchive& AFXAPI operator>>(CArchive& ar, class_name* &pOb) \
  748. { pOb = (class_name*) ar.ReadObject(RUNTIME_CLASS(class_name)); \
  749. return ar; } \
  750. #endif
  751. // optional bit for schema number that enables object versioning
  752. #define VERSIONABLE_SCHEMA (0x80000000)
  753. /////////////////////////////////////////////////////////////////////////////
  754. // other helpers
  755. // zero fill everything after the vtbl pointer
  756. #define AFX_ZERO_INIT_OBJECT(base_class) \
  757. memset(((base_class*)this)+1, 0, sizeof(*this) - sizeof(class base_class));
  758. /////////////////////////////////////////////////////////////////////////////
  759. // Exceptions
  760. #ifdef _AFXDLL
  761. class CException : public CObject
  762. #else
  763. class AFX_NOVTABLE CException : public CObject
  764. #endif
  765. {
  766. // abstract class for dynamic type checking
  767. DECLARE_DYNAMIC(CException)
  768. public:
  769. // Constructors
  770. CException(); // sets m_bAutoDelete = TRUE
  771. CException(BOOL bAutoDelete); // sets m_bAutoDelete = bAutoDelete
  772. // Operations
  773. void Delete(); // use to delete exception in 'catch' block
  774. virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
  775. PUINT pnHelpContext = NULL);
  776. virtual int ReportError(UINT nType = MB_OK, UINT nMessageID = 0);
  777. // Implementation (setting m_bAutoDelete to FALSE is advanced)
  778. public:
  779. virtual ~CException();
  780. BOOL m_bAutoDelete;
  781. #ifdef _DEBUG
  782. void PASCAL operator delete(void* pbData);
  783. #if (_MSC_VER >= 1200) && (_MFC_VER >= 0x0600)
  784. void PASCAL operator delete(void* pbData, LPCSTR lpszFileName, int nLine);
  785. #endif
  786. protected:
  787. BOOL m_bReadyForDelete;
  788. #endif
  789. };
  790. #ifdef _AFXDLL
  791. class CSimpleException : public CException
  792. #else
  793. class AFX_NOVTABLE CSimpleException : public CException
  794. #endif
  795. {
  796. // base class for resource-critical MFC exceptions
  797. // handles ownership and initialization of an error message
  798. public:
  799. // Constructors
  800. CSimpleException();
  801. CSimpleException(BOOL bAutoDelete);
  802. // Operations
  803. virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
  804. PUINT pnHelpContext = NULL);
  805. // Implementation (setting m_bAutoDelete to FALSE is advanced)
  806. public:
  807. virtual ~CSimpleException();
  808. BOOL m_bAutoDelete;
  809. void InitString(); // used during MFC initialization
  810. protected:
  811. BOOL m_bInitialized;
  812. BOOL m_bLoaded;
  813. TCHAR m_szMessage[128];
  814. UINT m_nResourceID;
  815. #ifdef _DEBUG
  816. BOOL m_bReadyForDelete;
  817. #endif
  818. };
  819. // helper routines for non-C++ EH implementations
  820. #ifdef _AFX_OLD_EXCEPTIONS
  821. BOOL AFXAPI AfxCatchProc(CRuntimeClass* pClass);
  822. void AFXAPI AfxThrow(CException* pException);
  823. #else
  824. // for THROW_LAST auto-delete backward compatiblity
  825. void AFXAPI AfxThrowLastCleanup();
  826. #endif
  827. // other out-of-line helper functions
  828. void AFXAPI AfxTryCleanup();
  829. #ifndef _AFX_JUMPBUF
  830. // Use portable 'jmp_buf' defined by ANSI by default.
  831. #define _AFX_JUMPBUF jmp_buf
  832. #endif
  833. // Placed on frame for EXCEPTION linkage, or CException cleanup
  834. struct AFX_EXCEPTION_LINK
  835. {
  836. #ifdef _AFX_OLD_EXCEPTIONS
  837. union
  838. {
  839. _AFX_JUMPBUF m_jumpBuf;
  840. struct
  841. {
  842. void (PASCAL* pfnCleanup)(AFX_EXCEPTION_LINK* pLink);
  843. void* pvData; // extra data follows
  844. } m_callback; // callback for cleanup (nType != 0)
  845. };
  846. UINT m_nType; // 0 for setjmp, !=0 for user extension
  847. #endif //!_AFX_OLD_EXCEPTIONS
  848. AFX_EXCEPTION_LINK* m_pLinkPrev; // previous top, next in handler chain
  849. CException* m_pException; // current exception (NULL in TRY block)
  850. AFX_EXCEPTION_LINK(); // for initialization and linking
  851. ~AFX_EXCEPTION_LINK() // for cleanup and unlinking
  852. { AfxTryCleanup(); };
  853. };
  854. // Exception global state - never access directly
  855. struct AFX_EXCEPTION_CONTEXT
  856. {
  857. AFX_EXCEPTION_LINK* m_pLinkTop;
  858. // Note: most of the exception context is now in the AFX_EXCEPTION_LINK
  859. };
  860. #ifndef _PNH_DEFINED
  861. typedef int (__cdecl * _PNH)( size_t );
  862. #define _PNH_DEFINED
  863. #endif
  864. _PNH AFXAPI AfxGetNewHandler();
  865. _PNH AFXAPI AfxSetNewHandler(_PNH pfnNewHandler);
  866. int AFX_CDECL AfxNewHandler(size_t nSize);
  867. void AFXAPI AfxAbort();
  868. #ifdef _AFX_OLD_EXCEPTIONS
  869. // Obsolete and non-portable: setting terminate handler
  870. // use CWinApp::ProcessWndProcException for Windows apps instead
  871. // can also use set_terminate which is part of C++ standard library
  872. // (these are provided for backward compatibility)
  873. void AFXAPI AfxTerminate();
  874. typedef void (AFXAPI* AFX_TERM_PROC)();
  875. AFX_TERM_PROC AFXAPI AfxSetTerminate(AFX_TERM_PROC);
  876. #endif
  877. /////////////////////////////////////////////////////////////////////////////
  878. // Exception macros using try, catch and throw
  879. // (for backward compatibility to previous versions of MFC)
  880. #ifndef _AFX_OLD_EXCEPTIONS
  881. #define TRY { AFX_EXCEPTION_LINK _afxExceptionLink; try {
  882. #define CATCH(class, e) } catch (class* e) \
  883. { ASSERT(e->IsKindOf(RUNTIME_CLASS(class))); \
  884. _afxExceptionLink.m_pException = e;
  885. #define AND_CATCH(class, e) } catch (class* e) \
  886. { ASSERT(e->IsKindOf(RUNTIME_CLASS(class))); \
  887. _afxExceptionLink.m_pException = e;
  888. #define END_CATCH } }
  889. #define THROW(e) throw e
  890. #define THROW_LAST() (AfxThrowLastCleanup(), throw)
  891. // Advanced macros for smaller code
  892. #define CATCH_ALL(e) } catch (CException* e) \
  893. { { ASSERT(e->IsKindOf(RUNTIME_CLASS(CException))); \
  894. _afxExceptionLink.m_pException = e;
  895. #define AND_CATCH_ALL(e) } catch (CException* e) \
  896. { { ASSERT(e->IsKindOf(RUNTIME_CLASS(CException))); \
  897. _afxExceptionLink.m_pException = e;
  898. #define END_CATCH_ALL } } }
  899. #define END_TRY } catch (CException* e) \
  900. { ASSERT(e->IsKindOf(RUNTIME_CLASS(CException))); \
  901. _afxExceptionLink.m_pException = e; } }
  902. #else //_AFX_OLD_EXCEPTIONS
  903. /////////////////////////////////////////////////////////////////////////////
  904. // Exception macros using setjmp and longjmp
  905. // (for portability to compilers with no support for C++ exception handling)
  906. #define TRY \
  907. { AFX_EXCEPTION_LINK _afxExceptionLink; \
  908. if (::setjmp(_afxExceptionLink.m_jumpBuf) == 0)
  909. #define CATCH(class, e) \
  910. else if (::AfxCatchProc(RUNTIME_CLASS(class))) \
  911. { class* e = (class*)_afxExceptionLink.m_pException;
  912. #define AND_CATCH(class, e) \
  913. } else if (::AfxCatchProc(RUNTIME_CLASS(class))) \
  914. { class* e = (class*)_afxExceptionLink.m_pException;
  915. #define END_CATCH \
  916. } else { ::AfxThrow(NULL); } }
  917. #define THROW(e) AfxThrow(e)
  918. #define THROW_LAST() AfxThrow(NULL)
  919. // Advanced macros for smaller code
  920. #define CATCH_ALL(e) \
  921. else { CException* e = _afxExceptionLink.m_pException;
  922. #define AND_CATCH_ALL(e) \
  923. } else { CException* e = _afxExceptionLink.m_pException;
  924. #define END_CATCH_ALL } }
  925. #define END_TRY }
  926. #endif //_AFX_OLD_EXCEPTIONS
  927. /////////////////////////////////////////////////////////////////////////////
  928. // Standard Exception classes
  929. class CMemoryException : public CSimpleException
  930. {
  931. DECLARE_DYNAMIC(CMemoryException)
  932. public:
  933. CMemoryException();
  934. // Implementation
  935. public:
  936. CMemoryException(BOOL bAutoDelete);
  937. CMemoryException(BOOL bAutoDelete, UINT nResourceID);
  938. virtual ~CMemoryException();
  939. };
  940. class CNotSupportedException : public CSimpleException
  941. {
  942. DECLARE_DYNAMIC(CNotSupportedException)
  943. public:
  944. CNotSupportedException();
  945. // Implementation
  946. public:
  947. CNotSupportedException(BOOL bAutoDelete);
  948. CNotSupportedException(BOOL bAutoDelete, UINT nResourceID);
  949. virtual ~CNotSupportedException();
  950. };
  951. class CArchiveException : public CException
  952. {
  953. DECLARE_DYNAMIC(CArchiveException)
  954. public:
  955. enum {
  956. none,
  957. generic,
  958. readOnly,
  959. endOfFile,
  960. writeOnly,
  961. badIndex,
  962. badClass,
  963. badSchema
  964. };
  965. // Constructor
  966. CArchiveException(int cause = CArchiveException::none,
  967. LPCTSTR lpszArchiveName = NULL);
  968. // Attributes
  969. int m_cause;
  970. CString m_strFileName;
  971. // Implementation
  972. public:
  973. virtual ~CArchiveException();
  974. #ifdef _DEBUG
  975. virtual void Dump(CDumpContext& dc) const;
  976. #endif
  977. virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
  978. PUINT pnHelpContext = NULL);
  979. };
  980. class CFileException : public CException
  981. {
  982. DECLARE_DYNAMIC(CFileException)
  983. public:
  984. enum {
  985. none,
  986. generic,
  987. fileNotFound,
  988. badPath,
  989. tooManyOpenFiles,
  990. accessDenied,
  991. invalidFile,
  992. removeCurrentDir,
  993. directoryFull,
  994. badSeek,
  995. hardIO,
  996. sharingViolation,
  997. lockViolation,
  998. diskFull,
  999. endOfFile
  1000. };
  1001. // Constructor
  1002. CFileException(int cause = CFileException::none, LONG lOsError = -1,
  1003. LPCTSTR lpszArchiveName = NULL);
  1004. // Attributes
  1005. int m_cause;
  1006. LONG m_lOsError;
  1007. CString m_strFileName;
  1008. // Operations
  1009. // convert a OS dependent error code to a Cause
  1010. static int PASCAL OsErrorToException(LONG lOsError);
  1011. static int PASCAL ErrnoToException(int nErrno);
  1012. // helper functions to throw exception after converting to a Cause
  1013. static void PASCAL ThrowOsError(LONG lOsError, LPCTSTR lpszFileName = NULL);
  1014. static void PASCAL ThrowErrno(int nErrno, LPCTSTR lpszFileName = NULL);
  1015. // Implementation
  1016. public:
  1017. virtual ~CFileException();
  1018. #ifdef _DEBUG
  1019. virtual void Dump(CDumpContext&) const;
  1020. #endif
  1021. virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
  1022. PUINT pnHelpContext = NULL);
  1023. };
  1024. /////////////////////////////////////////////////////////////////////////////
  1025. // Standard exception throws
  1026. void AFXAPI AfxThrowMemoryException();
  1027. void AFXAPI AfxThrowNotSupportedException();
  1028. void AFXAPI AfxThrowArchiveException(int cause,
  1029. LPCTSTR lpszArchiveName = NULL);
  1030. void AFXAPI AfxThrowFileException(int cause, LONG lOsError = -1,
  1031. LPCTSTR lpszFileName = NULL);
  1032. /////////////////////////////////////////////////////////////////////////////
  1033. // File - raw unbuffered disk file I/O
  1034. class CFile : public CObject
  1035. {
  1036. DECLARE_DYNAMIC(CFile)
  1037. public:
  1038. // Flag values
  1039. enum OpenFlags {
  1040. modeRead = 0x0000,
  1041. modeWrite = 0x0001,
  1042. modeReadWrite = 0x0002,
  1043. shareCompat = 0x0000,
  1044. shareExclusive = 0x0010,
  1045. shareDenyWrite = 0x0020,
  1046. shareDenyRead = 0x0030,
  1047. shareDenyNone = 0x0040,
  1048. modeNoInherit = 0x0080,
  1049. modeCreate = 0x1000,
  1050. modeNoTruncate = 0x2000,
  1051. typeText = 0x4000, // typeText and typeBinary are used in
  1052. typeBinary = (int)0x8000 // derived classes only
  1053. };
  1054. enum Attribute {
  1055. normal = 0x00,
  1056. readOnly = 0x01,
  1057. hidden = 0x02,
  1058. system = 0x04,
  1059. volume = 0x08,
  1060. directory = 0x10,
  1061. archive = 0x20
  1062. };
  1063. enum SeekPosition { begin = 0x0, current = 0x1, end = 0x2 };
  1064. enum { hFileNull = -1 };
  1065. // Constructors
  1066. CFile();
  1067. CFile(INT_PTR hFile);
  1068. CFile(LPCTSTR lpszFileName, UINT nOpenFlags);
  1069. // Attributes
  1070. UINT_PTR m_hFile;
  1071. operator HFILE() const;
  1072. virtual DWORD GetPosition() const;
  1073. BOOL GetStatus(CFileStatus& rStatus) const;
  1074. virtual CString GetFileName() const;
  1075. virtual CString GetFileTitle() const;
  1076. virtual CString GetFilePath() const;
  1077. virtual void SetFilePath(LPCTSTR lpszNewName);
  1078. // Operations
  1079. virtual BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags,
  1080. CFileException* pError = NULL);
  1081. static void PASCAL Rename(LPCTSTR lpszOldName,
  1082. LPCTSTR lpszNewName);
  1083. static void PASCAL Remove(LPCTSTR lpszFileName);
  1084. static BOOL PASCAL GetStatus(LPCTSTR lpszFileName,
  1085. CFileStatus& rStatus);
  1086. static void PASCAL SetStatus(LPCTSTR lpszFileName,
  1087. const CFileStatus& status);
  1088. DWORD SeekToEnd();
  1089. void SeekToBegin();
  1090. // backward compatible ReadHuge and WriteHuge
  1091. DWORD ReadHuge(void* lpBuffer, DWORD dwCount);
  1092. void WriteHuge(const void* lpBuffer, DWORD dwCount);
  1093. // Overridables
  1094. virtual CFile* Duplicate() const;
  1095. virtual LONG Seek(LONG lOff, UINT nFrom);
  1096. virtual void SetLength(DWORD dwNewLen);
  1097. virtual DWORD GetLength() const;
  1098. virtual UINT Read(void* lpBuf, UINT nCount);
  1099. virtual void Write(const void* lpBuf, UINT nCount);
  1100. virtual void LockRange(DWORD dwPos, DWORD dwCount);
  1101. virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
  1102. virtual void Abort();
  1103. virtual void Flush();
  1104. virtual void Close();
  1105. // Implementation
  1106. public:
  1107. virtual ~CFile();
  1108. #ifdef _DEBUG
  1109. virtual void AssertValid() const;
  1110. virtual void Dump(CDumpContext& dc) const;
  1111. #endif
  1112. enum BufferCommand { bufferRead, bufferWrite, bufferCommit, bufferCheck };
  1113. virtual UINT GetBufferPtr(UINT nCommand, UINT nCount = 0,
  1114. void** ppBufStart = NULL, void** ppBufMax = NULL);
  1115. protected:
  1116. BOOL m_bCloseOnDelete;
  1117. CString m_strFileName;
  1118. };
  1119. /////////////////////////////////////////////////////////////////////////////
  1120. // STDIO file implementation
  1121. class CStdioFile : public CFile
  1122. {
  1123. DECLARE_DYNAMIC(CStdioFile)
  1124. public:
  1125. // Constructors
  1126. CStdioFile();
  1127. CStdioFile(FILE* pOpenStream);
  1128. CStdioFile(LPCTSTR lpszFileName, UINT nOpenFlags);
  1129. // Attributes
  1130. FILE* m_pStream; // stdio FILE
  1131. // m_hFile from base class is _fileno(m_pStream)
  1132. // Operations
  1133. // reading and writing strings
  1134. virtual void WriteString(LPCTSTR lpsz);
  1135. virtual LPTSTR ReadString(LPTSTR lpsz, UINT nMax);
  1136. virtual BOOL ReadString(CString& rString);
  1137. // Implementation
  1138. public:
  1139. virtual ~CStdioFile();
  1140. #ifdef _DEBUG
  1141. void Dump(CDumpContext& dc) const;
  1142. #endif
  1143. virtual DWORD GetPosition() const;
  1144. virtual BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags,
  1145. CFileException* pError = NULL);
  1146. virtual UINT Read(void* lpBuf, UINT nCount);
  1147. virtual void Write(const void* lpBuf, UINT nCount);
  1148. virtual LONG Seek(LONG lOff, UINT nFrom);
  1149. virtual void Abort();
  1150. virtual void Flush();
  1151. virtual void Close();
  1152. // Unsupported APIs
  1153. virtual CFile* Duplicate() const;
  1154. virtual void LockRange(DWORD dwPos, DWORD dwCount);
  1155. virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
  1156. };
  1157. ////////////////////////////////////////////////////////////////////////////
  1158. // Memory based file implementation
  1159. class CMemFile : public CFile
  1160. {
  1161. DECLARE_DYNAMIC(CMemFile)
  1162. public:
  1163. // Constructors
  1164. CMemFile(UINT nGrowBytes = 1024);
  1165. CMemFile(BYTE* lpBuffer, UINT nBufferSize, UINT nGrowBytes = 0);
  1166. // Operations
  1167. void Attach(BYTE* lpBuffer, UINT nBufferSize, UINT nGrowBytes = 0);
  1168. BYTE* Detach();
  1169. // Advanced Overridables
  1170. protected:
  1171. virtual BYTE* Alloc(DWORD nBytes);
  1172. virtual BYTE* Realloc(BYTE* lpMem, DWORD nBytes);
  1173. virtual BYTE* Memcpy(BYTE* lpMemTarget, const BYTE* lpMemSource, UINT nBytes);
  1174. virtual void Free(BYTE* lpMem);
  1175. virtual void GrowFile(DWORD dwNewLen);
  1176. // Implementation
  1177. protected:
  1178. UINT m_nGrowBytes;
  1179. DWORD m_nPosition;
  1180. DWORD m_nBufferSize;
  1181. DWORD m_nFileSize;
  1182. BYTE* m_lpBuffer;
  1183. BOOL m_bAutoDelete;
  1184. public:
  1185. virtual ~CMemFile();
  1186. #ifdef _DEBUG
  1187. virtual void Dump(CDumpContext& dc) const;
  1188. virtual void AssertValid() const;
  1189. #endif
  1190. virtual DWORD GetPosition() const;
  1191. BOOL GetStatus(CFileStatus& rStatus) const;
  1192. virtual LONG Seek(LONG lOff, UINT nFrom);
  1193. virtual void SetLength(DWORD dwNewLen);
  1194. virtual UINT Read(void* lpBuf, UINT nCount);
  1195. virtual void Write(const void* lpBuf, UINT nCount);
  1196. virtual void Abort();
  1197. virtual void Flush();
  1198. virtual void Close();
  1199. virtual UINT GetBufferPtr(UINT nCommand, UINT nCount = 0,
  1200. void** ppBufStart = NULL, void** ppBufMax = NULL);
  1201. // Unsupported APIs
  1202. virtual CFile* Duplicate() const;
  1203. virtual void LockRange(DWORD dwPos, DWORD dwCount);
  1204. virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
  1205. };
  1206. ////////////////////////////////////////////////////////////////////////////
  1207. // Local file searches
  1208. class CFileFind : public CObject
  1209. {
  1210. public:
  1211. CFileFind();
  1212. virtual ~CFileFind();
  1213. // Attributes
  1214. public:
  1215. DWORD GetLength() const;
  1216. #if defined(_X86_) || defined(_ALPHA_)
  1217. __int64 GetLength64() const;
  1218. #endif
  1219. virtual CString GetFileName() const;
  1220. virtual CString GetFilePath() const;
  1221. virtual CString GetFileTitle() const;
  1222. virtual CString GetFileURL() const;
  1223. virtual CString GetRoot() const;
  1224. virtual BOOL GetLastWriteTime(FILETIME* pTimeStamp) const;
  1225. virtual BOOL GetLastAccessTime(FILETIME* pTimeStamp) const;
  1226. virtual BOOL GetCreationTime(FILETIME* pTimeStamp) const;
  1227. virtual BOOL GetLastWriteTime(CTime& refTime) const;
  1228. virtual BOOL GetLastAccessTime(CTime& refTime) const;
  1229. virtual BOOL GetCreationTime(CTime& refTime) const;
  1230. virtual BOOL MatchesMask(DWORD dwMask) const;
  1231. virtual BOOL IsDots() const;
  1232. // these aren't virtual because they all use MatchesMask(), which is
  1233. BOOL IsReadOnly() const;
  1234. BOOL IsDirectory() const;
  1235. BOOL IsCompressed() const;
  1236. BOOL IsSystem() const;
  1237. BOOL IsHidden() const;
  1238. BOOL IsTemporary() const;
  1239. BOOL IsNormal() const;
  1240. BOOL IsArchived() const;
  1241. // Operations
  1242. void Close();
  1243. virtual BOOL FindFile(LPCTSTR pstrName = NULL, DWORD dwUnused = 0);
  1244. virtual BOOL FindNextFile();
  1245. protected:
  1246. virtual void CloseContext();
  1247. // Implementation
  1248. protected:
  1249. void* m_pFoundInfo;
  1250. void* m_pNextInfo;
  1251. HANDLE m_hContext;
  1252. BOOL m_bGotLast;
  1253. CString m_strRoot;
  1254. TCHAR m_chDirSeparator; // not '\\' for Internet classes
  1255. #ifdef _DEBUG
  1256. void Dump(CDumpContext& dc) const;
  1257. void AssertValid() const;
  1258. #endif
  1259. DECLARE_DYNAMIC(CFileFind)
  1260. };
  1261. /////////////////////////////////////////////////////////////////////////////
  1262. // CTimeSpan and CTime
  1263. class CTimeSpan
  1264. {
  1265. public:
  1266. // Constructors
  1267. CTimeSpan();
  1268. CTimeSpan(time_t time);
  1269. CTimeSpan(LONG lDays, int nHours, int nMins, int nSecs);
  1270. CTimeSpan(const CTimeSpan& timeSpanSrc);
  1271. const CTimeSpan& operator=(const CTimeSpan& timeSpanSrc);
  1272. // Attributes
  1273. // extract parts
  1274. LONG_PTR GetDays() const; // total # of days
  1275. LONG_PTR GetTotalHours() const;
  1276. int GetHours() const;
  1277. LONG_PTR GetTotalMinutes() const;
  1278. int GetMinutes() const;
  1279. LONG_PTR GetTotalSeconds() const;
  1280. int GetSeconds() const;
  1281. // Operations
  1282. // time math
  1283. CTimeSpan operator-(CTimeSpan timeSpan) const;
  1284. CTimeSpan operator+(CTimeSpan timeSpan) const;
  1285. const CTimeSpan& operator+=(CTimeSpan timeSpan);
  1286. const CTimeSpan& operator-=(CTimeSpan timeSpan);
  1287. BOOL operator==(CTimeSpan timeSpan) const;
  1288. BOOL operator!=(CTimeSpan timeSpan) const;
  1289. BOOL operator<(CTimeSpan timeSpan) const;
  1290. BOOL operator>(CTimeSpan timeSpan) const;
  1291. BOOL operator<=(CTimeSpan timeSpan) const;
  1292. BOOL operator>=(CTimeSpan timeSpan) const;
  1293. #ifdef _UNICODE
  1294. // for compatibility with MFC 3.x
  1295. CString Format(LPCSTR pFormat) const;
  1296. #endif
  1297. CString Format(LPCTSTR pFormat) const;
  1298. CString Format(UINT nID) const;
  1299. // serialization
  1300. #ifdef _DEBUG
  1301. friend CDumpContext& AFXAPI operator<<(CDumpContext& dc,CTimeSpan timeSpan);
  1302. #endif
  1303. friend CArchive& AFXAPI operator<<(CArchive& ar, CTimeSpan timeSpan);
  1304. friend CArchive& AFXAPI operator>>(CArchive& ar, CTimeSpan& rtimeSpan);
  1305. private:
  1306. time_t m_timeSpan;
  1307. friend class CTime;
  1308. };
  1309. class CTime
  1310. {
  1311. public:
  1312. // Constructors
  1313. static CTime PASCAL GetCurrentTime();
  1314. CTime();
  1315. CTime(time_t time);
  1316. CTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec,
  1317. int nDST = -1);
  1318. CTime(WORD wDosDate, WORD wDosTime, int nDST = -1);
  1319. CTime(const CTime& timeSrc);
  1320. CTime(const SYSTEMTIME& sysTime, int nDST = -1);
  1321. CTime(const FILETIME& fileTime, int nDST = -1);
  1322. const CTime& operator=(const CTime& timeSrc);
  1323. const CTime& operator=(time_t t);
  1324. // Attributes
  1325. struct tm* GetGmtTm(struct tm* ptm = NULL) const;
  1326. struct tm* GetLocalTm(struct tm* ptm = NULL) const;
  1327. #if _MFC_VER >= 0x0600
  1328. BOOL GetAsSystemTime(SYSTEMTIME& timeDest) const;
  1329. #endif
  1330. time_t GetTime() const;
  1331. int GetYear() const;
  1332. int GetMonth() const; // month of year (1 = Jan)
  1333. int GetDay() const; // day of month
  1334. int GetHour() const;
  1335. int GetMinute() const;
  1336. int GetSecond() const;
  1337. int GetDayOfWeek() const; // 1=Sun, 2=Mon, ..., 7=Sat
  1338. // Operations
  1339. // time math
  1340. CTimeSpan operator-(CTime time) const;
  1341. CTime operator-(CTimeSpan timeSpan) const;
  1342. CTime operator+(CTimeSpan timeSpan) const;
  1343. const CTime& operator+=(CTimeSpan timeSpan);
  1344. const CTime& operator-=(CTimeSpan timeSpan);
  1345. BOOL operator==(CTime time) const;
  1346. BOOL operator!=(CTime time) const;
  1347. BOOL operator<(CTime time) const;
  1348. BOOL operator>(CTime time) const;
  1349. BOOL operator<=(CTime time) const;
  1350. BOOL operator>=(CTime time) const;
  1351. // formatting using "C" strftime
  1352. CString Format(LPCTSTR pFormat) const;
  1353. CString FormatGmt(LPCTSTR pFormat) const;
  1354. CString Format(UINT nFormatID) const;
  1355. CString FormatGmt(UINT nFormatID) const;
  1356. #ifdef _UNICODE
  1357. // for compatibility with MFC 3.x
  1358. CString Format(LPCSTR pFormat) const;
  1359. CString FormatGmt(LPCSTR pFormat) const;
  1360. #endif
  1361. // serialization
  1362. #ifdef _DEBUG
  1363. friend CDumpContext& AFXAPI operator<<(CDumpContext& dc, CTime time);
  1364. #endif
  1365. friend CArchive& AFXAPI operator<<(CArchive& ar, CTime time);
  1366. friend CArchive& AFXAPI operator>>(CArchive& ar, CTime& rtime);
  1367. private:
  1368. time_t m_time;
  1369. };
  1370. /////////////////////////////////////////////////////////////////////////////
  1371. // File status
  1372. struct CFileStatus
  1373. {
  1374. CTime m_ctime; // creation date/time of file
  1375. CTime m_mtime; // last modification date/time of file
  1376. CTime m_atime; // last access date/time of file
  1377. LONG m_size; // logical size of file in bytes
  1378. BYTE m_attribute; // logical OR of CFile::Attribute enum values
  1379. BYTE _m_padding; // pad the structure to a WORD
  1380. TCHAR m_szFullName[_MAX_PATH]; // absolute path name
  1381. #ifdef _DEBUG
  1382. void Dump(CDumpContext& dc) const;
  1383. #endif
  1384. };
  1385. /////////////////////////////////////////////////////////////////////////////
  1386. // Diagnostic memory management routines
  1387. // Low level sanity checks for memory blocks
  1388. BOOL AFXAPI AfxIsValidAddress(const void* lp,
  1389. UINT_PTR nBytes, BOOL bReadWrite = TRUE);
  1390. BOOL AFXAPI AfxIsValidString(LPCWSTR lpsz, int nLength = -1);
  1391. BOOL AFXAPI AfxIsValidString(LPCSTR lpsz, int nLength = -1);
  1392. #if defined(_DEBUG) && !defined(_AFX_NO_DEBUG_CRT)
  1393. // Memory tracking allocation
  1394. void* AFX_CDECL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
  1395. #define DEBUG_NEW new(THIS_FILE, __LINE__)
  1396. #if (_MSC_VER >= 1200) && (_MFC_VER >= 0x0600)
  1397. void AFX_CDECL operator delete(void* p, LPCSTR lpszFileName, int nLine);
  1398. #endif
  1399. void* AFXAPI AfxAllocMemoryDebug(size_t nSize, BOOL bIsObject,
  1400. LPCSTR lpszFileName, int nLine);
  1401. void AFXAPI AfxFreeMemoryDebug(void* pbData, BOOL bIsObject);
  1402. // Dump any memory leaks since program started
  1403. BOOL AFXAPI AfxDumpMemoryLeaks();
  1404. // Return TRUE if valid memory block of nBytes
  1405. BOOL AFXAPI AfxIsMemoryBlock(const void* p, UINT nBytes,
  1406. LONG* plRequestNumber = NULL);
  1407. // Return TRUE if memory is sane or print out what is wrong
  1408. BOOL AFXAPI AfxCheckMemory();
  1409. #define afxMemDF _crtDbgFlag
  1410. enum AfxMemDF // memory debug/diagnostic flags
  1411. {
  1412. allocMemDF = 0x01, // turn on debugging allocator
  1413. delayFreeMemDF = 0x02, // delay freeing memory
  1414. checkAlwaysMemDF = 0x04 // AfxCheckMemory on every alloc/free
  1415. };
  1416. #ifdef _UNICODE
  1417. #define AfxOutputDebugString(lpsz) \
  1418. do \
  1419. { \
  1420. USES_CONVERSION; \
  1421. _RPT0(_CRT_WARN, W2CA(lpsz)); \
  1422. } while (0)
  1423. #else
  1424. #define AfxOutputDebugString(lpsz) _RPT0(_CRT_WARN, lpsz)
  1425. #endif
  1426. // turn on/off tracking for a short while
  1427. BOOL AFXAPI AfxEnableMemoryTracking(BOOL bTrack);
  1428. // Advanced initialization: for overriding default diagnostics
  1429. BOOL AFXAPI AfxDiagnosticInit(void);
  1430. // A failure hook returns whether to permit allocation
  1431. typedef BOOL (AFXAPI* AFX_ALLOC_HOOK)(size_t nSize, BOOL bObject, LONG lRequestNumber);
  1432. // Set new hook, return old (never NULL)
  1433. AFX_ALLOC_HOOK AFXAPI AfxSetAllocHook(AFX_ALLOC_HOOK pfnAllocHook);
  1434. // Debugger hook on specified allocation request - Obsolete
  1435. void AFXAPI AfxSetAllocStop(LONG lRequestNumber);
  1436. // Memory state for snapshots/leak detection
  1437. struct CMemoryState
  1438. {
  1439. // Attributes
  1440. enum blockUsage
  1441. {
  1442. freeBlock, // memory not used
  1443. objectBlock, // contains a CObject derived class object
  1444. bitBlock, // contains ::operator new data
  1445. crtBlock,
  1446. ignoredBlock,
  1447. nBlockUseMax // total number of usages
  1448. };
  1449. _CrtMemState m_memState;
  1450. LONG_PTR m_lCounts[nBlockUseMax];
  1451. LONG_PTR m_lSizes[nBlockUseMax];
  1452. LONG_PTR m_lHighWaterCount;
  1453. LONG_PTR m_lTotalCount;
  1454. CMemoryState();
  1455. // Operations
  1456. void Checkpoint(); // fill with current state
  1457. BOOL Difference(const CMemoryState& oldState,
  1458. const CMemoryState& newState); // fill with difference
  1459. void UpdateData();
  1460. // Output to afxDump
  1461. void DumpStatistics() const;
  1462. void DumpAllObjectsSince() const;
  1463. };
  1464. // Enumerate allocated objects or runtime classes
  1465. void AFXAPI AfxDoForAllObjects(void (AFX_CDECL *pfn)(CObject* pObject, void* pContext),
  1466. void* pContext);
  1467. void AFXAPI AfxDoForAllClasses(void (AFX_CDECL *pfn)(const CRuntimeClass* pClass,
  1468. void* pContext), void* pContext);
  1469. #else
  1470. // non-_DEBUG_ALLOC version that assume everything is OK
  1471. #define DEBUG_NEW new
  1472. #define AfxCheckMemory() TRUE
  1473. #define AfxIsMemoryBlock(p, nBytes) TRUE
  1474. #define AfxEnableMemoryTracking(bTrack) FALSE
  1475. #define AfxOutputDebugString(lpsz) ::OutputDebugString(lpsz)
  1476. // diagnostic initialization
  1477. #ifndef _DEBUG
  1478. #define AfxDiagnosticInit() TRUE
  1479. #else
  1480. BOOL AFXAPI AfxDiagnosticInit(void);
  1481. #endif
  1482. #endif // _DEBUG
  1483. /////////////////////////////////////////////////////////////////////////////
  1484. // Archives for serializing CObject data
  1485. // needed for implementation
  1486. class CPtrArray;
  1487. class CMapPtrToPtr;
  1488. class CDocument;
  1489. class CArchive
  1490. {
  1491. public:
  1492. // Flag values
  1493. enum Mode { store = 0, load = 1, bNoFlushOnDelete = 2, bNoByteSwap = 4 };
  1494. CArchive(CFile* pFile, UINT nMode, int nBufSize = 4096, void* lpBuf = NULL);
  1495. ~CArchive();
  1496. // Attributes
  1497. BOOL IsLoading() const;
  1498. BOOL IsStoring() const;
  1499. BOOL IsByteSwapping() const;
  1500. BOOL IsBufferEmpty() const;
  1501. CFile* GetFile() const;
  1502. UINT GetObjectSchema(); // only valid when reading a CObject*
  1503. void SetObjectSchema(UINT nSchema);
  1504. // pointer to document being serialized -- must set to serialize
  1505. // COleClientItems in a document!
  1506. CDocument* m_pDocument;
  1507. // Operations
  1508. UINT Read(void* lpBuf, UINT nMax);
  1509. void Write(const void* lpBuf, UINT nMax);
  1510. void Flush();
  1511. void Close();
  1512. void Abort(); // close and shutdown without exceptions
  1513. // reading and writing strings
  1514. void WriteString(LPCTSTR lpsz);
  1515. LPTSTR ReadString(LPTSTR lpsz, UINT nMax);
  1516. BOOL ReadString(CString& rString);
  1517. public:
  1518. // Object I/O is pointer based to avoid added construction overhead.
  1519. // Use the Serialize member function directly for embedded objects.
  1520. friend CArchive& AFXAPI operator<<(CArchive& ar, const CObject* pOb);
  1521. friend CArchive& AFXAPI operator>>(CArchive& ar, CObject*& pOb);
  1522. friend CArchive& AFXAPI operator>>(CArchive& ar, const CObject*& pOb);
  1523. // insertion operations
  1524. CArchive& operator<<(BYTE by);
  1525. CArchive& operator<<(WORD w);
  1526. CArchive& operator<<(LONG l);
  1527. CArchive& operator<<(DWORD dw);
  1528. CArchive& operator<<(ULONGLONG qw);
  1529. CArchive& operator<<(float f);
  1530. CArchive& operator<<(double d);
  1531. CArchive& operator<<(int i);
  1532. CArchive& operator<<(short w);
  1533. CArchive& operator<<(char ch);
  1534. CArchive& operator<<(unsigned u);
  1535. // extraction operations
  1536. CArchive& operator>>(BYTE& by);
  1537. CArchive& operator>>(WORD& w);
  1538. CArchive& operator>>(DWORD& dw);
  1539. CArchive& operator>>(LONG& l);
  1540. CArchive& operator>>(ULONGLONG& qw);
  1541. CArchive& operator>>(float& f);
  1542. CArchive& operator>>(double& d);
  1543. CArchive& operator>>(int& i);
  1544. CArchive& operator>>(short& w);
  1545. CArchive& operator>>(char& ch);
  1546. CArchive& operator>>(unsigned& u);
  1547. // object read/write
  1548. CObject* ReadObject(const CRuntimeClass* pClass);
  1549. void WriteObject(const CObject* pOb);
  1550. // advanced object mapping (used for forced references)
  1551. void MapObject(const CObject* pOb);
  1552. // advanced versioning support
  1553. void WriteClass(const CRuntimeClass* pClassRef);
  1554. CRuntimeClass* ReadClass(const CRuntimeClass* pClassRefRequested = NULL,
  1555. UINT* pSchema = NULL, DWORD* pObTag = NULL);
  1556. void SerializeClass(const CRuntimeClass* pClassRef);
  1557. // advanced operations (used when storing/loading many objects)
  1558. void SetStoreParams(UINT nHashSize = 2053, UINT nBlockSize = 128);
  1559. void SetLoadParams(UINT nGrowBy = 1024);
  1560. // Implementation
  1561. public:
  1562. BOOL m_bForceFlat; // for COleClientItem implementation (default TRUE)
  1563. BOOL m_bDirectBuffer; // TRUE if m_pFile supports direct buffering
  1564. void FillBuffer(UINT nBytesNeeded);
  1565. void CheckCount(); // throw exception if m_nMapCount is too large
  1566. // special functions for reading and writing (16-bit compatible) counts
  1567. DWORD_PTR ReadCount();
  1568. void WriteCount(DWORD_PTR dwCount);
  1569. // public for advanced use
  1570. UINT m_nObjectSchema;
  1571. CString m_strFileName;
  1572. protected:
  1573. // archive objects cannot be copied or assigned
  1574. CArchive(const CArchive& arSrc);
  1575. void operator=(const CArchive& arSrc);
  1576. BOOL m_nMode;
  1577. BOOL m_bUserBuf;
  1578. int m_nBufSize;
  1579. CFile* m_pFile;
  1580. BYTE* m_lpBufCur;
  1581. BYTE* m_lpBufMax;
  1582. BYTE* m_lpBufStart;
  1583. // array/map for CObject* and CRuntimeClass* load/store
  1584. UINT m_nMapCount;
  1585. union
  1586. {
  1587. CPtrArray* m_pLoadArray;
  1588. CMapPtrToPtr* m_pStoreMap;
  1589. };
  1590. // map to keep track of mismatched schemas
  1591. CMapPtrToPtr* m_pSchemaMap;
  1592. // advanced parameters (controls performance with large archives)
  1593. UINT m_nGrowSize;
  1594. UINT m_nHashSize;
  1595. };
  1596. /////////////////////////////////////////////////////////////////////////////
  1597. // Diagnostic dumping
  1598. #if _MFC_VER >= 0x0600
  1599. // Note: AfxDumpStack is available in release builds, although it is always
  1600. // statically linked so as to not negatively affect the size of MFC42.DLL.
  1601. #define AFX_STACK_DUMP_TARGET_TRACE 0x0001
  1602. #define AFX_STACK_DUMP_TARGET_CLIPBOARD 0x0002
  1603. #define AFX_STACK_DUMP_TARGET_BOTH 0x0003
  1604. #define AFX_STACK_DUMP_TARGET_ODS 0x0004
  1605. #ifdef _DEBUG
  1606. #define AFX_STACK_DUMP_TARGET_DEFAULT AFX_STACK_DUMP_TARGET_TRACE
  1607. #else
  1608. #define AFX_STACK_DUMP_TARGET_DEFAULT AFX_STACK_DUMP_TARGET_CLIPBOARD
  1609. #endif
  1610. void AFXAPI AfxDumpStack(DWORD dwFlags = AFX_STACK_DUMP_TARGET_DEFAULT);
  1611. #endif
  1612. class CDumpContext
  1613. {
  1614. public:
  1615. CDumpContext(CFile* pFile = NULL);
  1616. // Attributes
  1617. int GetDepth() const; // 0 => this object, 1 => children objects
  1618. void SetDepth(int nNewDepth);
  1619. // Operations
  1620. CDumpContext& operator<<(LPCTSTR lpsz);
  1621. #ifdef _UNICODE
  1622. CDumpContext& operator<<(LPCSTR lpsz); // automatically widened
  1623. #else
  1624. CDumpContext& operator<<(LPCWSTR lpsz); // automatically thinned
  1625. #endif
  1626. CDumpContext& operator<<(const void* lp);
  1627. CDumpContext& operator<<(const CObject* pOb);
  1628. CDumpContext& operator<<(const CObject& ob);
  1629. CDumpContext& operator<<(BYTE by);
  1630. CDumpContext& operator<<(WORD w);
  1631. CDumpContext& operator<<(UINT u);
  1632. CDumpContext& operator<<(LONG l);
  1633. CDumpContext& operator<<(DWORD dw);
  1634. CDumpContext& operator<<(float f);
  1635. CDumpContext& operator<<(double d);
  1636. CDumpContext& operator<<(int n);
  1637. #ifdef _WIN64
  1638. CDumpContext& operator<<(__int64 n);
  1639. CDumpContext& operator<<(unsigned __int64 n);
  1640. #endif
  1641. void HexDump(LPCTSTR lpszLine, BYTE* pby, int nBytes, int nWidth);
  1642. void Flush();
  1643. // Implementation
  1644. protected:
  1645. // dump context objects cannot be copied or assigned
  1646. CDumpContext(const CDumpContext& dcSrc);
  1647. void operator=(const CDumpContext& dcSrc);
  1648. void OutputString(LPCTSTR lpsz);
  1649. int m_nDepth;
  1650. public:
  1651. CFile* m_pFile;
  1652. };
  1653. #ifdef _DEBUG
  1654. extern AFX_DATA CDumpContext afxDump;
  1655. extern AFX_DATA BOOL afxTraceEnabled;
  1656. #endif
  1657. /////////////////////////////////////////////////////////////////////////////
  1658. // Special include for Win32s compatibility
  1659. #ifdef _AFX_PACKING
  1660. #pragma pack(pop)
  1661. #endif
  1662. #ifndef __AFXCOLL_H__
  1663. #include <afxcoll.h>
  1664. #ifndef __AFXSTATE_H__
  1665. #include <afxstat_.h> // for _AFX_APP_STATE and _AFX_THREAD_STATE
  1666. #endif
  1667. #endif
  1668. /////////////////////////////////////////////////////////////////////////////
  1669. // Inline function declarations
  1670. #ifdef _AFX_ENABLE_INLINES
  1671. #define _AFX_INLINE AFX_INLINE
  1672. #if !defined(_AFX_CORE_IMPL) || !defined(_AFXDLL) || defined(_DEBUG)
  1673. #define _AFX_PUBLIC_INLINE AFX_INLINE
  1674. #else
  1675. #define _AFX_PUBLIC_INLINE
  1676. #endif
  1677. #include <afx.inl>
  1678. #endif
  1679. #undef AFX_DATA
  1680. #define AFX_DATA
  1681. #ifdef _AFX_MINREBUILD
  1682. #pragma component(minrebuild, on)
  1683. #endif
  1684. #ifndef _AFX_FULLTYPEINFO
  1685. #pragma component(mintypeinfo, off)
  1686. #endif
  1687. #endif // __AFX_H__
  1688. /////////////////////////////////////////////////////////////////////////////