DataManager.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // DataManager.cpp : Defines the initialization routines for the DLL.
  2. //
  3. #include "stdafx.h"
  4. #include "DataManager.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. extern Def_CreateObj* g_pfCreateObj;
  11. extern Def_ReleaseObj* g_pfReleaseObj;
  12. //
  13. // Note!
  14. //
  15. // If this DLL is dynamically linked against the MFC
  16. // DLLs, any functions exported from this DLL which
  17. // call into MFC must have the AFX_MANAGE_STATE macro
  18. // added at the very beginning of the function.
  19. //
  20. // For example:
  21. //
  22. // extern "C" BOOL PASCAL EXPORT ExportedFunction()
  23. // {
  24. // AFX_MANAGE_STATE(AfxGetStaticModuleState());
  25. // // normal function body here
  26. // }
  27. //
  28. // It is very important that this macro appear in each
  29. // function, prior to any calls into MFC. This means that
  30. // it must appear as the first statement within the
  31. // function, even before any object variable declarations
  32. // as their constructors may generate calls into the MFC
  33. // DLL.
  34. //
  35. // Please see MFC Technical Notes 33 and 58 for additional
  36. // details.
  37. //
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CDataManagerApp
  40. BEGIN_MESSAGE_MAP(CDataManagerApp, CWinApp)
  41. //{{AFX_MSG_MAP(CDataManagerApp)
  42. // NOTE - the ClassWizard will add and remove mapping macros here.
  43. // DO NOT EDIT what you see in these blocks of generated code!
  44. //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CDataManagerApp construction
  48. CDataManagerApp::CDataManagerApp()
  49. {
  50. // TODO: add construction code here,
  51. // Place all significant initialization in InitInstance
  52. m_bLoadedByMainProg = FALSE;
  53. }
  54. /////////////////////////////////////////////////////////////////////////////
  55. // The one and only CDataManagerApp object
  56. CDataManagerApp theApp;
  57. BOOL CDataManagerApp::GetObjFuncs(CString strAppName, Def_CreateObj* &fpCreateObj, Def_ReleaseObj* &fpReleaseObj)
  58. {
  59. fpCreateObj = NULL;
  60. fpReleaseObj = NULL;
  61. CString strAppNameThis = AfxGetAppName();
  62. strAppNameThis.MakeUpper();
  63. strAppName.MakeUpper();
  64. if(strAppName == strAppNameThis)
  65. {
  66. fpCreateObj = (Def_CreateObj*)CreateObj;
  67. fpReleaseObj = (Def_ReleaseObj*)ReleaseObj;
  68. }
  69. else
  70. {
  71. HMODULE hDll = NULL;
  72. if(!m_mapAllAppHandle.Lookup(strAppName, (void*&)hDll))
  73. {
  74. hDll = LoadLibrary(strAppName);
  75. if(GetProcAddress(hDll, "ReleaseObj") == NULL || GetProcAddress(hDll, "CreateObj") == NULL)
  76. {
  77. FreeLibrary(hDll);
  78. hDll = NULL;
  79. }
  80. else
  81. {
  82. m_mapAllAppHandle.SetAt(strAppName, hDll);
  83. }
  84. }
  85. if(hDll)
  86. {
  87. fpCreateObj = (Def_CreateObj*)GetProcAddress(hDll, "CreateObj");
  88. fpReleaseObj = (Def_ReleaseObj*)GetProcAddress(hDll, "ReleaseObj");
  89. }
  90. else
  91. {
  92. fpCreateObj = g_pfCreateObj;
  93. fpReleaseObj = g_pfReleaseObj;
  94. }
  95. }
  96. return (fpCreateObj != NULL && fpReleaseObj != NULL);
  97. }
  98. BOOL CDataManagerApp::InitInstance()
  99. {
  100. // TODO: Add your specialized code here and/or call the base class
  101. srand( (unsigned)time( NULL ) );
  102. #ifndef _DEBUG
  103. SetErrorMode(SEM_NOGPFAULTERRORBOX);
  104. #endif
  105. m_strAppPath = GetAppPath();
  106. m_strDllPath = GetDllPath();
  107. m_bLoadedByMainProg = (m_strDllPath == m_strAppPath);
  108. char szBuf[MAX_PATH];
  109. CString strMyDwIni = m_strDllPath + "\\MyDwCtl.Ini";
  110. GetPrivateProfileString("Language", "Language", "¼òÌåÖÐÎÄ", szBuf, MAX_PATH, strMyDwIni);
  111. m_nChineseType = GetPrivateProfileInt("Common", "ChnType", CHN_TYPE_SIMPL, strMyDwIni);
  112. if(CString(szBuf) != "¼òÌåÖÐÎÄ")
  113. m_nChineseType = CHN_TYPE_NONE;
  114. m_bJtToFj = (m_nChineseType == CHN_TYPE_TRAD);
  115. AddPathToEnvirPath(m_strDllPath);
  116. AddPathToEnvirPath(m_strAppPath);
  117. char szAppName[MAX_PATH+1] = {0};
  118. GetModuleFileName(NULL, szAppName, MAX_PATH);
  119. CString strAppName = szAppName;
  120. strAppName.MakeUpper();
  121. static BOOL bTranslate = GetPrivateProfileInt("Language", "Translate", 1, "DataCenter.ini");
  122. if(bTranslate && strAppName.Find("FRONTPG.EXE") == -1 && strAppName.Find("MSDEV.EXE") == -1)
  123. CLanguage::LoadDll();
  124. return CWinApp::InitInstance();
  125. }
  126. int CDataManagerApp::ExitInstance()
  127. {
  128. // TODO: Add your specialized code here and/or call the base class
  129. CString strAppName;
  130. HMODULE hDll = NULL;
  131. POSITION pos = m_mapAllAppHandle.GetStartPosition();
  132. while (pos)
  133. {
  134. m_mapAllAppHandle.GetNextAssoc(pos, strAppName, (void*&)hDll);
  135. FreeLibrary(hDll);
  136. }
  137. m_mapAllAppHandle.RemoveAll();
  138. return CWinApp::ExitInstance();
  139. }