7fd59977 |
1 | // This is a part of the Microsoft Foundation Classes C++ library. |
2 | // Copyright (C) 1992-1995 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 | |
11 | #include "stdafx.h" |
12 | |
13 | #include <Standard_ErrorHandler.hxx> |
14 | #include <Standard_SStream.hxx> |
15 | #include <Standard_Failure.hxx> |
16 | #include <Message.hxx> |
17 | #include <Message_Messenger.hxx> |
18 | #include <Message_PrinterOStream.hxx> |
19 | |
20 | #ifdef AFX_CORE1_SEG |
21 | #pragma code_seg(AFX_CORE1_SEG) |
22 | #endif |
23 | |
24 | ///////////////////////////////////////////////////////////////////////////// |
25 | // Standard WinMain implementation |
26 | // Can be replaced as long as 'AfxWinInit' is called first |
27 | |
28 | // for cout redefinition : |
29 | #include <io.h> // for _open_osfhandle |
30 | #include <fcntl.h> // for _O_TEXT |
31 | |
32 | #ifdef _DEBUG |
33 | #define DISPLAYCONSOLE 1 |
34 | #endif |
35 | |
36 | int AFXAPI AfxWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
37 | LPTSTR lpCmdLine, int nCmdShow) |
38 | { |
39 | #ifdef DISPLAYCONSOLE |
40 | |
41 | // Redirection of standard output to console |
42 | int hCrt; BOOL rep; FILE *hf; |
43 | _SYSTEM_INFO lps; |
44 | GetSystemInfo(&lps); |
45 | rep = AllocConsole(); |
e0280ce9 |
46 | hCrt = _open_osfhandle((intptr_t) GetStdHandle(STD_OUTPUT_HANDLE),_O_TEXT); |
7fd59977 |
47 | hf = _fdopen( hCrt, "w" ); |
48 | *stdout = *hf; |
49 | // stop the buffer on stdout |
50 | // int i = setvbuf( stdout, NULL, _IONBF, 0 ); |
51 | // filebuf ff(hCrt); |
52 | // cout = &ff; |
04232180 |
53 | std::cout<<"This Debug Window is defined in WinMain.cpp and will disappear in release mode"<<std::endl; |
7fd59977 |
54 | |
55 | #endif // DISPLAYCONSOLE // By Matra |
56 | |
57 | // create log file for all OCC messages |
58 | // Message::DefaultMessenger()->AddPrinter (new Message_PrinterOStream ("OCCSampleRun.log", Standard_False)); |
59 | |
60 | ASSERT(hPrevInstance == NULL); |
61 | |
62 | int nReturnCode = -1; |
63 | CWinApp* pApp = AfxGetApp(); |
64 | |
65 | // new in 2.0 CAS.CADE uses the standard C++ exception mechanism |
66 | /*#ifdef _DEBUG // By Matra |
67 | // _Function declaratiob here because you can jump to InitFailure |
68 | Standard_ErrorHandler _Function; |
69 | #endif // _DEBUG // By Matra |
70 | */ |
71 | // AFX internal initialization |
72 | if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow)) |
73 | goto InitFailure; |
74 | |
75 | // App global initializations (rare) |
76 | ASSERT_VALID(pApp); |
77 | if (!pApp->InitApplication()) |
78 | goto InitFailure; |
79 | ASSERT_VALID(pApp); |
80 | |
81 | // Perform specific initializations |
82 | if (!pApp->InitInstance()) |
83 | { |
84 | if (pApp->m_pMainWnd != NULL) |
85 | { |
86 | TRACE0("Warning: Destroying non-NULL m_pMainWnd\n"); |
87 | pApp->m_pMainWnd->DestroyWindow(); |
88 | } |
89 | nReturnCode = pApp->ExitInstance(); |
90 | goto InitFailure; |
91 | } |
92 | ASSERT_VALID(pApp); |
93 | |
94 | |
95 | #ifdef _DEBUG // By Matra |
96 | Application: |
97 | |
98 | // new in 2.0 CAS.CADE uses the standard C++ exception mechanism |
99 | |
100 | // if(DoesNotAbort(_Function)) |
101 | try |
102 | { |
103 | nReturnCode = pApp->Run(); |
104 | } |
105 | // if(_Function.Catches(STANDARD_TYPE(Standard_Failure))) |
9775fa61 |
106 | catch(Standard_Failure const& anException) |
7fd59977 |
107 | { |
108 | Standard_SStream ostr; |
9775fa61 |
109 | ostr<<anException<<"\n\0"; |
576f8b11 |
110 | CString aMsg = ostr.str().c_str(); |
111 | MessageBoxW (NULL, aMsg, L"CasCade Error", MB_ICONERROR); |
7fd59977 |
112 | goto Application; // restart application loop |
113 | } |
114 | #else // _DEBUG // By Matra |
115 | nReturnCode = pApp->Run(); |
116 | #endif // _DEBUG // By Matra |
117 | |
118 | |
119 | ASSERT_VALID(pApp); |
120 | |
121 | InitFailure: |
122 | #ifdef _DEBUG |
123 | // Check for missing AfxLockTempMap calls |
124 | if (AfxGetModuleThreadState()->m_nTempMapLock != 0) |
125 | { |
126 | TRACE1("Warning: Temp map lock count non-zero (%ld).\n", |
127 | AfxGetModuleThreadState()->m_nTempMapLock); |
128 | } |
129 | |
130 | AfxLockTempMaps(); |
131 | AfxUnlockTempMaps(); |
132 | #endif |
133 | |
134 | AfxWinTerm(); |
135 | |
136 | #ifdef DISPLAYCONSOLE // By Matra |
137 | // ferme la console pour le cout |
138 | fclose( stdout ); |
139 | //hCrt = _fcloseall(); :-) |
140 | rep = FreeConsole(); |
141 | #endif // DISPLAYCONSOLE // By Matra |
142 | |
143 | |
144 | return nReturnCode; |
145 | } |
146 | |
147 | ///////////////////////////////////////////////////////////////////////////// |