1 /*****************************************************************************\
3 * Name : DLL Main Root Support *
4 * Author : Chris Koeritz *
6 *******************************************************************************
7 * Copyright (c) 1995-$now By Author. This program is free software; you can *
8 * redistribute it and/or modify it under the terms of the GNU General Public *
9 * License as published by the Free Software Foundation; either version 2 of *
10 * the License or (at your option) any later version. This is online at: *
11 * http://www.fsf.org/copyleft/gpl.html *
12 * Please send any updates to: fred@gruntose.com *
13 \*****************************************************************************/
15 // Thanks to Andy Tan for some research into MFC extension dlls.
17 #include <application/base_application.h>
18 #include <basis/utf_conversion.h>
19 #include <structures/static_memory_gremlin.h>
21 //HOOPLE_STARTUP_CODE_DLL;
22 // initialize objects needed by the hoople libs.
27 #define TRACE_PRINTER(s) TRACE_PRINT(s)
29 #define TRACE_PRINTER(s)
34 #include <afxext.h> // MFC extensions.
35 #include <afxdllx.h> // Extension DLL declarations; include only once!
37 bool check_DLL_versions();
38 // supplied by the library's version of dllmain.cpp.
40 static AFX_EXTENSION_MODULE SomeDLL = { NULL, NULL };
43 #define DLL_NAME "unnamed DLL"
46 extern "C" int APIENTRY
47 DllMain(application_instance instance, DWORD reason, LPVOID reserved)
49 SET_INSTANCE_HANDLE(instance);
50 // Remove this if you use lpReserved.
51 UNREFERENCED_PARAMETER(reserved);
53 char *dll_name = DLL_NAME;
54 // mainly for debugging purposes. having the value for DLL_NAME actually
55 // stored should allow us to know which dll is being debugged.
57 static CDynLinkLibrary *dll_link = NULL_POINTER;
59 static int dll_entry_count = 0;
62 case DLL_PROCESS_ATTACH: {
63 char *message = DLL_NAME " Initializing!\n";
64 TRACE_PRINTER(message);
66 if (!check_DLL_versions()) return 0;
68 // Extension DLL one-time initialization
69 if (!AfxInitExtensionModule(SomeDLL, instance)) return 0;
71 // Insert this DLL into the resource chain.
72 dll_link = new CDynLinkLibrary(SomeDLL);
74 // NOTE: If this Extension DLL is being implicitly linked to by an MFC
75 // Regular DLL (such as an ActiveX Control) instead of an MFC
76 // application, then you will want to remove this line from DllMain and
77 // put it in a separate function exported from this Extension DLL. The
78 // Regular DLL that uses this Extension DLL should then explicitly call
79 // that function to initialize this Extension DLL. Otherwise, the
80 // CDynLinkLibrary object will not be attached to the Regular DLL's
81 // resource chain, and serious problems will result.
85 case DLL_PROCESS_DETACH: {
87 char *message = DLL_NAME " Terminating!\n";
88 TRACE_PRINTER(message);
89 // clean up our other stuff.
91 // Terminate the library before destructors are called.
92 AfxTermExtensionModule(SomeDLL);
95 case DLL_THREAD_ATTACH:
98 case DLL_THREAD_DETACH:
109 #elif defined(__WIN32__)
113 #include <application/windoze_helper.h> // base windows stuff.
115 bool check_DLL_versions();
116 // supplied by the library's version of dllmain.cpp.
118 BOOL APIENTRY DllMain(HANDLE module, DWORD ul_reason_for_call, LPVOID reserved)
120 SET_INSTANCE_HANDLE((application_instance)module);
121 switch (ul_reason_for_call) {
122 case DLL_PROCESS_ATTACH:
123 if (!check_DLL_versions()) return 0;
126 // these are currently not processed.
127 case DLL_THREAD_ATTACH:
128 case DLL_THREAD_DETACH:
129 case DLL_PROCESS_DETACH: