// Bank.cpp : implementation file
//

#include "stdafx.h"
#include "mymfc29a.h"
#include "Bank.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBank

IMPLEMENT_DYNCREATE(CBank, CCmdTarget)

CBank::CBank()
{
	m_dBalance = 0.0;
	EnableAutomation();
	
	// To keep the application running as long as an OLE automation 
	//	object is active, the constructor calls AfxOleLockApp.
	
	AfxOleLockApp();
}

CBank::~CBank()
{
	// To terminate the application when all objects created with
	// 	with OLE automation, the destructor calls AfxOleUnlockApp.
	
	AfxOleUnlockApp();
}


void CBank::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(CBank, CCmdTarget)
	//{{AFX_MSG_MAP(CBank)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BEGIN_DISPATCH_MAP(CBank, CCmdTarget)
	//{{AFX_DISPATCH_MAP(CBank)
	DISP_PROPERTY_EX(CBank, "Balance", GetBalance, SetBalance, VT_R8)
	DISP_FUNCTION(CBank, "Withdrawal", Withdrawal, VT_R8, VTS_R8)
	DISP_FUNCTION(CBank, "Deposit", Deposit, VT_EMPTY, VTS_R8)
	//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()

// Note: we add support for IID_IBank to support typesafe binding
//  from VBA.  This IID must match the GUID that is attached to the 
//  dispinterface in the .ODL file.

// {122FA935-F2E8-4EB0-B974-D0BF4C59E53D}
static const IID IID_IBank =
{ 0x122fa935, 0xf2e8, 0x4eb0, { 0xb9, 0x74, 0xd0, 0xbf, 0x4c, 0x59, 0xe5, 0x3d } };

BEGIN_INTERFACE_MAP(CBank, CCmdTarget)
	INTERFACE_PART(CBank, IID_IBank, Dispatch)
END_INTERFACE_MAP()

// {58E7A2CE-C23D-4A09-A1AD-E4710AE28E4D}
IMPLEMENT_OLECREATE2(CBank, "mymfc29A.Bank", 0x58e7a2ce, 0xc23d,
		0x4a09, 0xa1, 0xad, 0xe4, 0x71, 0xa, 0xe2, 0x8e, 0x4d)

/////////////////////////////////////////////////////////////////////////////
// CBank message handlers

double CBank::Withdrawal(double dAmount) 
{
	// TODO: Add your dispatch handler code here
	if (dAmount < 0.0) {
        return 0.0;
        }
        if (dAmount <= m_dBalance) {
            m_dBalance -= dAmount;
            return dAmount;
        }
        double dTemp = m_dBalance;
        m_dBalance = 0.0;
        return dTemp;
}

void CBank::Deposit(double dAmount) 
{
	// TODO: Add your dispatch handler code here
	if (dAmount < 0.0) {
            return;
        }
        m_dBalance += dAmount;
}

double CBank::GetBalance() 
{
	// TODO: Add your property handler here
	return m_dBalance;
}

void CBank::SetBalance(double newValue) 
{
	// TODO: Add your property handler here
	TRACE("Sorry, Doe, I can't do that!\n");
}

