NCBI C++ ToolKit
winmain.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: winmain.cpp 85932 2019-03-25 13:48:34Z gouriano $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Mike DiCuccio
27  *
28  * File Description:
29  * WinMain() - necessary to launch a Win32 app in as a non-console app
30  */
31 
32 //
33 // WinMain provided here for Windows compatibility
34 // This allows us to run our application without a console
35 //
36 
37 #include <ncbi_pch.hpp>
38 #include <windows.h>
39 #include <tchar.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <corelib/ncbiexpt.hpp>
43 #include <corelib/ncbistr.hpp>
44 #include <corelib/ncbiapp.hpp>
45 
46 #ifdef _DEBUG
47 # include <crtdbg.h>
48 #endif
49 
51 
52 extern int NcbiSys_main(int argc, const ncbi::TXChar* const argv[]);
53 
55  HINSTANCE hPrevInstance,
56  LPTSTR lpCmdLine,
57  int nCmdShow)
58 {
59 #ifdef _UNICODE
60  TXChar** argv = __wargv;
61 #else
62  TXChar** argv = __argv;
63 #endif
64 
65 #ifdef _DEBUG
66 
67  ///
68  /// comment this section out if you want verbose leak tracking
69  ///
70 
71  int flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
72  flags &= ~_CRTDBG_LEAK_CHECK_DF;
73  _CrtSetDbgFlag(flags);
74 
75  ///
76  ///
77  ///
78 
79  // standard memory leak reporting infrastructure
80  _CrtMemState start_state;
81  _CrtMemState stop_state;
82  _CrtMemCheckpoint(&start_state);
83 
84 #ifndef _DEBUG_NO_CONSOLE
85  //
86  // In debug mode, a console will be created to display stdout/stderr
87  //
88  AllocConsole();
89  freopen("conin$", "r", stdin);
90  freopen("conout$", "w", stdout);
91  freopen("conout$", "w", stderr);
92 
93  // LOG_EER can be called from static initializers
94  // this puts stream in error state
95  // after that no stream output can be performed
96  // so after console initialization we clear stream state
97  cerr.clear();
98  cout.clear();
99 
100  // call the app-supplied main()
101  int ret_val = NcbiSys_main(__argc, argv);
102 
103  // close our console
104  fclose(stdin);
105  fclose(stdout);
106  fclose(stderr);
107 
108 #else
109 
110  // call the app-supplied main()
111  int ret_val = NcbiSys_main(__argc, argv);
112 
113 #endif
114 
115  // finalize our leak tracking
116  _CrtMemCheckpoint(&stop_state);
117  _CrtMemState diff_state;
118  if (_CrtMemDifference(&diff_state, &start_state, &stop_state)) {
119  _CrtMemDumpStatistics(&diff_state);
120  //_CrtMemDumpAllObjectsSince(&diff_state);
121  }
122 
123  return ret_val;
124 
125 #else
126 
127  return NcbiSys_main(__argc, argv);
128 
129 #endif
130 }
int NcbiSys_main(int argc, const ncbi::TXChar *const argv[])
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
Definition: winmain.cpp:54
USING_SCOPE(ncbi)
The NCBI C++ standard methods for dealing with std::string.
static uch flags
#define APIENTRY
Definition: gloscontext.hpp:46
char TXChar
Definition: ncbistr.hpp:172
Magic spell ;-) needed for some weird compilers... very empiric.
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Defines NCBI C++ exception handling.
TCHAR * LPTSTR
Definition: sqltypes.h:111
void * HINSTANCE
Definition: sqltypes.h:116
Modified on Sat Dec 09 04:49:44 2023 by modify_doxy.py rev. 669887