// [!output PROJECT_NAME].cpp : Defines the initialization routines for the DLL. // #include "stdafx.h" [!if DLL_TYPE_EXTENSION] #include #ifdef _MANAGED #error Please read instructions in [!output PROJECT_NAME].cpp to compile with /clr // If you want to add /clr to your project you must do the following: // 1. Remove the above include for afxdllx.h // 2. Add a .cpp file to your project that does not have /clr thrown and has // Precompiled headers disabled, with the following text: // #include // #include #endif [!else] #include "[!output PROJECT_NAME].h" [!endif] #ifdef _DEBUG #define new DEBUG_NEW #endif [!if DLL_TYPE_REGULAR || DLL_TYPE_REGULAR_STATIC] // //TODO: If this DLL is dynamically linked against the MFC DLLs, // any functions exported from this DLL which call into // MFC must have the AFX_MANAGE_STATE macro added at the // very beginning of the function. // // For example: // // extern "C" BOOL PASCAL EXPORT ExportedFunction() // { // AFX_MANAGE_STATE(AfxGetStaticModuleState()); // // normal function body here // } // // It is very important that this macro appear in each // function, prior to any calls into MFC. This means that // it must appear as the first statement within the // function, even before any object variable declarations // as their constructors may generate calls into the MFC // DLL. // // Please see MFC Technical Notes 33 and 58 for additional // details. // [!endif] [!if DLL_TYPE_EXTENSION] static AFX_EXTENSION_MODULE [!output SAFE_PROJECT_IDENTIFIER_NAME]DLL = { NULL, NULL }; #ifdef _MANAGED #pragma managed(push, off) #endif extern "C" int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) { // Remove this if you use lpReserved UNREFERENCED_PARAMETER(lpReserved); if (dwReason == DLL_PROCESS_ATTACH) { TRACE0("[!output PROJECT_NAME].DLL Initializing!\n"); // Extension DLL one-time initialization if (!AfxInitExtensionModule([!output SAFE_PROJECT_IDENTIFIER_NAME]DLL, hInstance)) return 0; // Insert this DLL into the resource chain // NOTE: If this Extension DLL is being implicitly linked to by // an MFC Regular DLL (such as an ActiveX Control) // instead of an MFC application, then you will want to // remove this line from DllMain and put it in a separate // function exported from this Extension DLL. The Regular DLL // that uses this Extension DLL should then explicitly call that // function to initialize this Extension DLL. Otherwise, // the CDynLinkLibrary object will not be attached to the // Regular DLL's resource chain, and serious problems will // result. new CDynLinkLibrary([!output SAFE_PROJECT_IDENTIFIER_NAME]DLL); [!if SOCKETS] // Sockets initialization // NOTE: If this Extension DLL is being implicitly linked to by // an MFC Regular DLL (such as an ActiveX Control) // instead of an MFC application, then you will want to // remove the following lines from DllMain and put them in a separate // function exported from this Extension DLL. The Regular DLL // that uses this Extension DLL should then explicitly call that // function to initialize this Extension DLL. if (!AfxSocketInit()) { return FALSE; } [!endif] } else if (dwReason == DLL_PROCESS_DETACH) { TRACE0("[!output PROJECT_NAME].DLL Terminating!\n"); // Terminate the library before destructors are called AfxTermExtensionModule([!output SAFE_PROJECT_IDENTIFIER_NAME]DLL); } return 1; // ok } #ifdef _MANAGED #pragma managed(pop) #endif [!else] // [!output APP_CLASS] BEGIN_MESSAGE_MAP([!output APP_CLASS], [!output APP_BASE_CLASS]) END_MESSAGE_MAP() // [!output APP_CLASS] construction [!output APP_CLASS]::[!output APP_CLASS]() { // TODO: add construction code here, // Place all significant initialization in InitInstance } // The one and only [!output APP_CLASS] object [!output APP_CLASS] theApp; [!if AUTOMATION] const GUID CDECL BASED_CODE _tlid = [!output LIBID_STATIC_CONST_GUID_FORMAT]; const WORD _wVerMajor = 1; const WORD _wVerMinor = 0; [!endif] // [!output APP_CLASS] initialization BOOL [!output APP_CLASS]::InitInstance() { [!output APP_BASE_CLASS]::InitInstance(); [!if SOCKETS] if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; } [!endif] [!if AUTOMATION] // Register all OLE server (factories) as running. This enables the // OLE libraries to create objects from other applications. COleObjectFactory::RegisterAll(); [!endif] return TRUE; } [!if AUTOMATION] // DllGetClassObject - Returns class factory STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); return AfxDllGetClassObject(rclsid, riid, ppv); } // DllCanUnloadNow - Allows COM to unload DLL STDAPI DllCanUnloadNow(void) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); return AfxDllCanUnloadNow(); } // DllRegisterServer - Adds entries to the system registry STDAPI DllRegisterServer(void) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid)) return SELFREG_E_TYPELIB; if (!COleObjectFactory::UpdateRegistryAll()) return SELFREG_E_CLASS; return S_OK; } // DllUnregisterServer - Removes entries from the system registry STDAPI DllUnregisterServer(void) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor)) return SELFREG_E_TYPELIB; if (!COleObjectFactory::UpdateRegistryAll(FALSE)) return SELFREG_E_CLASS; return S_OK; } [!endif] [!endif]