// TestMarshalCtl.cpp : Implementation of the CTestMarshalCtrl ActiveX Control class.

#include "stdafx.h"
#include "TestMarshal.h"
#include "TestMarshalCtl.h"
#include "TestMarshalPpg.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


IMPLEMENT_DYNCREATE(CTestMarshalCtrl, COleControl)


/////////////////////////////////////////////////////////////////////////////
// Message map

BEGIN_MESSAGE_MAP(CTestMarshalCtrl, COleControl)
	//{{AFX_MSG_MAP(CTestMarshalCtrl)
	// NOTE - ClassWizard will add and remove message map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG_MAP
	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// Dispatch map

BEGIN_DISPATCH_MAP(CTestMarshalCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CTestMarshalCtrl)
	DISP_FUNCTION(CTestMarshalCtrl, "SetArrayTest", SetArrayTest, VT_EMPTY, VTS_PI4)
	DISP_FUNCTION(CTestMarshalCtrl, "SetArrayTest1", SetArrayTest1, VT_EMPTY, VTS_I2)
	//}}AFX_DISPATCH_MAP
	DISP_FUNCTION_ID(CTestMarshalCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()


/////////////////////////////////////////////////////////////////////////////
// Event map

BEGIN_EVENT_MAP(CTestMarshalCtrl, COleControl)
	//{{AFX_EVENT_MAP(CTestMarshalCtrl)
	// NOTE - ClassWizard will add and remove event map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_EVENT_MAP
END_EVENT_MAP()


/////////////////////////////////////////////////////////////////////////////
// Property pages

// TODO: Add more property pages as needed.  Remember to increase the count!
BEGIN_PROPPAGEIDS(CTestMarshalCtrl, 1)
	PROPPAGEID(CTestMarshalPropPage::guid)
END_PROPPAGEIDS(CTestMarshalCtrl)


/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid

IMPLEMENT_OLECREATE_EX(CTestMarshalCtrl, "TESTMARSHAL.TestMarshalCtrl.1",
	0x6c175754, 0x6482, 0x4689, 0x89, 0xe0, 0x68, 0xa9, 0xa3, 0xd3, 0x31, 0x27)


/////////////////////////////////////////////////////////////////////////////
// Type library ID and version

IMPLEMENT_OLETYPELIB(CTestMarshalCtrl, _tlid, _wVerMajor, _wVerMinor)


/////////////////////////////////////////////////////////////////////////////
// Interface IDs

const IID BASED_CODE IID_DTestMarshal =
		{ 0x2da70060, 0x1c50, 0x4d1d, { 0x9e, 0x8f, 0xc8, 0x21, 0x47, 0x3f, 0xfe, 0x25 } };
const IID BASED_CODE IID_DTestMarshalEvents =
		{ 0x663ce652, 0x1c48, 0x480e, { 0xa5, 0x76, 0x9d, 0x51, 0x96, 0x48, 0xf6, 0x7d } };


/////////////////////////////////////////////////////////////////////////////
// Control type information

static const DWORD BASED_CODE _dwTestMarshalOleMisc =
	OLEMISC_ACTIVATEWHENVISIBLE |
	OLEMISC_SETCLIENTSITEFIRST |
	OLEMISC_INSIDEOUT |
	OLEMISC_CANTLINKINSIDE |
	OLEMISC_RECOMPOSEONRESIZE;

IMPLEMENT_OLECTLTYPE(CTestMarshalCtrl, IDS_TESTMARSHAL, _dwTestMarshalOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CTestMarshalCtrl::CTestMarshalCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CTestMarshalCtrl

BOOL CTestMarshalCtrl::CTestMarshalCtrlFactory::UpdateRegistry(BOOL bRegister)
{
	// TODO: Verify that your control follows apartment-model threading rules.
	// Refer to MFC TechNote 64 for more information.
	// If your control does not conform to the apartment-model rules, then
	// you must modify the code below, changing the 6th parameter from
	// afxRegApartmentThreading to 0.

	if (bRegister)
		return AfxOleRegisterControlClass(
			AfxGetInstanceHandle(),
			m_clsid,
			m_lpszProgID,
			IDS_TESTMARSHAL,
			IDB_TESTMARSHAL,
			afxRegApartmentThreading,
			_dwTestMarshalOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// CTestMarshalCtrl::CTestMarshalCtrl - Constructor

CTestMarshalCtrl::CTestMarshalCtrl()
{
	InitializeIIDs(&IID_DTestMarshal, &IID_DTestMarshalEvents);

	// TODO: Initialize your control's instance data here.
}


/////////////////////////////////////////////////////////////////////////////
// CTestMarshalCtrl::~CTestMarshalCtrl - Destructor

CTestMarshalCtrl::~CTestMarshalCtrl()
{
	// TODO: Cleanup your control's instance data here.
}


/////////////////////////////////////////////////////////////////////////////
// CTestMarshalCtrl::OnDraw - Drawing function

void CTestMarshalCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	// TODO: Replace the following code with your own drawing code.
	pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
	pdc->Ellipse(rcBounds);
}


/////////////////////////////////////////////////////////////////////////////
// CTestMarshalCtrl::DoPropExchange - Persistence support

void CTestMarshalCtrl::DoPropExchange(CPropExchange* pPX)
{
	ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
	COleControl::DoPropExchange(pPX);

	// TODO: Call PX_ functions for each persistent custom property.

}


/////////////////////////////////////////////////////////////////////////////
// CTestMarshalCtrl::OnResetState - Reset control to default state

void CTestMarshalCtrl::OnResetState()
{
	COleControl::OnResetState();  // Resets defaults found in DoPropExchange

	// TODO: Reset any other control state here.
}


/////////////////////////////////////////////////////////////////////////////
// CTestMarshalCtrl::AboutBox - Display an "About" box to the user

void CTestMarshalCtrl::AboutBox()
{
	CDialog dlgAbout(IDD_ABOUTBOX_TESTMARSHAL);
	dlgAbout.DoModal();
}


/////////////////////////////////////////////////////////////////////////////
// CTestMarshalCtrl message handlers

void CTestMarshalCtrl::SetArrayTest(long FAR* nParam) 
{
	// TODO: Add your dispatch handler code here
	CString sLogMessage;
	CString sTemp;

	for (int i = 0; i < 5; i ++ )
	{
		sTemp.Format("%d ", nParam[i]);
		sLogMessage += sTemp;
		nParam[i] = i;
	}

	AfxMessageBox(sLogMessage);
}

void CTestMarshalCtrl::SetArrayTest1(short nparam) 
{
	// TODO: Add your dispatch handler code here
	CString sLogMessage;
	CString sTemp;
	
	sLogMessage.Format("%d", nparam);

	AfxMessageBox(sLogMessage);
}
