afx.h 59 KB

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