// Class1.cpp : implementation file
//
// Author : David Shepherd
// Copyright (c) 2002, DaeDoe-Software
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MFCDemo.h"
#include "Class1.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CClass1
IMPLEMENT_DYNCREATE(CClass1, CCmdTarget)
CClass1::CClass1()
{
EnableAutomation();
EnableConnections();
EnableTypeLib();
// To keep the application running as long as an OLE automation
// object is active, the constructor calls AfxOleLockApp.
AfxOleLockApp();
}
CClass1::~CClass1()
{
// To terminate the application when all objects created with
// with OLE automation, the destructor calls AfxOleUnlockApp.
AfxOleUnlockApp();
}
void CClass1::OnFinalRelease()
{
// When the last reference for an automation object is released
// OnFinalRelease is called. The base class will automatically
// deletes the object. Add additional cleanup required for your
// object before calling the base class.
CCmdTarget::OnFinalRelease();
}
BEGIN_MESSAGE_MAP(CClass1, CCmdTarget)
//{{AFX_MSG_MAP(CClass1)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(CClass1, CCmdTarget)
//{{AFX_DISPATCH_MAP(CClass1)
DISP_PROPERTY_EX(CClass1, "Text", GetText, SetText, VT_BSTR)
DISP_FUNCTION(CClass1, "ShowText", ShowText, VT_EMPTY, VTS_NONE)
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
// Note: we add support for IID_IClass1 to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
// {BB10A01E-7B75-4C58-8273-52994BCE0AE8}
static const IID IID_IClass1 =
{ 0xbb10a01e, 0x7b75, 0x4c58, { 0x82, 0x73, 0x52, 0x99, 0x4b, 0xce, 0xa, 0xe8 } };
BEGIN_INTERFACE_MAP(CClass1, CCmdTarget)
INTERFACE_PART(CClass1, IID_IClass1, Dispatch)
INTERFACE_PART(CClass1, IID_IConnectionPointContainer, ConnPtContainer)
END_INTERFACE_MAP()
BEGIN_CONNECTION_MAP(CClass1, CCmdTarget)
CONNECTION_PART(CClass1, DIID_IClass1Events, Class1CP)
END_CONNECTION_MAP()
// {ED1FFD26-423B-4A41-B52A-467A15D042A8}
IMPLEMENT_OLECREATE(CClass1, "MFCDemo.Class1", 0xed1ffd26, 0x423b, 0x4a41, 0xb5, 0x2a, 0x46, 0x7a, 0x15, 0xd0, 0x42, 0xa8)
IMPLEMENT_OLETYPELIB(CClass1, LIBID_MFCDemo, 1, 0)
/////////////////////////////////////////////////////////////////////////////
// CClass1 message handlers
BSTR CClass1::GetText()
{
// return the text
return m_Text.AllocSysString();
}
void CClass1::SetText(LPCTSTR lpszNewValue)
{
// set the text
m_Text=lpszNewValue;
// fire the text changed event
const CPtrArray *pConnections=m_xClass1CP.GetConnections();
for(long l=0; l<pConnections->GetSize(); l++)
{
CComVariant varResult;
DISPPARAMS disp = { NULL, NULL, 0, 0 };
IClass1Events *pDisp=
(IClass1Events *)pConnections->GetAt(l);
(void)pDisp->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &disp, &varResult, NULL, NULL);
}
}
void CClass1::ShowText()
{
// show the text in a message box
CString Message=_T("Text is ")+m_Text;
(void)AfxMessageBox(Message);
}