GME  13
ConstraintManager.cpp
Go to the documentation of this file.
00001 // ConstraintManager.cpp : Implementation of DLL Exports.
00002 
00003 
00004 // Note: Proxy/Stub Information
00005 //      To build a separate proxy/stub DLL,
00006 //      run nmake -f ConstraintManagerps.mk in the project directory.
00007 #include "Solve4786.h"
00008 #include "stdafx.h"
00009 #include "resource.h"
00010 #include <initguid.h>
00011 #include "ConstraintManager.h"
00012 
00013 #include "ConstraintManager_i.c"
00014 #include "ConstraintMgr.h"
00015 #include "Core_i.c"
00016 #include "Mga_i.c"
00017 #include "MgaUtil.h"
00018 #include "ExpressionChecker.h"
00019 
00020 CComModule _Module;
00021 
00022 BEGIN_OBJECT_MAP(ObjectMap)
00023 OBJECT_ENTRY(CLSID_ConstraintManager, CConstraintMgr)
00024 OBJECT_ENTRY(CLSID_ExpressionChecker, CExpressionChecker)
00025 END_OBJECT_MAP()
00026 
00027 class CConstraintManagerApp : public CWinApp
00028 {
00029 public:
00030 
00031 // Overrides
00032         // ClassWizard generated virtual function overrides
00033         //{{AFX_VIRTUAL(CConstraintManagerApp)
00034         public:
00035     virtual BOOL InitInstance();
00036     virtual int ExitInstance();
00037         //}}AFX_VIRTUAL
00038 
00039         //{{AFX_MSG(CConstraintManagerApp)
00040                 // NOTE - the ClassWizard will add and remove member functions here.
00041                 //    DO NOT EDIT what you see in these blocks of generated code !
00042         //}}AFX_MSG
00043         DECLARE_MESSAGE_MAP()
00044 };
00045 
00046 BEGIN_MESSAGE_MAP(CConstraintManagerApp, CWinApp)
00047         //{{AFX_MSG_MAP(CConstraintManagerApp)
00048                 // NOTE - the ClassWizard will add and remove mapping macros here.
00049                 //    DO NOT EDIT what you see in these blocks of generated code!
00050         //}}AFX_MSG_MAP
00051 END_MESSAGE_MAP()
00052 
00053 CConstraintManagerApp theApp;
00054 
00055 BOOL CConstraintManagerApp::InitInstance()
00056 {
00057 #if _MSC_VER < 1700
00058         // See MSDN example code for CWinApp::InitInstance: http://msdn.microsoft.com/en-us/library/ae6yx0z0.aspx
00059         // MFC module state handling code is changed with VC80.
00060         // We follow the Microsoft's suggested way, but in case of any trouble the set the
00061         // HKCU\Software\GME\AfxSetAmbientActCtxMod key to 0
00062         UINT uAfxSetAmbientActCtxMod = 1;
00063         HKEY hKey;
00064         if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\GME\\"),
00065                                          0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
00066         {
00067                 TCHAR szData[128];
00068                 DWORD dwKeyDataType;
00069                 DWORD dwDataBufSize = sizeof(szData)/sizeof(TCHAR);
00070 
00071                 if (RegQueryValueEx(hKey, _T("AfxSetAmbientActCtxMod"), NULL, &dwKeyDataType,
00072                                                         (LPBYTE) &szData, &dwDataBufSize) == ERROR_SUCCESS)
00073                 {
00074                         uAfxSetAmbientActCtxMod = _tcstoul(szData, NULL, 10);
00075                 }
00076 
00077                 RegCloseKey(hKey);
00078         }
00079         if (uAfxSetAmbientActCtxMod != 0)
00080         {
00081                 AfxSetAmbientActCtx(FALSE);
00082         }
00083 #endif
00084 
00085     _Module.Init(ObjectMap, m_hInstance, &LIBID_CONSTRAINTMANAGERLib);
00086     return CWinApp::InitInstance();
00087 }
00088 
00089 int CConstraintManagerApp::ExitInstance()
00090 {
00091     _Module.Term();
00092     return CWinApp::ExitInstance();
00093 }
00094 
00096 // Used to determine whether the DLL can be unloaded by OLE
00097 
00098 STDAPI DllCanUnloadNow(void)
00099 {
00100     AFX_MANAGE_STATE(AfxGetStaticModuleState());
00101     return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
00102 }
00103 
00105 // Returns a class factory to create an object of the requested type
00106 
00107 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
00108 {
00109     AFX_MANAGE_STATE(AfxGetStaticModuleState());//z1
00110         return _Module.GetClassObject(rclsid, riid, ppv);
00111 }
00112 
00113 class CComponentReg
00114 {
00115 public:
00116         static HRESULT RegisterComponent();
00117         static HRESULT UnregisterComponent();
00118 };
00119 
00120 
00121 HRESULT CComponentReg::UnregisterComponent() {
00122   COMTRY {
00123         CComPtr<IMgaRegistrar> registrar;
00124         COMTHROW(registrar.CoCreateInstance(OLESTR("Mga.MgaRegistrar")));
00125         COMTHROW(registrar->UnregisterComponent(CComBSTR(MGR_COMPONENT_PROGID), REGACCESS_SYSTEM));
00126         COMTHROW(registrar->UnregisterComponent(CComBSTR(EXP_COMPONENT_PROGID), REGACCESS_SYSTEM));
00127   } COMCATCH(;)
00128 }
00129 
00130 HRESULT CComponentReg::RegisterComponent() {
00131   COMTRY {
00132         CComPtr<IMgaRegistrar> registrar;
00133         COMTHROW(registrar.CoCreateInstance(OLESTR("Mga.MgaRegistrar")));
00134 
00135         COMTHROW(registrar->RegisterComponent(CComBSTR(MGR_COMPONENT_PROGID), MGR_CETYPE, CComBSTR(MGR_COMPONENT_NAME), REGACCESS_SYSTEM));
00136         COMTHROW(registrar->Associate(CComBSTR(MGR_COMPONENT_PROGID), CComBSTR(MGR_PARADIGM), REGACCESS_SYSTEM));
00137 
00138         COMTHROW(registrar->RegisterComponent(CComBSTR(EXP_COMPONENT_PROGID), EXP_CETYPE, CComBSTR(EXP_COMPONENT_NAME), REGACCESS_SYSTEM));
00139         COMTHROW(registrar->Associate(CComBSTR(EXP_COMPONENT_PROGID), CComBSTR(EXP_PARADIGM), REGACCESS_SYSTEM));
00140 
00141         #ifdef ICON_SUPPORT
00142         COMTHROW(registrar->put_ComponentExtraInfo( REGACCESS_SYSTEM, CComBSTR( EXP_COMPONENT_PROGID ), CComBSTR( "Icon" ), CComBSTR( ",IDI_EC_CHECKALL" ) ) );
00143         #endif
00144 
00145   } COMCATCH(;)
00146 }
00147 
00149 // DllRegisterServer - Adds entries to the system registry
00150 
00151 STDAPI DllRegisterServer(void)
00152 {
00153     AFX_MANAGE_STATE(AfxGetStaticModuleState());//z1
00154         // registers object, typelib and all interfaces in typelib
00155         HRESULT res = _Module.RegisterServer(TRUE);
00156         if(res == S_OK) {
00157                 COMRETURN( CComponentReg::RegisterComponent());
00158         }
00159     return res;
00160 }
00161 
00163 // DllUnregisterServer - Removes entries from the system registry
00164 
00165 STDAPI DllUnregisterServer(void)
00166 {
00167     AFX_MANAGE_STATE(AfxGetStaticModuleState());//z1
00168         HRESULT res = _Module.UnregisterServer(TRUE);
00169         if(res == S_OK) {
00170                 COMRETURN( CComponentReg::UnregisterComponent());
00171         }
00172         return res;
00173 }
00174 
00175