GME
13
|
00001 // MgaUtil.cpp : Defines the initialization routines for the DLL. 00002 // 00003 00004 #include "stdafx.h" 00005 #include <initguid.h> 00006 #include "MgaUtilApp.h" 00007 00008 00009 #include "MgaResolver.h" 00010 #include "MgaRegistrar.h" 00011 #include "MgaLauncher.h" 00012 #include "MgaProgressDlg.h" 00013 #include "MgaClosure.h" 00014 #include "MgaEventLogger.h" 00015 #include "ComponentProxy.h" 00016 00017 #ifdef _DEBUG 00018 #define new DEBUG_NEW 00019 #undef THIS_FILE 00020 static char THIS_FILE[] = __FILE__; 00021 #endif 00022 00023 // 00024 // Note! 00025 // 00026 // If this DLL is dynamically linked against the MFC 00027 // DLLs, any functions exported from this DLL which 00028 // call into MFC must have the AFX_MANAGE_STATE macro 00029 // added at the very beginning of the function. 00030 // 00031 // For example: 00032 // 00033 // extern "C" BOOL PASCAL EXPORT ExportedFunction() 00034 // { 00035 // AFX_MANAGE_STATE(AfxGetStaticModuleState()); 00036 // // normal function body here 00037 // } 00038 // 00039 // It is very important that this macro appear in each 00040 // function, prior to any calls into MFC. This means that 00041 // it must appear as the first statement within the 00042 // function, even before any object variable declarations 00043 // as their constructors may generate calls into the MFC 00044 // DLL. 00045 // 00046 // Please see MFC Technical Notes 33 and 58 for additional 00047 // details. 00048 // 00049 00051 // CMgaUtilApp 00052 00053 BEGIN_MESSAGE_MAP(CMgaUtilApp, CWinApp) 00054 //{{AFX_MSG_MAP(CMgaUtilApp) 00055 // NOTE - the ClassWizard will add and remove mapping macros here. 00056 // DO NOT EDIT what you see in these blocks of generated code! 00057 //}}AFX_MSG_MAP 00058 END_MESSAGE_MAP() 00059 00061 // CMgaUtilApp construction 00062 00063 CMgaUtilApp::CMgaUtilApp() 00064 { 00065 // TODO: add construction code here, 00066 // Place all significant initialization in InitInstance 00067 } 00068 00070 // The one and only CMgaUtilApp object 00071 00072 CMgaUtilApp theApp; 00073 00074 00075 CComModule _Module; 00076 00077 BEGIN_OBJECT_MAP(ObjectMap) 00078 OBJECT_ENTRY(__uuidof(MgaResolver), CMgaResolver) 00079 OBJECT_ENTRY(__uuidof(MgaRegistrar), CMgaRegistrar) 00080 OBJECT_ENTRY(__uuidof(MgaLauncher), CMgaLauncher) 00081 OBJECT_ENTRY(__uuidof(MgaProgressDlg), CMgaProgressDlg) 00082 OBJECT_ENTRY(__uuidof(ComponentProxy), CComponentProxy) 00083 OBJECT_ENTRY(__uuidof(MgaClosure), CMgaClosure) 00084 OBJECT_ENTRY(__uuidof(MgaEventLogger), CMgaEventLogger) 00085 END_OBJECT_MAP() 00086 00087 STDAPI DllCanUnloadNow(void) 00088 { 00089 return (_Module.GetLockCount() == 0) ? S_OK : S_FALSE; 00090 } 00091 00093 // Returns a class factory to create an object of the requested type 00094 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) 00095 { 00096 return _Module.GetClassObject(rclsid, riid, ppv); 00097 } 00099 // DllRegisterServer - Adds entries to the system registry 00100 STDAPI DllRegisterServer(void) 00101 { 00102 // registers object, typelib and all interfaces in typelib 00103 _Module.UpdateRegistryFromResource(IDR_MGAUTIL, TRUE); 00104 return _Module.RegisterServer(TRUE); 00105 } 00107 // DllUnregisterServer - Removes entries from the system registry 00108 STDAPI DllUnregisterServer(void) 00109 { 00110 _Module.UpdateRegistryFromResource(IDR_MGAUTIL, FALSE); 00111 _Module.UnregisterServer(TRUE); //TRUE indicates that typelib is unreg'd 00112 return S_OK; 00113 } 00114 00115 BOOL CMgaUtilApp::InitInstance() 00116 { 00117 #if _MSC_VER < 1700 00118 // See MSDN example code for CWinApp::InitInstance: http://msdn.microsoft.com/en-us/library/ae6yx0z0.aspx 00119 // MFC module state handling code is changed with VC80. 00120 // We follow the Microsoft's suggested way, but in case of any trouble the set the 00121 // HKCU\Software\GME\AfxSetAmbientActCtxMod key to 0 00122 UINT uAfxSetAmbientActCtxMod = 1; 00123 HKEY hKey; 00124 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\GME\\"), 00125 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) 00126 { 00127 TCHAR szData[128]; 00128 DWORD dwKeyDataType; 00129 DWORD dwDataBufSize = sizeof(szData)/sizeof(TCHAR); 00130 00131 if (RegQueryValueEx(hKey, _T("AfxSetAmbientActCtxMod"), NULL, &dwKeyDataType, 00132 (LPBYTE) &szData, &dwDataBufSize) == ERROR_SUCCESS) 00133 { 00134 uAfxSetAmbientActCtxMod = _tcstoul(szData, NULL, 10); 00135 } 00136 00137 RegCloseKey(hKey); 00138 } 00139 if (uAfxSetAmbientActCtxMod != 0) 00140 { 00141 AfxSetAmbientActCtx(FALSE); 00142 } 00143 #endif 00144 00145 if (!InitATL()) 00146 return FALSE; 00147 00148 return CWinApp::InitInstance(); 00149 00150 } 00151 00152 int CMgaUtilApp::ExitInstance() 00153 { 00154 _Module.Term(); 00155 00156 return CWinApp::ExitInstance(); 00157 00158 } 00159 00160 BOOL CMgaUtilApp::InitATL() 00161 { 00162 _Module.Init(ObjectMap, AfxGetInstanceHandle()); 00163 return TRUE; 00164 00165 } 00166 00167 regaccessmode_enum regacc_translate(int x) { 00168 if(x == 0) return REGACCESS_SYSTEM; 00169 if(x == 1) return REGACCESS_USER; 00170 if(x == 2) return REGACCESS_BOTH; 00171 ASSERT(false); 00172 return REGACCESS_NONE; 00173 }