main.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 3k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. /*++
  2.    
  3.     Contains DLLMain and standard OLE COM object creation stuff.
  4. --*/
  5. #include <windows.h>
  6. #include <objbase.h>
  7. #include <shlobj.h>
  8. #include <olectl.h> // Dll[Un]RegisterServer
  9. #include "classfac.h"
  10. #include "psexsup.h"
  11. //   GUID stuff
  12. // this is only done once
  13. // TODO, see if this is appropriate
  14. #pragma data_seg(".text")
  15. #define INITGUID
  16. #include <initguid.h>
  17. #include <shlguid.h>
  18. #include "guid.h"
  19. #pragma data_seg()
  20. HINSTANCE   g_hInst;
  21. LONG        g_DllRefCount = 0;
  22. BOOL        g_bShowIETB;
  23. BOOL        g_bShowISTB;
  24. int         g_nColumn1;
  25. int         g_nColumn2;
  26. extern "C" BOOL WINAPI DllMain(
  27.     HINSTANCE hInstance,
  28.     DWORD dwReason,
  29.     LPVOID lpReserved
  30.     )
  31. {
  32.     switch(dwReason)
  33.     {
  34.         case DLL_PROCESS_ATTACH:
  35.             DisableThreadLibraryCalls(hInstance);
  36.             g_hInst = hInstance;
  37.             //
  38.             // initialize Protected Storage Support routines
  39.             //
  40.             
  41.             if(!InitializePStoreSupport())
  42.                 return FALSE;
  43.     //
  44. // init common controls
  45. //
  46.     INITCOMMONCONTROLSEX iccex;
  47.     iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  48.     iccex.dwICC = ICC_LISTVIEW_CLASSES;
  49.     InitCommonControlsEx(&iccex);
  50.             break;
  51.         case DLL_PROCESS_DETACH:
  52.             ShutdownPStoreSupport();
  53.             break;
  54.     }
  55.     return TRUE;
  56. }                                 
  57. STDAPI
  58. DllCanUnloadNow(
  59.     void
  60.     )
  61. {
  62.     return (g_DllRefCount ? S_FALSE : S_OK);
  63. }
  64. STDAPI
  65. DllGetClassObject(
  66.     REFCLSID rclsid,
  67.     REFIID riid,
  68.     LPVOID *ppReturn
  69.     )
  70. {
  71.     //
  72.     // if we don't support this classid, return the proper error code
  73.     //
  74.     if(!IsEqualCLSID(rclsid, CLSID_PStoreNameSpace))
  75.        return CLASS_E_CLASSNOTAVAILABLE;
  76.     //
  77.     // create a CClassFactory object and check it for validity
  78.     //
  79.     CClassFactory *pClassFactory = new CClassFactory();
  80.     if(NULL == pClassFactory)
  81.        return E_OUTOFMEMORY;
  82.     //
  83.     // get the QueryInterface return for our return value
  84.     //
  85.     HRESULT hResult = pClassFactory->QueryInterface(riid, ppReturn);
  86.     //
  87.     // call Release to decrement the ref count - creating the object set it to
  88.     // one and QueryInterface incremented it - since its being used externally
  89.     // (not by us), we only want the ref count to be 1
  90.     //
  91.     pClassFactory->Release();
  92.     return hResult;
  93. }
  94. //
  95. // overload new and delete so we don't need to bring in full CRT
  96. //
  97. void * __cdecl operator new(unsigned int cb)
  98. {
  99.     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb);
  100. }
  101. void __cdecl operator delete(void * pv)
  102. {
  103.     HeapFree(GetProcessHeap(), 0, pv);
  104. }