GME  13
MgaDecorators.cpp
Go to the documentation of this file.
00001 // MgaDecorators.cpp : Implementation of DLL Exports.
00002 
00003 
00004 // Note: Proxy/Stub Information
00005 //      To build a separate proxy/stub DLL, 
00006 //      run nmake -f MgaDecoratorsps.mk in the project directory.
00007 
00008 #include "stdafx.h"
00009 #include "resource.h"
00010 #include <initguid.h>
00011 #include "Gme.h"
00012 #include "MgaDecoratorLib.h"
00013 #include "MgaDecoratorLib_i.c"
00014 #include "BoxDecoratorImpl.h"
00015 
00016 
00017 CComModule _Module;
00018 
00019 BEGIN_OBJECT_MAP(ObjectMap)
00020 OBJECT_ENTRY(CLSID_BoxDecorator, CBoxDecoratorImpl)
00021 END_OBJECT_MAP()
00022 
00023 class CMgaDecoratorsApp : public CWinApp
00024 {
00025 public:
00026 
00027 // Overrides
00028         // ClassWizard generated virtual function overrides
00029         //{{AFX_VIRTUAL(CMgaDecoratorsApp)
00030         public:
00031     virtual BOOL InitInstance();
00032     virtual int ExitInstance();
00033         //}}AFX_VIRTUAL
00034 
00035         //{{AFX_MSG(CMgaDecoratorsApp)
00036                 // NOTE - the ClassWizard will add and remove member functions here.
00037                 //    DO NOT EDIT what you see in these blocks of generated code !
00038         //}}AFX_MSG
00039         DECLARE_MESSAGE_MAP()
00040 };
00041 
00042 BEGIN_MESSAGE_MAP(CMgaDecoratorsApp, CWinApp)
00043         //{{AFX_MSG_MAP(CMgaDecoratorsApp)
00044                 // NOTE - the ClassWizard will add and remove mapping macros here.
00045                 //    DO NOT EDIT what you see in these blocks of generated code!
00046         //}}AFX_MSG_MAP
00047 END_MESSAGE_MAP()
00048 
00049 CMgaDecoratorsApp theApp;
00050 
00051 BOOL CMgaDecoratorsApp::InitInstance()
00052 {
00053 #if _MSC_VER < 1700
00054         // See MSDN example code for CWinApp::InitInstance: http://msdn.microsoft.com/en-us/library/ae6yx0z0.aspx
00055         // MFC module state handling code is changed with VC80.
00056         // We follow the Microsoft's suggested way, but in case of any trouble the set the
00057         // HKCU\Software\GME\AfxSetAmbientActCtxMod key to 0
00058         UINT uAfxSetAmbientActCtxMod = 1;
00059         HKEY hKey;
00060         if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\GME\\"),
00061                                          0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
00062         {
00063                 TCHAR szData[128];
00064                 DWORD dwKeyDataType;
00065                 DWORD dwDataBufSize = sizeof(szData)/sizeof(TCHAR);
00066 
00067                 if (RegQueryValueEx(hKey, _T("AfxSetAmbientActCtxMod"), NULL, &dwKeyDataType,
00068                                                         (LPBYTE) &szData, &dwDataBufSize) == ERROR_SUCCESS)
00069                 {
00070                         uAfxSetAmbientActCtxMod = _tcstoul(szData, NULL, 10);
00071                 }
00072 
00073                 RegCloseKey(hKey);
00074         }
00075         if (uAfxSetAmbientActCtxMod != 0)
00076         {
00077                 AfxSetAmbientActCtx(FALSE);
00078         }
00079 #endif
00080 
00081     _Module.Init(ObjectMap, m_hInstance, &LIBID_MGADECORATORLib);
00082     return CWinApp::InitInstance();
00083 }
00084 
00085 int CMgaDecoratorsApp::ExitInstance()
00086 {
00087     _Module.Term();
00088     return CWinApp::ExitInstance();
00089 }
00090 
00092 // Used to determine whether the DLL can be unloaded by OLE
00093 
00094 STDAPI DllCanUnloadNow(void)
00095 {
00096         AFX_MANAGE_STATE(AfxGetStaticModuleState());
00097 
00098     return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
00099 }
00100 
00102 // Returns a class factory to create an object of the requested type
00103 
00104 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
00105 {
00106     return _Module.GetClassObject(rclsid, riid, ppv);
00107 }
00108 
00110 // DllRegisterServer - Adds entries to the system registry
00111 
00112 STDAPI DllRegisterServer(void)
00113 {
00114     // registers object, typelib and all interfaces in typelib
00115     return _Module.RegisterServer(TRUE);
00116 }
00117 
00119 // DllUnregisterServer - Removes entries from the system registry
00120 
00121 STDAPI DllUnregisterServer(void)
00122 {
00123     return _Module.UnregisterServer(TRUE);
00124 }
00125 
00126