GME  13
PartBrowser.cpp
Go to the documentation of this file.
00001 // PartBrowser.cpp : Implementation of CPartBrowserApp and DLL registration.
00002 
00003 #include "stdafx.h"
00004 #include "PartBrowser.h"
00005 #include "PartBrowserCtrl.h"
00006 #include "PartBrowser_i.c"
00007 
00008 #ifdef _DEBUG
00009 #define new DEBUG_NEW
00010 #endif
00011 
00012 
00013 CPartBrowserApp NEAR theApp;
00014 
00015 const GUID CDECL BASED_CODE _tlid =
00016                 { 0xEA3F7431, 0x913A, 0x421F, { 0x9B, 0x9C, 0xBE, 0xB6, 0xA7, 0x35, 0x28, 0x5A } };
00017 const WORD _wVerMajor = 1;
00018 const WORD _wVerMinor = 0;
00019 
00020 
00021 CComModule _Module;
00022 
00023 BEGIN_OBJECT_MAP(ObjectMap)
00024 END_OBJECT_MAP()
00025 
00026 
00027 // CPartBrowserApp::InitInstance - DLL initialization
00028 
00029 BOOL CPartBrowserApp::InitInstance()
00030 {
00031 #if _MSC_VER < 1700
00032         // See MSDN example code for CWinApp::InitInstance: http://msdn.microsoft.com/en-us/library/ae6yx0z0.aspx
00033         // MFC module state handling code is changed with VC80.
00034         // We follow the Microsoft's suggested way, but in case of any trouble the set the
00035         // HKCU\Software\GME\AfxSetAmbientActCtxMod key to 0
00036         UINT uAfxSetAmbientActCtxMod = 1;
00037         HKEY hKey;
00038         if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\GME\\"),
00039                                          0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
00040         {
00041                 TCHAR szData[128];
00042                 DWORD dwKeyDataType;
00043                 DWORD dwDataBufSize = sizeof(szData)/sizeof(TCHAR);
00044 
00045                 if (RegQueryValueEx(hKey, _T("AfxSetAmbientActCtxMod"), NULL, &dwKeyDataType,
00046                                                         (LPBYTE) &szData, &dwDataBufSize) == ERROR_SUCCESS)
00047                 {
00048                         uAfxSetAmbientActCtxMod = _tcstoul(szData, NULL, 10);
00049                 }
00050 
00051                 RegCloseKey(hKey);
00052         }
00053         if (uAfxSetAmbientActCtxMod != 0)
00054         {
00055                 AfxSetAmbientActCtx(FALSE);
00056         }
00057 #endif
00058 
00059     _Module.Init(ObjectMap, m_hInstance, &LIBID_PartBrowserLib);
00060 
00061 //      return CWinApp::InitInstance();
00062         return COleControlModule::InitInstance();
00063 }
00064 
00065 
00066 
00067 // CPartBrowserApp::ExitInstance - DLL termination
00068 
00069 int CPartBrowserApp::ExitInstance()
00070 {
00071         // TODO: Add your own module termination code here.
00072     _Module.Term();
00073 
00074 //      return CWinApp::ExitInstance();
00075         return COleControlModule::ExitInstance();
00076 }
00077 
00078 /*
00080 // Used to determine whether the DLL can be unloaded by OLE
00081 
00082 STDAPI DllCanUnloadNow(void)
00083 {
00084         AFX_MANAGE_STATE(AfxGetStaticModuleState());
00085 
00086     return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
00087 }
00088 
00090 // Returns a class factory to create an object of the requested type
00091 
00092 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
00093 {
00094     AFX_MANAGE_STATE(AfxGetStaticModuleState());//z
00095         return _Module.GetClassObject(rclsid, riid, ppv);
00096 }
00097 */
00099 // DllRegisterServer - Adds entries to the system registry
00100 
00101 STDAPI DllRegisterServer(void)
00102 {
00103         AFX_MANAGE_STATE(AfxGetStaticModuleState());
00104 
00105         if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
00106                 return ResultFromScode(SELFREG_E_TYPELIB);
00107 
00108         if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
00109                 return ResultFromScode(SELFREG_E_CLASS);
00110 
00111         return NOERROR;
00112 }
00113 
00115 // DllUnregisterServer - Removes entries from the system registry
00116 
00117 STDAPI DllUnregisterServer(void)
00118 {
00119         AFX_MANAGE_STATE(AfxGetStaticModuleState());
00120 
00121         if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
00122                 return ResultFromScode(SELFREG_E_TYPELIB);
00123 
00124         if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
00125                 return ResultFromScode(SELFREG_E_CLASS);
00126 
00127         return NOERROR;
00128 }