home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / addins / booknote / booknote.cpp < prev    next >
C/C++ Source or Header  |  1998-04-02  |  3KB  |  107 lines

  1. // booknote.cpp : Implementation of DLL Exports.
  2.  
  3.  
  4. // Note: Proxy/Stub Information
  5. //      To build a separate proxy/stub DLL, 
  6. //      run nmake -f booknoteps.mk in the project directory.
  7.  
  8. #include "stdafx.h"
  9. #include "resource.h"
  10. #include <initguid.h>
  11. #include "booknote.h"
  12.  
  13. #include "booknote_i.c"
  14. #include "MarkIt.h"
  15.  
  16.  
  17. CComModule _Module;
  18.  
  19. BEGIN_OBJECT_MAP(ObjectMap)
  20. OBJECT_ENTRY(CLSID_MarkIt, CMarkIt)
  21. END_OBJECT_MAP()
  22.  
  23. class CBooknoteApp : public CWinApp
  24. {
  25. public:
  26.  
  27. // Overrides
  28.     // ClassWizard generated virtual function overrides
  29.     //{{AFX_VIRTUAL(CBooknoteApp)
  30.     public:
  31.     virtual BOOL InitInstance();
  32.     virtual int ExitInstance();
  33.     //}}AFX_VIRTUAL
  34.  
  35.     //{{AFX_MSG(CBooknoteApp)
  36.         // NOTE - the ClassWizard will add and remove member functions here.
  37.         //    DO NOT EDIT what you see in these blocks of generated code !
  38.     //}}AFX_MSG
  39.     DECLARE_MESSAGE_MAP()
  40. };
  41.  
  42. BEGIN_MESSAGE_MAP(CBooknoteApp, CWinApp)
  43.     //{{AFX_MSG_MAP(CBooknoteApp)
  44.         // NOTE - the ClassWizard will add and remove mapping macros here.
  45.         //    DO NOT EDIT what you see in these blocks of generated code!
  46.     //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48.  
  49. CBooknoteApp theApp;
  50.  
  51. BOOL CBooknoteApp::InitInstance()
  52. {
  53.     _Module.Init(ObjectMap, m_hInstance, &LIBID_BOOKNOTELib);
  54.     return CWinApp::InitInstance();
  55. }
  56.  
  57. int CBooknoteApp::ExitInstance()
  58. {
  59.     _Module.Term();
  60.     return CWinApp::ExitInstance();
  61. }
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // Used to determine whether the DLL can be unloaded by OLE
  65.  
  66. STDAPI DllCanUnloadNow(void)
  67. {
  68.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  69.     return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  70. }
  71.  
  72. /////////////////////////////////////////////////////////////////////////////
  73. // Returns a class factory to create an object of the requested type
  74.  
  75. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  76. {
  77.     return _Module.GetClassObject(rclsid, riid, ppv);
  78. }
  79.  
  80. /////////////////////////////////////////////////////////////////////////////
  81. // DllRegisterServer - Adds entries to the system registry
  82.  
  83. STDAPI DllRegisterServer(void)
  84. {
  85.     // registers object, typelib and all interfaces in typelib
  86.     return _Module.RegisterServer(TRUE);
  87. }
  88.  
  89. /////////////////////////////////////////////////////////////////////////////
  90. // DllUnregisterServer - Removes entries from the system registry
  91.  
  92. STDAPI DllUnregisterServer(void)
  93. {
  94.     HRESULT hr = _Module.UnregisterServer();
  95.  
  96. #if _WIN32_WINNT >= 0x0400
  97.     if (FAILED(hr))
  98.         return hr;
  99.  
  100.     hr = UnRegisterTypeLib(LIBID_BOOKNOTELib, 1, 0, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), SYS_WIN32);
  101. #endif
  102.  
  103.     return hr;
  104. }
  105.  
  106.  
  107.