GME  13
Parser.cpp
Go to the documentation of this file.
00001 // MgaMetaParser.cpp : Implementation of DLL Exports.
00002 
00003 
00004 // Note: Proxy/Stub Information
00005 //      To merge the proxy/stub code into the object DLL, add the file 
00006 //      dlldatax.c to the project.  Make sure precompiled headers 
00007 //      are turned off for this file, and add _MERGE_PROXYSTUB to the 
00008 //      defines for the project.  
00009 //
00010 //      If you are not running WinNT4.0 or Win95 with DCOM, then you
00011 //      need to remove the following define from dlldatax.c
00012 //      #define _WIN32_WINNT 0x0400
00013 //
00014 //      Further, if you are running MIDL without /Oicf switch, you also 
00015 //      need to remove the following define from dlldatax.c.
00016 //      #define USE_STUBLESS_PROXY
00017 //
00018 //      Modify the custom build rule for MgaMetaParser.idl by adding the following 
00019 //      files to the Outputs.
00020 //          MgaMetaParser_p.c
00021 //          dlldata.c
00022 //      To build a separate proxy/stub DLL, 
00023 //      run nmake -f MgaMetaParserps.mk in the project directory.
00024 
00025 #include "stdafx.h"
00026 #include "resource.h"
00027 #include <initguid.h>
00028 #include "dlldatax.h"
00029 
00030 #include "Parser_i.c"
00031 #include "ParserLib_i.c"
00032 #include "Meta_i.c"
00033 #include "Core_i.c"
00034 
00035 #include "CommonError.h"
00036 #include "CommonSmart.h"
00037 #include "CommonStl.h"
00038 
00039 #include "MetaParser.h"
00040 #include "MgaDumper.h"
00041 #include "MgaParser.h"
00042 
00043 #ifdef _MERGE_PROXYSTUB
00044 extern "C" HINSTANCE hProxyDll;
00045 #endif
00046 
00047 CComModule _Module;
00048 
00049 BEGIN_OBJECT_MAP(ObjectMap)
00050 OBJECT_ENTRY(CLSID_MgaMetaParser, CMgaMetaParser)
00051 OBJECT_ENTRY(CLSID_MgaDumper, CMgaDumper)
00052 OBJECT_ENTRY(CLSID_MgaParser, CMgaParser)
00053 END_OBJECT_MAP()
00054 
00056 // DLL Entry Point
00057 
00058 extern "C"
00059 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
00060 {
00061     lpReserved;
00062 #ifdef _MERGE_PROXYSTUB
00063     if (!PrxDllMain(hInstance, dwReason, lpReserved))
00064         return FALSE;
00065 #endif
00066     if (dwReason == DLL_PROCESS_ATTACH)
00067     {
00068         _Module.Init(ObjectMap, hInstance, &LIBID_MGAParserLib);
00069         DisableThreadLibraryCalls(hInstance);
00070     }
00071     else if (dwReason == DLL_PROCESS_DETACH)
00072         _Module.Term();
00073     return TRUE;    // ok
00074 }
00075 
00077 // Used to determine whether the DLL can be unloaded by OLE
00078 
00079 STDAPI DllCanUnloadNow(void)
00080 {
00081 #ifdef _MERGE_PROXYSTUB
00082     if (PrxDllCanUnloadNow() != S_OK)
00083         return S_FALSE;
00084 #endif
00085     return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
00086 }
00087 
00089 // Returns a class factory to create an object of the requested type
00090 
00091 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
00092 {
00093 #ifdef _MERGE_PROXYSTUB
00094     if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
00095         return S_OK;
00096 #endif
00097     return _Module.GetClassObject(rclsid, riid, ppv);
00098 }
00099 
00101 // DllRegisterServer - Adds entries to the system registry
00102 
00103 STDAPI DllRegisterServer(void)
00104 {
00105 #ifdef _MERGE_PROXYSTUB
00106     HRESULT hRes = PrxDllRegisterServer();
00107     if (FAILED(hRes))
00108         return hRes;
00109 #endif
00110     // registers object, typelib and all interfaces in typelib
00111     return _Module.RegisterServer(TRUE);
00112 }
00113 
00115 // DllUnregisterServer - Removes entries from the system registry
00116 
00117 STDAPI DllUnregisterServer(void)
00118 {
00119 #ifdef _MERGE_PROXYSTUB
00120     PrxDllUnregisterServer();
00121 #endif
00122     return _Module.UnregisterServer(TRUE);
00123 }
00124 
00125