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

  1. // ObjOne.cpp : implementation file
  2. //
  3. // This is a part of the Active Template Library.
  4. // Copyright (C) 1996-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Active Template Library Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Active Template Library product.
  12.  
  13. #include "premfcat.h"
  14. #include "MfcAtl.h"
  15. #include "ObjOne.h"
  16.  
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CObjectOne
  25.  
  26. IMPLEMENT_DYNCREATE(CObjectOne, CCmdTarget)
  27.  
  28. CObjectOne::CObjectOne()
  29. {
  30.     EnableAutomation();
  31.  
  32.     // To keep the application running as long as an OLE automation
  33.     //  object is active, the constructor calls AfxOleLockApp.
  34.  
  35.     AfxOleLockApp();
  36. }
  37.  
  38. CObjectOne::~CObjectOne()
  39. {
  40.     // To terminate the application when all objects created with
  41.     //  with OLE automation, the destructor calls AfxOleUnlockApp.
  42.  
  43.     AfxOleUnlockApp();
  44. }
  45.  
  46.  
  47. void CObjectOne::OnFinalRelease()
  48. {
  49.     // When the last reference for an automation object is released
  50.     // OnFinalRelease is called.  The base class will automatically
  51.     // deletes the object.  Add additional cleanup required for your
  52.     // object before calling the base class.
  53.  
  54.     CCmdTarget::OnFinalRelease();
  55. }
  56.  
  57.  
  58. BEGIN_MESSAGE_MAP(CObjectOne, CCmdTarget)
  59.     //{{AFX_MSG_MAP(CObjectOne)
  60.         // NOTE - the ClassWizard will add and remove mapping macros here.
  61.     //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63.  
  64. BEGIN_DISPATCH_MAP(CObjectOne, CCmdTarget)
  65.     //{{AFX_DISPATCH_MAP(CObjectOne)
  66.     DISP_FUNCTION(CObjectOne, "SayHello", SayHello, VT_BSTR, VTS_NONE)
  67.     //}}AFX_DISPATCH_MAP
  68. END_DISPATCH_MAP()
  69.  
  70. // Note: we add support for IID_IObjectOne to support typesafe binding
  71. //  from VBA.  This IID must match the GUID that is attached to the
  72. //  dispinterface in the .ODL file.
  73.  
  74. // {5D0CE84F-D909-11CF-91FC-00A0C903976F}
  75. static const IID IID_IObjectOne =
  76. { 0x5d0ce84f, 0xd909, 0x11cf, { 0x91, 0xfc, 0x0, 0xa0, 0xc9, 0x3, 0x97, 0x6f } };
  77.  
  78. BEGIN_INTERFACE_MAP(CObjectOne, CCmdTarget)
  79.     INTERFACE_PART(CObjectOne, IID_IObjectOne, Dispatch)
  80. END_INTERFACE_MAP()
  81.  
  82. // {5D0CE850-D909-11CF-91FC-00A0C903976F}
  83. IMPLEMENT_OLECREATE(CObjectOne, "MfcAtl.ObjectOne", 0x5d0ce850, 0xd909, 0x11cf, 0x91, 0xfc, 0x0, 0xa0, 0xc9, 0x3, 0x97, 0x6f)
  84.  
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CObjectOne message handlers
  87.  
  88. BSTR CObjectOne::SayHello()
  89. {
  90.     return SysAllocString(OLESTR("Hello from Object One!"));
  91. }
  92.