convert line ends
[canaan.git] / prj / tech / libsrc / appcore / appcore.cpp
blobb24c84f96bd0f53c28797fdd3f8350fb587af061
1 ///////////////////////////////////////////////////////////////////////////////
2 // $Source: x:/prj/tech/libsrc/appcore/RCS/appcore.cpp $
3 // $Author: TOML $
4 // $Date: 1997/02/15 17:44:44 $
5 // $Revision: 1.28 $
6 //
8 #ifdef _WIN32
9 #include <windows.h>
10 #endif
12 #include <lg.h>
13 #include <codewrit.h>
15 #include <appagg.h>
16 #include <objcguid.h>
17 #include <objcoll.h>
18 #include <stdlib.h>
20 ///////////////////////////////////////////////////////////////////////////////
22 static IAggregate * pAppAggregate;
24 ///////////////////////////////////////////////////////////////////////////////
26 tResult _AppAggregateCreate(REFIID)
28 pAppAggregate = CreateGenericAggregate("Application Aggregate", kISetKeyLGGUIDs);
29 AssertMsg(pAppAggregate, "Failed to create application aggregate!");
30 _AppSetAggregate(pAppAggregate);
31 return (pAppAggregate) ? NOERROR : E_FAIL;
34 ///////////////////////////////////////
36 static BOOL g_fCallAppExit;
37 static BOOL g_fReturnedFromMain;
39 void AppOnExit()
41 // Tell the app the components are about to go away
42 if (g_fCallAppExit)
43 AppExit();
44 if (pAppAggregate)
46 pAppAggregate->End();
49 // This module always retains 1 reference on the aggregate. However, this
50 // function must handle the (not too unusual) case of closing without cleaning
51 // up all reference counts.
53 ulong ulRefsRemaining = pAppAggregate->ReleaseAll();
54 //AssertMsg1(!g_fReturnedFromMain || ulRefsRemaining == 1, "Reference of application object is incorrect on exit (was %d, expected 1)", ulRefsRemaining);
55 pAppAggregate = NULL;
59 ///////////////////////////////////////////////////////////////////////////////
61 extern "C" {
63 int _g_referenceExtendedStartup = 0;
64 extern int _g_referenceEntryPoint;
68 ///////////////////////////////////////////////////////////////////////////////
70 // This is the primary client entry-point
73 extern "C"
74 int LGAPI _AppMain(int argc, const char *argv[])
76 // Force link of main/WinMain/LibMain
77 _g_referenceEntryPoint = 1;
79 #ifdef _WIN32
80 // Allow our code to be self-modifying
81 if (GetPrivateProfileInt("AppCore", "MakeAllCodeWritable", !!(g_fAppStartupFlags & kASF_MakeCodeWritable), "lg.ini"))
82 MakeAllCodeWritable();
83 #endif
85 // Increase the number of available handles in the standard buffered i/o
86 #ifdef __WATCOMC__
87 _grow_handles(60);
88 #else
89 #pragma message("Need a way to increase available file handles")
90 #endif
92 // Create the core aggregate entity
93 _AppAggregateCreate(IID_IAggregate);
95 // Tell the app to create the application-level COM objects
96 if (AppCreateObjects(argc, argv) != NOERROR)
97 return 1;
99 // Clean-up is done through exit()
100 atexit(AppOnExit);
102 // Initialize the components
103 if (pAppAggregate)
104 pAppAggregate->Init();
106 // Tell the app the components are initialized
107 if (AppInit() != NOERROR)
108 return 1;
110 // Set flag indicating successful initialization, so should call AppExit()
111 g_fCallAppExit = TRUE;
113 // Start the application
114 int mainRetVal = AppMain(argc, argv);
115 g_fReturnedFromMain = TRUE;
116 return mainRetVal;
119 ///////////////////////////////////////////////////////////////////////////////
121 // Symbol to Force inclusion of this extended startup code
124 int __ExtendedStartup(void)
126 return 0;