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

  1. // varassoc.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "inproc.h"
  15. #include "varassoc.h"
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char BASED_CODE THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CVariantAssoc
  24.  
  25. IMPLEMENT_DYNCREATE(CVariantAssoc, CCmdTarget)
  26.  
  27. CVariantAssoc::CVariantAssoc()
  28. {
  29.     EnableAutomation();
  30.  
  31.     // To keep the application running as long as an OLE automation 
  32.     //  object is active, the constructor calls AfxOleLockApp.
  33.     
  34.     AfxOleLockApp();
  35. }
  36.  
  37. CVariantAssoc::~CVariantAssoc()
  38. {
  39.     // To terminate the application when all objects created with
  40.     //  with OLE automation, the destructor calls AfxOleUnlockApp.
  41.     
  42.     AfxOleUnlockApp();
  43. }
  44.  
  45. void CVariantAssoc::OnFinalRelease()
  46. {
  47.     // When the last reference for an automation object is released
  48.     //  OnFinalRelease is called.  This implementation deletes the 
  49.     //  object.  Add additional cleanup required for your object before
  50.     //  deleting it from memory.
  51.  
  52.     delete this;
  53. }
  54.  
  55. BEGIN_MESSAGE_MAP(CVariantAssoc, CCmdTarget)
  56.     //{{AFX_MSG_MAP(CVariantAssoc)
  57.         // NOTE - the ClassWizard will add and remove mapping macros here.
  58.     //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60.  
  61. BEGIN_DISPATCH_MAP(CVariantAssoc, CCmdTarget)
  62.     //{{AFX_DISPATCH_MAP(CVariantAssoc)
  63.     DISP_PROPERTY_EX(CVariantAssoc, "Key", GetKey, SetNotSupported, VT_VARIANT)
  64.     DISP_PROPERTY_EX(CVariantAssoc, "Value", GetValue, SetNotSupported, VT_VARIANT)
  65.     //}}AFX_DISPATCH_MAP
  66. END_DISPATCH_MAP()
  67.  
  68. // {84E099E0-F9F6-11cd-8C3D-00AA004BB3B7}
  69. static const IID IID_IVariantAssoc = { 0x84e099e0, 0xf9f6, 0x11cd, 
  70.     { 0x8c, 0x3d, 0x0, 0xaa, 0x0, 0x4b, 0xb3, 0xb7 } };
  71.  
  72. // Note: we add support for IID_IVariantAssoc to support typesafe binding
  73. // from VBA.  This IID must match the GUID that is attached to the 
  74. // dispinterface in the .ODL file.
  75.  
  76. BEGIN_INTERFACE_MAP(CVariantAssoc, CCmdTarget)
  77.     INTERFACE_PART(CVariantAssoc, IID_IVariantAssoc, Dispatch)
  78. END_INTERFACE_MAP()
  79.  
  80. /////////////////////////////////////////////////////////////////////////////
  81. // CVariantAssoc message handlers
  82.  
  83. VARIANT CVariantAssoc::GetKey() 
  84. {
  85.     COleVariant varResult = m_varKey;
  86.     return varResult.Detach();
  87. }
  88.  
  89. VARIANT CVariantAssoc::GetValue() 
  90. {
  91.     COleVariant varResult = m_varValue;
  92.     return varResult.Detach();
  93. }
  94.