// DataManager.cpp : Defines the initialization routines for the DLL. // #include "stdafx.h" #include "DataManager.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern Def_CreateObj* g_pfCreateObj; extern Def_ReleaseObj* g_pfReleaseObj; // // Note! // // 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. // ///////////////////////////////////////////////////////////////////////////// // CDataManagerApp BEGIN_MESSAGE_MAP(CDataManagerApp, CWinApp) //{{AFX_MSG_MAP(CDataManagerApp) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDataManagerApp construction CDataManagerApp::CDataManagerApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance m_bLoadedByMainProg = FALSE; } ///////////////////////////////////////////////////////////////////////////// // The one and only CDataManagerApp object CDataManagerApp theApp; BOOL CDataManagerApp::GetObjFuncs(CString strAppName, Def_CreateObj* &fpCreateObj, Def_ReleaseObj* &fpReleaseObj) { fpCreateObj = NULL; fpReleaseObj = NULL; CString strAppNameThis = AfxGetAppName(); strAppNameThis.MakeUpper(); strAppName.MakeUpper(); if(strAppName == strAppNameThis) { fpCreateObj = (Def_CreateObj*)CreateObj; fpReleaseObj = (Def_ReleaseObj*)ReleaseObj; } else { HMODULE hDll = NULL; if(!m_mapAllAppHandle.Lookup(strAppName, (void*&)hDll)) { hDll = LoadLibrary(strAppName); if(GetProcAddress(hDll, "ReleaseObj") == NULL || GetProcAddress(hDll, "CreateObj") == NULL) { FreeLibrary(hDll); hDll = NULL; } else { m_mapAllAppHandle.SetAt(strAppName, hDll); } } if(hDll) { fpCreateObj = (Def_CreateObj*)GetProcAddress(hDll, "CreateObj"); fpReleaseObj = (Def_ReleaseObj*)GetProcAddress(hDll, "ReleaseObj"); } else { fpCreateObj = g_pfCreateObj; fpReleaseObj = g_pfReleaseObj; } } return (fpCreateObj != NULL && fpReleaseObj != NULL); } BOOL CDataManagerApp::InitInstance() { // TODO: Add your specialized code here and/or call the base class srand( (unsigned)time( NULL ) ); #ifndef _DEBUG SetErrorMode(SEM_NOGPFAULTERRORBOX); #endif m_strAppPath = GetAppPath(); m_strDllPath = GetDllPath(); m_bLoadedByMainProg = (m_strDllPath == m_strAppPath); char szBuf[MAX_PATH]; CString strMyDwIni = m_strDllPath + "\\MyDwCtl.Ini"; GetPrivateProfileString("Language", "Language", "简体中文", szBuf, MAX_PATH, strMyDwIni); m_nChineseType = GetPrivateProfileInt("Common", "ChnType", CHN_TYPE_SIMPL, strMyDwIni); if(CString(szBuf) != "简体中文") m_nChineseType = CHN_TYPE_NONE; m_bJtToFj = (m_nChineseType == CHN_TYPE_TRAD); AddPathToEnvirPath(m_strDllPath); AddPathToEnvirPath(m_strAppPath); char szAppName[MAX_PATH+1] = {0}; GetModuleFileName(NULL, szAppName, MAX_PATH); CString strAppName = szAppName; strAppName.MakeUpper(); static BOOL bTranslate = GetPrivateProfileInt("Language", "Translate", 1, "DataCenter.ini"); if(bTranslate && strAppName.Find("FRONTPG.EXE") == -1 && strAppName.Find("MSDEV.EXE") == -1) CLanguage::LoadDll(); return CWinApp::InitInstance(); } int CDataManagerApp::ExitInstance() { // TODO: Add your specialized code here and/or call the base class CString strAppName; HMODULE hDll = NULL; POSITION pos = m_mapAllAppHandle.GetStartPosition(); while (pos) { m_mapAllAppHandle.GetNextAssoc(pos, strAppName, (void*&)hDll); FreeLibrary(hDll); } m_mapAllAppHandle.RemoveAll(); return CWinApp::ExitInstance(); }