afx.h 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003
  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. #ifndef WINSCP
  740. virtual int ReportError(UINT nType = MB_OK, UINT nMessageID = 0);
  741. #endif
  742. // Implementation (setting m_bAutoDelete to FALSE is advanced)
  743. public:
  744. virtual ~CException();
  745. BOOL m_bAutoDelete;
  746. #ifdef MFC_DEBUG
  747. void PASCAL operator delete(void* pbData);
  748. #if 0 // __BORLANDC__ was _MSC_VER >= 1200
  749. void PASCAL operator delete(void* pbData, LPCSTR lpszFileName, int nLine);
  750. #endif
  751. protected:
  752. BOOL m_bReadyForDelete;
  753. #endif
  754. };
  755. #ifdef _AFXDLL
  756. class CSimpleException : public CException
  757. #else
  758. class AFX_NOVTABLE CSimpleException : public CException
  759. #endif
  760. {
  761. // base class for resource-critical MFC exceptions
  762. // handles ownership and initialization of an error message
  763. public:
  764. // Constructors
  765. CSimpleException();
  766. CSimpleException(BOOL bAutoDelete);
  767. // Operations
  768. virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
  769. PUINT pnHelpContext = NULL);
  770. // Implementation (setting m_bAutoDelete to FALSE is advanced)
  771. public:
  772. virtual ~CSimpleException();
  773. BOOL m_bAutoDelete;
  774. void InitString(); // used during MFC initialization
  775. protected:
  776. BOOL m_bInitialized;
  777. BOOL m_bLoaded;
  778. TCHAR m_szMessage[128];
  779. UINT m_nResourceID;
  780. #ifdef MFC_DEBUG
  781. BOOL m_bReadyForDelete;
  782. #endif
  783. };
  784. // helper routines for non-C++ EH implementations
  785. #ifdef _AFX_OLD_EXCEPTIONS
  786. BOOL AFXAPI AfxCatchProc(CRuntimeClass* pClass);
  787. void AFXAPI AfxThrow(CException* pException);
  788. #else
  789. // for THROW_LAST auto-delete backward compatiblity
  790. void AFXAPI AfxThrowLastCleanup();
  791. #endif
  792. // other out-of-line helper functions
  793. void AFXAPI AfxTryCleanup();
  794. #ifndef _AFX_JUMPBUF
  795. // Use portable 'jmp_buf' defined by ANSI by default.
  796. #define _AFX_JUMPBUF jmp_buf
  797. #endif
  798. // Placed on frame for EXCEPTION linkage, or CException cleanup
  799. struct AFX_EXCEPTION_LINK
  800. {
  801. #ifdef _AFX_OLD_EXCEPTIONS
  802. union
  803. {
  804. _AFX_JUMPBUF m_jumpBuf;
  805. struct
  806. {
  807. void (PASCAL* pfnCleanup)(AFX_EXCEPTION_LINK* pLink);
  808. void* pvData; // extra data follows
  809. } m_callback; // callback for cleanup (nType != 0)
  810. };
  811. UINT m_nType; // 0 for setjmp, !=0 for user extension
  812. #endif //!_AFX_OLD_EXCEPTIONS
  813. AFX_EXCEPTION_LINK* m_pLinkPrev; // previous top, next in handler chain
  814. CException* m_pException; // current exception (NULL in TRY block)
  815. AFX_EXCEPTION_LINK(); // for initialization and linking
  816. ~AFX_EXCEPTION_LINK() // for cleanup and unlinking
  817. { AfxTryCleanup(); };
  818. };
  819. // Exception global state - never access directly
  820. struct AFX_EXCEPTION_CONTEXT
  821. {
  822. AFX_EXCEPTION_LINK* m_pLinkTop;
  823. // Note: most of the exception context is now in the AFX_EXCEPTION_LINK
  824. };
  825. #ifndef _PNH_DEFINED
  826. typedef int (__cdecl * _PNH)( size_t );
  827. #define _PNH_DEFINED
  828. #endif
  829. _PNH AFXAPI AfxGetNewHandler();
  830. _PNH AFXAPI AfxSetNewHandler(_PNH pfnNewHandler);
  831. int AFX_CDECL AfxNewHandler(size_t nSize);
  832. void AFXAPI AfxAbort();
  833. #ifdef _AFX_OLD_EXCEPTIONS
  834. // Obsolete and non-portable: setting terminate handler
  835. // use CWinApp::ProcessWndProcException for Windows apps instead
  836. // can also use set_terminate which is part of C++ standard library
  837. // (these are provided for backward compatibility)
  838. void AFXAPI AfxTerminate();
  839. typedef void (AFXAPI* AFX_TERM_PROC)();
  840. AFX_TERM_PROC AFXAPI AfxSetTerminate(AFX_TERM_PROC);
  841. #endif
  842. /////////////////////////////////////////////////////////////////////////////
  843. // Exception macros using try, catch and throw
  844. // (for backward compatibility to previous versions of MFC)
  845. #ifndef _AFX_OLD_EXCEPTIONS
  846. #define TRY { AFX_EXCEPTION_LINK _afxExceptionLink; try {
  847. #define CATCH(class, e) } catch (class* e) \
  848. { ASSERT(e->IsKindOf(RUNTIME_CLASS(class))); \
  849. _afxExceptionLink.m_pException = e;
  850. #define AND_CATCH(class, e) } catch (class* e) \
  851. { ASSERT(e->IsKindOf(RUNTIME_CLASS(class))); \
  852. _afxExceptionLink.m_pException = e;
  853. #define END_CATCH } }
  854. #define THROW(e) throw e
  855. #define THROW_LAST() (AfxThrowLastCleanup(), throw)
  856. // Advanced macros for smaller code
  857. #define CATCH_ALL(e) } catch (CException* e) \
  858. { { ASSERT(e->IsKindOf(RUNTIME_CLASS(CException))); \
  859. _afxExceptionLink.m_pException = e;
  860. #define AND_CATCH_ALL(e) } catch (CException* e) \
  861. { { ASSERT(e->IsKindOf(RUNTIME_CLASS(CException))); \
  862. _afxExceptionLink.m_pException = e;
  863. #define END_CATCH_ALL } } }
  864. #define END_TRY } catch (CException* e) \
  865. { ASSERT(e->IsKindOf(RUNTIME_CLASS(CException))); \
  866. _afxExceptionLink.m_pException = e; } }
  867. #else //_AFX_OLD_EXCEPTIONS
  868. /////////////////////////////////////////////////////////////////////////////
  869. // Exception macros using setjmp and longjmp
  870. // (for portability to compilers with no support for C++ exception handling)
  871. #define TRY \
  872. { AFX_EXCEPTION_LINK _afxExceptionLink; \
  873. if (::setjmp(_afxExceptionLink.m_jumpBuf) == 0)
  874. #define CATCH(class, e) \
  875. else if (::AfxCatchProc(RUNTIME_CLASS(class))) \
  876. { class* e = (class*)_afxExceptionLink.m_pException;
  877. #define AND_CATCH(class, e) \
  878. } else if (::AfxCatchProc(RUNTIME_CLASS(class))) \
  879. { class* e = (class*)_afxExceptionLink.m_pException;
  880. #define END_CATCH \
  881. } else { ::AfxThrow(NULL); } }
  882. #define THROW(e) AfxThrow(e)
  883. #define THROW_LAST() AfxThrow(NULL)
  884. // Advanced macros for smaller code
  885. #define CATCH_ALL(e) \
  886. else { CException* e = _afxExceptionLink.m_pException;
  887. #define AND_CATCH_ALL(e) \
  888. } else { CException* e = _afxExceptionLink.m_pException;
  889. #define END_CATCH_ALL } }
  890. #define END_TRY }
  891. #endif //_AFX_OLD_EXCEPTIONS
  892. /////////////////////////////////////////////////////////////////////////////
  893. // Standard Exception classes
  894. class CMemoryException : public CSimpleException
  895. {
  896. DECLARE_DYNAMIC(CMemoryException)
  897. public:
  898. CMemoryException();
  899. // Implementation
  900. public:
  901. CMemoryException(BOOL bAutoDelete);
  902. CMemoryException(BOOL bAutoDelete, UINT nResourceID);
  903. virtual ~CMemoryException();
  904. };
  905. class CNotSupportedException : public CSimpleException
  906. {
  907. DECLARE_DYNAMIC(CNotSupportedException)
  908. public:
  909. CNotSupportedException();
  910. // Implementation
  911. public:
  912. CNotSupportedException(BOOL bAutoDelete);
  913. CNotSupportedException(BOOL bAutoDelete, UINT nResourceID);
  914. virtual ~CNotSupportedException();
  915. };
  916. class CArchiveException : public CException
  917. {
  918. DECLARE_DYNAMIC(CArchiveException)
  919. public:
  920. enum {
  921. none,
  922. generic,
  923. readOnly,
  924. endOfFile,
  925. writeOnly,
  926. badIndex,
  927. badClass,
  928. badSchema
  929. };
  930. // Constructor
  931. CArchiveException(int cause = CArchiveException::none,
  932. LPCTSTR lpszArchiveName = NULL);
  933. // Attributes
  934. int m_cause;
  935. CString m_strFileName;
  936. // Implementation
  937. public:
  938. virtual ~CArchiveException();
  939. #ifdef MFC_DEBUG
  940. virtual void Dump(CDumpContext& dc) const;
  941. #endif
  942. virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
  943. PUINT pnHelpContext = NULL);
  944. };
  945. class CFileException : public CException
  946. {
  947. DECLARE_DYNAMIC(CFileException)
  948. public:
  949. enum {
  950. none,
  951. generic,
  952. fileNotFound,
  953. badPath,
  954. tooManyOpenFiles,
  955. accessDenied,
  956. invalidFile,
  957. removeCurrentDir,
  958. directoryFull,
  959. badSeek,
  960. hardIO,
  961. sharingViolation,
  962. lockViolation,
  963. diskFull,
  964. endOfFile
  965. };
  966. // Constructor
  967. CFileException(int cause = CFileException::none, LONG lOsError = -1,
  968. LPCTSTR lpszArchiveName = NULL);
  969. // Attributes
  970. int m_cause;
  971. LONG m_lOsError;
  972. CString m_strFileName;
  973. // Operations
  974. // convert a OS dependent error code to a Cause
  975. static int PASCAL OsErrorToException(LONG lOsError);
  976. static int PASCAL ErrnoToException(int nErrno);
  977. // helper functions to throw exception after converting to a Cause
  978. static void PASCAL ThrowOsError(LONG lOsError, LPCTSTR lpszFileName = NULL);
  979. static void PASCAL ThrowErrno(int nErrno, LPCTSTR lpszFileName = NULL);
  980. // Implementation
  981. public:
  982. virtual ~CFileException();
  983. #ifdef MFC_DEBUG
  984. virtual void Dump(CDumpContext&) const;
  985. #endif
  986. virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
  987. PUINT pnHelpContext = NULL);
  988. };
  989. /////////////////////////////////////////////////////////////////////////////
  990. // Standard exception throws
  991. void AFXAPI AfxThrowMemoryException();
  992. void AFXAPI AfxThrowNotSupportedException();
  993. void AFXAPI AfxThrowArchiveException(int cause,
  994. LPCTSTR lpszArchiveName = NULL);
  995. void AFXAPI AfxThrowFileException(int cause, LONG lOsError = -1,
  996. LPCTSTR lpszFileName = NULL);
  997. /////////////////////////////////////////////////////////////////////////////
  998. // File - raw unbuffered disk file I/O
  999. class CFile : public CObject
  1000. {
  1001. DECLARE_DYNAMIC(CFile)
  1002. public:
  1003. // Flag values
  1004. enum OpenFlags {
  1005. modeRead = 0x0000,
  1006. modeWrite = 0x0001,
  1007. modeReadWrite = 0x0002,
  1008. shareCompat = 0x0000,
  1009. shareExclusive = 0x0010,
  1010. shareDenyWrite = 0x0020,
  1011. shareDenyRead = 0x0030,
  1012. shareDenyNone = 0x0040,
  1013. modeNoInherit = 0x0080,
  1014. modeCreate = 0x1000,
  1015. modeNoTruncate = 0x2000,
  1016. typeText = 0x4000, // typeText and typeBinary are used in
  1017. typeBinary = (int)0x8000 // derived classes only
  1018. };
  1019. enum Attribute {
  1020. normal = 0x00,
  1021. readOnly = 0x01,
  1022. hidden = 0x02,
  1023. system = 0x04,
  1024. volume = 0x08,
  1025. directory = 0x10,
  1026. archive = 0x20
  1027. };
  1028. enum SeekPosition { begin = 0x0, current = 0x1, end = 0x2 };
  1029. enum { hFileNull = -1 };
  1030. // Constructors
  1031. CFile();
  1032. CFile(int hFile);
  1033. CFile(LPCTSTR lpszFileName, UINT nOpenFlags);
  1034. // Attributes
  1035. UINT m_hFile;
  1036. operator HFILE() const;
  1037. virtual DWORD GetPosition() const;
  1038. BOOL GetStatus(CFileStatus& rStatus) const;
  1039. #ifndef WINSCP
  1040. virtual CString GetFileName() const;
  1041. virtual CString GetFileTitle() const;
  1042. #endif
  1043. virtual CString GetFilePath() const;
  1044. virtual void SetFilePath(LPCTSTR lpszNewName);
  1045. // Operations
  1046. virtual BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags,
  1047. CFileException* pError = NULL);
  1048. static void PASCAL Rename(LPCTSTR lpszOldName,
  1049. LPCTSTR lpszNewName);
  1050. static void PASCAL Remove(LPCTSTR lpszFileName);
  1051. static BOOL PASCAL GetStatus(LPCTSTR lpszFileName,
  1052. CFileStatus& rStatus);
  1053. static void PASCAL SetStatus(LPCTSTR lpszFileName,
  1054. const CFileStatus& status);
  1055. DWORD SeekToEnd();
  1056. void SeekToBegin();
  1057. // backward compatible ReadHuge and WriteHuge
  1058. DWORD ReadHuge(void* lpBuffer, DWORD dwCount);
  1059. void WriteHuge(const void* lpBuffer, DWORD dwCount);
  1060. // Overridables
  1061. virtual CFile* Duplicate() const;
  1062. virtual LONG Seek(LONG lOff, UINT nFrom);
  1063. virtual void SetLength(DWORD dwNewLen);
  1064. virtual DWORD GetLength() const;
  1065. virtual UINT Read(void* lpBuf, UINT nCount);
  1066. virtual void Write(const void* lpBuf, UINT nCount);
  1067. virtual void LockRange(DWORD dwPos, DWORD dwCount);
  1068. virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
  1069. virtual void Abort();
  1070. virtual void Flush();
  1071. virtual void Close();
  1072. // Implementation
  1073. public:
  1074. virtual ~CFile();
  1075. #ifdef MFC_DEBUG
  1076. virtual void AssertValid() const;
  1077. virtual void Dump(CDumpContext& dc) const;
  1078. #endif
  1079. enum BufferCommand { bufferRead, bufferWrite, bufferCommit, bufferCheck };
  1080. virtual UINT GetBufferPtr(UINT nCommand, UINT nCount = 0,
  1081. void** ppBufStart = NULL, void** ppBufMax = NULL);
  1082. protected:
  1083. BOOL m_bCloseOnDelete;
  1084. CString m_strFileName;
  1085. };
  1086. /////////////////////////////////////////////////////////////////////////////
  1087. // STDIO file implementation
  1088. class CStdioFile : public CFile
  1089. {
  1090. DECLARE_DYNAMIC(CStdioFile)
  1091. public:
  1092. // Constructors
  1093. CStdioFile();
  1094. CStdioFile(FILE* pOpenStream);
  1095. CStdioFile(LPCTSTR lpszFileName, UINT nOpenFlags);
  1096. // Attributes
  1097. FILE* m_pStream; // stdio FILE
  1098. // m_hFile from base class is _fileno(m_pStream)
  1099. // Operations
  1100. // reading and writing strings
  1101. virtual void WriteString(LPCTSTR lpsz);
  1102. virtual LPTSTR ReadString(LPTSTR lpsz, UINT nMax);
  1103. virtual BOOL ReadString(CString& rString);
  1104. // Implementation
  1105. public:
  1106. virtual ~CStdioFile();
  1107. #ifdef MFC_DEBUG
  1108. void Dump(CDumpContext& dc) const;
  1109. #endif
  1110. virtual DWORD GetPosition() const;
  1111. virtual BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags,
  1112. CFileException* pError = NULL);
  1113. virtual UINT Read(void* lpBuf, UINT nCount);
  1114. virtual void Write(const void* lpBuf, UINT nCount);
  1115. virtual LONG Seek(LONG lOff, UINT nFrom);
  1116. virtual void Abort();
  1117. virtual void Flush();
  1118. virtual void Close();
  1119. // Unsupported APIs
  1120. virtual CFile* Duplicate() const;
  1121. virtual void LockRange(DWORD dwPos, DWORD dwCount);
  1122. virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
  1123. };
  1124. ////////////////////////////////////////////////////////////////////////////
  1125. // Memory based file implementation
  1126. class CMemFile : public CFile
  1127. {
  1128. DECLARE_DYNAMIC(CMemFile)
  1129. public:
  1130. // Constructors
  1131. CMemFile(UINT nGrowBytes = 1024);
  1132. CMemFile(BYTE* lpBuffer, UINT nBufferSize, UINT nGrowBytes = 0);
  1133. // Operations
  1134. void Attach(BYTE* lpBuffer, UINT nBufferSize, UINT nGrowBytes = 0);
  1135. BYTE* Detach();
  1136. // Advanced Overridables
  1137. protected:
  1138. virtual BYTE* Alloc(DWORD nBytes);
  1139. virtual BYTE* Realloc(BYTE* lpMem, DWORD nBytes);
  1140. virtual BYTE* Memcpy(BYTE* lpMemTarget, const BYTE* lpMemSource, UINT nBytes);
  1141. virtual void Free(BYTE* lpMem);
  1142. virtual void GrowFile(DWORD dwNewLen);
  1143. // Implementation
  1144. protected:
  1145. UINT m_nGrowBytes;
  1146. DWORD m_nPosition;
  1147. DWORD m_nBufferSize;
  1148. DWORD m_nFileSize;
  1149. BYTE* m_lpBuffer;
  1150. BOOL m_bAutoDelete;
  1151. public:
  1152. virtual ~CMemFile();
  1153. #ifdef MFC_DEBUG
  1154. virtual void Dump(CDumpContext& dc) const;
  1155. virtual void AssertValid() const;
  1156. #endif
  1157. virtual DWORD GetPosition() const;
  1158. BOOL GetStatus(CFileStatus& rStatus) const;
  1159. virtual LONG Seek(LONG lOff, UINT nFrom);
  1160. virtual void SetLength(DWORD dwNewLen);
  1161. virtual UINT Read(void* lpBuf, UINT nCount);
  1162. virtual void Write(const void* lpBuf, UINT nCount);
  1163. virtual void Abort();
  1164. virtual void Flush();
  1165. virtual void Close();
  1166. virtual UINT GetBufferPtr(UINT nCommand, UINT nCount = 0,
  1167. void** ppBufStart = NULL, void** ppBufMax = NULL);
  1168. // Unsupported APIs
  1169. virtual CFile* Duplicate() const;
  1170. virtual void LockRange(DWORD dwPos, DWORD dwCount);
  1171. virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
  1172. };
  1173. ////////////////////////////////////////////////////////////////////////////
  1174. // Local file searches
  1175. class CFileFind : public CObject
  1176. {
  1177. public:
  1178. CFileFind();
  1179. virtual ~CFileFind();
  1180. // Attributes
  1181. public:
  1182. DWORD GetLength() const;
  1183. #if defined(_X86_) || defined(_ALPHA_)
  1184. __int64 GetLength64() const;
  1185. #endif
  1186. virtual CString GetFileName() const;
  1187. virtual CString GetFilePath() const;
  1188. virtual CString GetFileTitle() const;
  1189. virtual CString GetFileURL() const;
  1190. virtual CString GetRoot() const;
  1191. virtual BOOL GetLastWriteTime(FILETIME* pTimeStamp) const;
  1192. virtual BOOL GetLastAccessTime(FILETIME* pTimeStamp) const;
  1193. virtual BOOL GetCreationTime(FILETIME* pTimeStamp) const;
  1194. virtual BOOL GetLastWriteTime(CTime& refTime) const;
  1195. virtual BOOL GetLastAccessTime(CTime& refTime) const;
  1196. virtual BOOL GetCreationTime(CTime& refTime) const;
  1197. virtual BOOL MatchesMask(DWORD dwMask) const;
  1198. virtual BOOL IsDots() const;
  1199. // these aren't virtual because they all use MatchesMask(), which is
  1200. BOOL IsReadOnly() const;
  1201. BOOL IsDirectory() const;
  1202. BOOL IsCompressed() const;
  1203. BOOL IsSystem() const;
  1204. BOOL IsHidden() const;
  1205. BOOL IsTemporary() const;
  1206. BOOL IsNormal() const;
  1207. BOOL IsArchived() const;
  1208. // Operations
  1209. void Close();
  1210. virtual BOOL FindFile(LPCTSTR pstrName = NULL, DWORD dwUnused = 0);
  1211. virtual BOOL FindNextFile();
  1212. protected:
  1213. virtual void CloseContext();
  1214. // Implementation
  1215. protected:
  1216. void* m_pFoundInfo;
  1217. void* m_pNextInfo;
  1218. HANDLE m_hContext;
  1219. BOOL m_bGotLast;
  1220. CString m_strRoot;
  1221. TCHAR m_chDirSeparator; // not '\\' for Internet classes
  1222. #ifdef MFC_DEBUG
  1223. void Dump(CDumpContext& dc) const;
  1224. void AssertValid() const;
  1225. #endif
  1226. DECLARE_DYNAMIC(CFileFind)
  1227. };
  1228. /////////////////////////////////////////////////////////////////////////////
  1229. // CTimeSpan and CTime
  1230. class CTimeSpan
  1231. {
  1232. public:
  1233. // Constructors
  1234. CTimeSpan();
  1235. CTimeSpan(time_t time);
  1236. CTimeSpan(LONG lDays, int nHours, int nMins, int nSecs);
  1237. CTimeSpan(const CTimeSpan& timeSpanSrc);
  1238. const CTimeSpan& operator=(const CTimeSpan& timeSpanSrc);
  1239. // Attributes
  1240. // extract parts
  1241. LONG GetDays() const; // total # of days
  1242. LONG GetTotalHours() const;
  1243. int GetHours() const;
  1244. LONG GetTotalMinutes() const;
  1245. int GetMinutes() const;
  1246. LONG GetTotalSeconds() const;
  1247. int GetSeconds() const;
  1248. // Operations
  1249. // time math
  1250. CTimeSpan operator-(CTimeSpan timeSpan) const;
  1251. CTimeSpan operator+(CTimeSpan timeSpan) const;
  1252. const CTimeSpan& operator+=(CTimeSpan timeSpan);
  1253. const CTimeSpan& operator-=(CTimeSpan timeSpan);
  1254. BOOL operator==(CTimeSpan timeSpan) const;
  1255. BOOL operator!=(CTimeSpan timeSpan) const;
  1256. BOOL operator<(CTimeSpan timeSpan) const;
  1257. BOOL operator>(CTimeSpan timeSpan) const;
  1258. BOOL operator<=(CTimeSpan timeSpan) const;
  1259. BOOL operator>=(CTimeSpan timeSpan) const;
  1260. #ifdef _UNICODE
  1261. // for compatibility with MFC 3.x
  1262. CString Format(LPCSTR pFormat) const;
  1263. #endif
  1264. CString Format(LPCTSTR pFormat) const;
  1265. CString Format(UINT nID) const;
  1266. // serialization
  1267. #ifdef MFC_DEBUG
  1268. friend CDumpContext& AFXAPI operator<<(CDumpContext& dc,CTimeSpan timeSpan);
  1269. #endif
  1270. friend CArchive& AFXAPI operator<<(CArchive& ar, CTimeSpan timeSpan);
  1271. friend CArchive& AFXAPI operator>>(CArchive& ar, CTimeSpan& rtimeSpan);
  1272. private:
  1273. time_t m_timeSpan;
  1274. friend class CTime;
  1275. };
  1276. class CTime
  1277. {
  1278. public:
  1279. // Constructors
  1280. static CTime PASCAL GetCurrentTime();
  1281. CTime();
  1282. CTime(time_t time);
  1283. CTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec,
  1284. int nDST = -1);
  1285. CTime(WORD wDosDate, WORD wDosTime, int nDST = -1);
  1286. CTime(const CTime& timeSrc);
  1287. CTime(const SYSTEMTIME& sysTime, int nDST = -1);
  1288. CTime(const FILETIME& fileTime, int nDST = -1);
  1289. const CTime& operator=(const CTime& timeSrc);
  1290. const CTime& operator=(time_t t);
  1291. // Attributes
  1292. struct tm* GetGmtTm(struct tm* ptm = NULL) const;
  1293. struct tm* GetLocalTm(struct tm* ptm = NULL) const;
  1294. BOOL GetAsSystemTime(SYSTEMTIME& timeDest) const;
  1295. time_t GetTime() const;
  1296. int GetYear() const;
  1297. int GetMonth() const; // month of year (1 = Jan)
  1298. int GetDay() const; // day of month
  1299. int GetHour() const;
  1300. int GetMinute() const;
  1301. int GetSecond() const;
  1302. int GetDayOfWeek() const; // 1=Sun, 2=Mon, ..., 7=Sat
  1303. // Operations
  1304. // time math
  1305. CTimeSpan operator-(CTime time) const;
  1306. CTime operator-(CTimeSpan timeSpan) const;
  1307. CTime operator+(CTimeSpan timeSpan) const;
  1308. const CTime& operator+=(CTimeSpan timeSpan);
  1309. const CTime& operator-=(CTimeSpan timeSpan);
  1310. BOOL operator==(CTime time) const;
  1311. BOOL operator!=(CTime time) const;
  1312. BOOL operator<(CTime time) const;
  1313. BOOL operator>(CTime time) const;
  1314. BOOL operator<=(CTime time) const;
  1315. BOOL operator>=(CTime time) const;
  1316. // formatting using "C" strftime
  1317. CString Format(LPCTSTR pFormat) const;
  1318. CString FormatGmt(LPCTSTR pFormat) const;
  1319. CString Format(UINT nFormatID) const;
  1320. CString FormatGmt(UINT nFormatID) const;
  1321. #ifdef _UNICODE
  1322. // for compatibility with MFC 3.x
  1323. CString Format(LPCSTR pFormat) const;
  1324. CString FormatGmt(LPCSTR pFormat) const;
  1325. #endif
  1326. // serialization
  1327. #ifdef MFC_DEBUG
  1328. friend CDumpContext& AFXAPI operator<<(CDumpContext& dc, CTime time);
  1329. #endif
  1330. friend CArchive& AFXAPI operator<<(CArchive& ar, CTime time);
  1331. friend CArchive& AFXAPI operator>>(CArchive& ar, CTime& rtime);
  1332. private:
  1333. time_t m_time;
  1334. };
  1335. /////////////////////////////////////////////////////////////////////////////
  1336. // File status
  1337. struct CFileStatus
  1338. {
  1339. CTime m_ctime; // creation date/time of file
  1340. CTime m_mtime; // last modification date/time of file
  1341. CTime m_atime; // last access date/time of file
  1342. LONG m_size; // logical size of file in bytes
  1343. BYTE m_attribute; // logical OR of CFile::Attribute enum values
  1344. BYTE _m_padding; // pad the structure to a WORD
  1345. TCHAR m_szFullName[_MAX_PATH]; // absolute path name
  1346. #ifdef MFC_DEBUG
  1347. void Dump(CDumpContext& dc) const;
  1348. #endif
  1349. };
  1350. /////////////////////////////////////////////////////////////////////////////
  1351. // Diagnostic memory management routines
  1352. // Low level sanity checks for memory blocks
  1353. BOOL AFXAPI AfxIsValidAddress(const void* lp,
  1354. UINT nBytes, BOOL bReadWrite = TRUE);
  1355. BOOL AFXAPI AfxIsValidString(LPCWSTR lpsz, int nLength = -1);
  1356. BOOL AFXAPI AfxIsValidString(LPCSTR lpsz, int nLength = -1);
  1357. #if defined(MFC_DEBUG) && !defined(_AFX_NO_DEBUG_CRT)
  1358. // Memory tracking allocation
  1359. void* AFX_CDECL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
  1360. #define DEBUG_NEW new(THIS_FILE, __LINE__)
  1361. #if _MSC_VER >= 1200
  1362. void AFX_CDECL operator delete(void* p, LPCSTR lpszFileName, int nLine);
  1363. #endif
  1364. void* AFXAPI AfxAllocMemoryDebug(size_t nSize, BOOL bIsObject,
  1365. LPCSTR lpszFileName, int nLine);
  1366. void AFXAPI AfxFreeMemoryDebug(void* pbData, BOOL bIsObject);
  1367. // Dump any memory leaks since program started
  1368. BOOL AFXAPI AfxDumpMemoryLeaks();
  1369. // Return TRUE if valid memory block of nBytes
  1370. BOOL AFXAPI AfxIsMemoryBlock(const void* p, UINT nBytes,
  1371. LONG* plRequestNumber = NULL);
  1372. // Return TRUE if memory is sane or print out what is wrong
  1373. BOOL AFXAPI AfxCheckMemory();
  1374. #define afxMemDF _crtDbgFlag
  1375. enum AfxMemDF // memory debug/diagnostic flags
  1376. {
  1377. allocMemDF = 0x01, // turn on debugging allocator
  1378. delayFreeMemDF = 0x02, // delay freeing memory
  1379. checkAlwaysMemDF = 0x04 // AfxCheckMemory on every alloc/free
  1380. };
  1381. #ifdef _UNICODE
  1382. #define AfxOutputDebugString(lpsz) \
  1383. do \
  1384. { \
  1385. USES_CONVERSION; \
  1386. _RPT0(_CRT_WARN, W2CA(lpsz)); \
  1387. } while (0)
  1388. #else
  1389. #define AfxOutputDebugString(lpsz) _RPT0(_CRT_WARN, lpsz)
  1390. #endif
  1391. // turn on/off tracking for a short while
  1392. BOOL AFXAPI AfxEnableMemoryTracking(BOOL bTrack);
  1393. // Advanced initialization: for overriding default diagnostics
  1394. BOOL AFXAPI AfxDiagnosticInit(void);
  1395. // A failure hook returns whether to permit allocation
  1396. typedef BOOL (AFXAPI* AFX_ALLOC_HOOK)(size_t nSize, BOOL bObject, LONG lRequestNumber);
  1397. // Set new hook, return old (never NULL)
  1398. AFX_ALLOC_HOOK AFXAPI AfxSetAllocHook(AFX_ALLOC_HOOK pfnAllocHook);
  1399. // Debugger hook on specified allocation request - Obsolete
  1400. void AFXAPI AfxSetAllocStop(LONG lRequestNumber);
  1401. // Memory state for snapshots/leak detection
  1402. struct CMemoryState
  1403. {
  1404. // Attributes
  1405. enum blockUsage
  1406. {
  1407. freeBlock, // memory not used
  1408. objectBlock, // contains a CObject derived class object
  1409. bitBlock, // contains ::operator new data
  1410. crtBlock,
  1411. ignoredBlock,
  1412. nBlockUseMax // total number of usages
  1413. };
  1414. _CrtMemState m_memState;
  1415. LONG m_lCounts[nBlockUseMax];
  1416. LONG m_lSizes[nBlockUseMax];
  1417. LONG m_lHighWaterCount;
  1418. LONG m_lTotalCount;
  1419. CMemoryState();
  1420. // Operations
  1421. void Checkpoint(); // fill with current state
  1422. BOOL Difference(const CMemoryState& oldState,
  1423. const CMemoryState& newState); // fill with difference
  1424. void UpdateData();
  1425. // Output to afxDump
  1426. void DumpStatistics() const;
  1427. void DumpAllObjectsSince() const;
  1428. };
  1429. // Enumerate allocated objects or runtime classes
  1430. void AFXAPI AfxDoForAllObjects(void (AFX_CDECL *pfn)(CObject* pObject, void* pContext),
  1431. void* pContext);
  1432. void AFXAPI AfxDoForAllClasses(void (AFX_CDECL *pfn)(const CRuntimeClass* pClass,
  1433. void* pContext), void* pContext);
  1434. #else
  1435. // non-_DEBUG_ALLOC version that assume everything is OK
  1436. #define DEBUG_NEW new
  1437. #define AfxCheckMemory() TRUE
  1438. #define AfxIsMemoryBlock(p, nBytes) TRUE
  1439. #define AfxEnableMemoryTracking(bTrack) FALSE
  1440. #define AfxOutputDebugString(lpsz) ::OutputDebugString(lpsz)
  1441. // diagnostic initialization
  1442. #ifndef MFC_DEBUG
  1443. #define AfxDiagnosticInit() TRUE
  1444. #else
  1445. BOOL AFXAPI AfxDiagnosticInit(void);
  1446. #endif
  1447. #endif // MFC_DEBUG
  1448. /////////////////////////////////////////////////////////////////////////////
  1449. // Archives for serializing CObject data
  1450. // needed for implementation
  1451. class CPtrArray;
  1452. class CMapPtrToPtr;
  1453. class CDocument;
  1454. class CArchive
  1455. {
  1456. public:
  1457. // Flag values
  1458. enum Mode { store = 0, load = 1, bNoFlushOnDelete = 2, bNoByteSwap = 4 };
  1459. CArchive(CFile* pFile, UINT nMode, int nBufSize = 4096, void* lpBuf = NULL);
  1460. ~CArchive();
  1461. // Attributes
  1462. BOOL IsLoading() const;
  1463. BOOL IsStoring() const;
  1464. BOOL IsByteSwapping() const;
  1465. BOOL IsBufferEmpty() const;
  1466. CFile* GetFile() const;
  1467. UINT GetObjectSchema(); // only valid when reading a CObject*
  1468. void SetObjectSchema(UINT nSchema);
  1469. // pointer to document being serialized -- must set to serialize
  1470. // COleClientItems in a document!
  1471. CDocument* m_pDocument;
  1472. // Operations
  1473. UINT Read(void* lpBuf, UINT nMax);
  1474. void Write(const void* lpBuf, UINT nMax);
  1475. void Flush();
  1476. void Close();
  1477. void Abort(); // close and shutdown without exceptions
  1478. // reading and writing strings
  1479. void WriteString(LPCTSTR lpsz);
  1480. LPTSTR ReadString(LPTSTR lpsz, UINT nMax);
  1481. BOOL ReadString(CString& rString);
  1482. public:
  1483. // Object I/O is pointer based to avoid added construction overhead.
  1484. // Use the Serialize member function directly for embedded objects.
  1485. friend CArchive& AFXAPI operator<<(CArchive& ar, const CObject* pOb);
  1486. friend CArchive& AFXAPI operator>>(CArchive& ar, CObject*& pOb);
  1487. friend CArchive& AFXAPI operator>>(CArchive& ar, const CObject*& pOb);
  1488. // insertion operations
  1489. CArchive& operator<<(BYTE by);
  1490. CArchive& operator<<(WORD w);
  1491. CArchive& operator<<(LONG l);
  1492. CArchive& operator<<(DWORD dw);
  1493. CArchive& operator<<(float f);
  1494. CArchive& operator<<(double d);
  1495. CArchive& operator<<(int i);
  1496. CArchive& operator<<(short w);
  1497. CArchive& operator<<(char ch);
  1498. CArchive& operator<<(unsigned u);
  1499. // extraction operations
  1500. CArchive& operator>>(BYTE& by);
  1501. CArchive& operator>>(WORD& w);
  1502. CArchive& operator>>(DWORD& dw);
  1503. CArchive& operator>>(LONG& l);
  1504. CArchive& operator>>(float& f);
  1505. CArchive& operator>>(double& d);
  1506. CArchive& operator>>(int& i);
  1507. CArchive& operator>>(short& w);
  1508. CArchive& operator>>(char& ch);
  1509. CArchive& operator>>(unsigned& u);
  1510. // object read/write
  1511. CObject* ReadObject(const CRuntimeClass* pClass);
  1512. void WriteObject(const CObject* pOb);
  1513. // advanced object mapping (used for forced references)
  1514. void MapObject(const CObject* pOb);
  1515. // advanced versioning support
  1516. void WriteClass(const CRuntimeClass* pClassRef);
  1517. CRuntimeClass* ReadClass(const CRuntimeClass* pClassRefRequested = NULL,
  1518. UINT* pSchema = NULL, DWORD* pObTag = NULL);
  1519. void SerializeClass(const CRuntimeClass* pClassRef);
  1520. // advanced operations (used when storing/loading many objects)
  1521. void SetStoreParams(UINT nHashSize = 2053, UINT nBlockSize = 128);
  1522. void SetLoadParams(UINT nGrowBy = 1024);
  1523. // Implementation
  1524. public:
  1525. BOOL m_bForceFlat; // for COleClientItem implementation (default TRUE)
  1526. BOOL m_bDirectBuffer; // TRUE if m_pFile supports direct buffering
  1527. void FillBuffer(UINT nBytesNeeded);
  1528. void CheckCount(); // throw exception if m_nMapCount is too large
  1529. // special functions for reading and writing (16-bit compatible) counts
  1530. DWORD ReadCount();
  1531. void WriteCount(DWORD dwCount);
  1532. // public for advanced use
  1533. UINT m_nObjectSchema;
  1534. CString m_strFileName;
  1535. protected:
  1536. // archive objects cannot be copied or assigned
  1537. CArchive(const CArchive& arSrc);
  1538. void operator=(const CArchive& arSrc);
  1539. BOOL m_nMode;
  1540. BOOL m_bUserBuf;
  1541. int m_nBufSize;
  1542. CFile* m_pFile;
  1543. BYTE* m_lpBufCur;
  1544. BYTE* m_lpBufMax;
  1545. BYTE* m_lpBufStart;
  1546. // array/map for CObject* and CRuntimeClass* load/store
  1547. UINT m_nMapCount;
  1548. union
  1549. {
  1550. CPtrArray* m_pLoadArray;
  1551. CMapPtrToPtr* m_pStoreMap;
  1552. };
  1553. // map to keep track of mismatched schemas
  1554. CMapPtrToPtr* m_pSchemaMap;
  1555. // advanced parameters (controls performance with large archives)
  1556. UINT m_nGrowSize;
  1557. UINT m_nHashSize;
  1558. };
  1559. /////////////////////////////////////////////////////////////////////////////
  1560. // Diagnostic dumping
  1561. // Note: AfxDumpStack is available in release builds, although it is always
  1562. // statically linked so as to not negatively affect the size of MFC42.DLL.
  1563. #define AFX_STACK_DUMP_TARGET_TRACE 0x0001
  1564. #define AFX_STACK_DUMP_TARGET_CLIPBOARD 0x0002
  1565. #define AFX_STACK_DUMP_TARGET_BOTH 0x0003
  1566. #define AFX_STACK_DUMP_TARGET_ODS 0x0004
  1567. #ifdef MFC_DEBUG
  1568. #define AFX_STACK_DUMP_TARGET_DEFAULT AFX_STACK_DUMP_TARGET_TRACE
  1569. #else
  1570. #define AFX_STACK_DUMP_TARGET_DEFAULT AFX_STACK_DUMP_TARGET_CLIPBOARD
  1571. #endif
  1572. void AFXAPI AfxDumpStack(DWORD dwFlags = AFX_STACK_DUMP_TARGET_DEFAULT);
  1573. class CDumpContext
  1574. {
  1575. public:
  1576. CDumpContext(CFile* pFile = NULL);
  1577. // Attributes
  1578. int GetDepth() const; // 0 => this object, 1 => children objects
  1579. void SetDepth(int nNewDepth);
  1580. // Operations
  1581. CDumpContext& operator<<(LPCTSTR lpsz);
  1582. #ifdef _UNICODE
  1583. CDumpContext& operator<<(LPCSTR lpsz); // automatically widened
  1584. #else
  1585. CDumpContext& operator<<(LPCWSTR lpsz); // automatically thinned
  1586. #endif
  1587. CDumpContext& operator<<(const void* lp);
  1588. CDumpContext& operator<<(const CObject* pOb);
  1589. CDumpContext& operator<<(const CObject& ob);
  1590. CDumpContext& operator<<(BYTE by);
  1591. CDumpContext& operator<<(WORD w);
  1592. CDumpContext& operator<<(UINT u);
  1593. CDumpContext& operator<<(LONG l);
  1594. CDumpContext& operator<<(DWORD dw);
  1595. CDumpContext& operator<<(float f);
  1596. CDumpContext& operator<<(double d);
  1597. CDumpContext& operator<<(int n);
  1598. void HexDump(LPCTSTR lpszLine, BYTE* pby, int nBytes, int nWidth);
  1599. void Flush();
  1600. // Implementation
  1601. protected:
  1602. // dump context objects cannot be copied or assigned
  1603. CDumpContext(const CDumpContext& dcSrc);
  1604. void operator=(const CDumpContext& dcSrc);
  1605. void OutputString(LPCTSTR lpsz);
  1606. int m_nDepth;
  1607. public:
  1608. CFile* m_pFile;
  1609. };
  1610. #ifdef MFC_DEBUG
  1611. extern AFX_DATA CDumpContext afxDump;
  1612. extern AFX_DATA BOOL afxTraceEnabled;
  1613. #endif
  1614. /////////////////////////////////////////////////////////////////////////////
  1615. // Special include for Win32s compatibility
  1616. #ifdef _AFX_PACKING
  1617. #pragma pack(pop)
  1618. #endif
  1619. #ifndef WINSCP
  1620. #ifndef __AFXCOLL_H__
  1621. #include <afxcoll.h>
  1622. #ifndef __AFXSTATE_H__
  1623. #include <afxstat_.h> // for _AFX_APP_STATE and _AFX_THREAD_STATE
  1624. #endif
  1625. #endif
  1626. #endif
  1627. /////////////////////////////////////////////////////////////////////////////
  1628. // Inline function declarations
  1629. #ifdef _AFX_ENABLE_INLINES
  1630. #define _AFX_INLINE AFX_INLINE
  1631. #if !defined(_AFX_CORE_IMPL) || !defined(_AFXDLL) || defined(MFC_DEBUG)
  1632. #define _AFX_PUBLIC_INLINE AFX_INLINE
  1633. #else
  1634. #define _AFX_PUBLIC_INLINE
  1635. #endif
  1636. #include <afx.inl>
  1637. #endif
  1638. #undef AFX_DATA
  1639. #define AFX_DATA
  1640. #ifdef _AFX_MINREBUILD
  1641. #pragma component(minrebuild, on)
  1642. #endif
  1643. #ifndef _AFX_FULLTYPEINFO
  1644. #pragma component(mintypeinfo, off)
  1645. #endif
  1646. #ifdef WINSCP
  1647. extern HINSTANCE afxCurrentResourceHandle;
  1648. #endif
  1649. #endif // __AFX_H__
  1650. /////////////////////////////////////////////////////////////////////////////