GME  13
GMEActiveBrowser.cpp
Go to the documentation of this file.
00001 // GMEActiveBrowser.cpp : Implementation of CGMEActiveBrowserApp and DLL registration.
00002 
00003 #include "stdafx.h"
00004 #include "GMEActiveBrowser.h"
00005 #include <initguid.h>
00006 #include "GMEActiveBrowser_i.c"
00007 
00008 #ifdef _DEBUG
00009 #define new DEBUG_NEW
00010 #undef THIS_FILE
00011 static char THIS_FILE[] = __FILE__;
00012 #endif
00013 
00014 
00015 CGMEActiveBrowserApp NEAR theApp;
00016 
00017 const GUID CDECL BASED_CODE _tlid =
00018                 { 0xfda9edb8, 0xed6a, 0x468f, { 0xa3, 0xa9, 0xe9, 0x36, 0x1f, 0xee, 0xd0, 0x51 } };
00019 const WORD _wVerMajor = 1;
00020 const WORD _wVerMinor = 0;
00021 
00022 
00024 // CGMEActiveBrowserApp::InitInstance - DLL initialization
00025 
00026 BOOL CGMEActiveBrowserApp::InitInstance()
00027 {
00028 #if _MSC_VER < 1700
00029         // See MSDN example code for CWinApp::InitInstance: http://msdn.microsoft.com/en-us/library/ae6yx0z0.aspx
00030         // MFC module state handling code is changed with VC80.
00031         // We follow the Microsoft's suggested way, but in case of any trouble the set the
00032         // HKCU\Software\GME\AfxSetAmbientActCtxMod key to 0
00033         UINT uAfxSetAmbientActCtxMod = 1;
00034         HKEY hKey;
00035         if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\GME\\"),
00036                                          0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
00037         {
00038                 TCHAR szData[128];
00039                 DWORD dwKeyDataType;
00040                 DWORD dwDataBufSize = sizeof(szData)/sizeof(TCHAR);
00041 
00042                 if (RegQueryValueEx(hKey, _T("AfxSetAmbientActCtxMod"), NULL, &dwKeyDataType,
00043                                                         (LPBYTE) &szData, &dwDataBufSize) == ERROR_SUCCESS)
00044                 {
00045                         uAfxSetAmbientActCtxMod = _tcstoul(szData, NULL, 10);
00046                 }
00047 
00048                 RegCloseKey(hKey);
00049         }
00050         if (uAfxSetAmbientActCtxMod != 0)
00051         {
00052                 AfxSetAmbientActCtx(FALSE);
00053         }
00054 #endif
00055 
00056         BOOL bInit = COleControlModule::InitInstance();
00057         if (!InitATL())
00058                 return FALSE;
00059 
00060 
00061         if (bInit)
00062         {
00063                 m_pCtrl=NULL;
00064                 
00065                 SetRegistryKey(_T("GME\\GUI"));
00066 
00067                 free((void*)m_pszProfileName);
00068                 //Change the name of the .INI file.
00069                 //The CWinApp destructor will free the memory.
00070                 m_pszProfileName=_tcsdup(_T("GMEActiveBrowser"));
00071 
00072 
00073         }
00074 
00075         return bInit;
00076 }
00077 
00078 
00080 // CGMEActiveBrowserApp::ExitInstance - DLL termination
00081 
00082 int CGMEActiveBrowserApp::ExitInstance()
00083 {
00084         // TODO: Add your own module termination code here.
00085 
00086         _Module.Term();
00087 
00088 
00089         return COleControlModule::ExitInstance();
00090 }
00091 
00092 
00094 // DllRegisterServer - Adds entries to the system registry
00095 
00096 STDAPI DllRegisterServer(void)
00097 {
00098         AFX_MANAGE_STATE(_afxModuleAddrThis);
00099 
00100         if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
00101                 return ResultFromScode(SELFREG_E_TYPELIB);
00102 
00103         if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
00104                 return ResultFromScode(SELFREG_E_CLASS);
00105 
00106         return _Module.RegisterServer(TRUE);
00107 
00108         return NOERROR;
00109 }
00110 
00111 
00113 // DllUnregisterServer - Removes entries from the system registry
00114 
00115 STDAPI DllUnregisterServer(void)
00116 {
00117         AFX_MANAGE_STATE(_afxModuleAddrThis);
00118 
00119         if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
00120                 return ResultFromScode(SELFREG_E_TYPELIB);
00121 
00122         if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
00123                 return ResultFromScode(SELFREG_E_CLASS);
00124 
00125         _Module.UnregisterServer(TRUE); //TRUE indicates that typelib is unreg'd
00126 
00127         return NOERROR;
00128 }
00129 
00130         
00131 CComModule _Module;
00132 
00133 BEGIN_OBJECT_MAP(ObjectMap)
00134 END_OBJECT_MAP()
00135 
00136 STDAPI DllCanUnloadNow(void)
00137 {
00138         AFX_MANAGE_STATE(AfxGetStaticModuleState());
00139         return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
00140 }
00142 // Returns a class factory to create an object of the requested type
00143 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
00144 {
00145         AFX_MANAGE_STATE(AfxGetStaticModuleState());
00146         if(AfxDllGetClassObject(rclsid, riid, ppv) == S_OK)
00147                 return S_OK;
00148         return _Module.GetClassObject(rclsid, riid, ppv);
00149 }
00150 
00151 BOOL CGMEActiveBrowserApp::InitATL()
00152 {
00153         _Module.Init(ObjectMap, AfxGetInstanceHandle());
00154         return TRUE;
00155 
00156 }
00157 
00158 
00159 // Stupid MFC does not make the Control object reachable from the App.
00160 
00161 CGMEActiveBrowserCtrl* CGMEActiveBrowserApp::GetCtrl()
00162 {
00163         ASSERT(m_pCtrl);
00164         return m_pCtrl;
00165 }
00166 
00167 void CGMEActiveBrowserApp::SetCtrl(CGMEActiveBrowserCtrl *pCtrl)
00168 {
00169         m_pCtrl=pCtrl;
00170 }