/*
*********************************************************************
*
*	The Essence of OLE
*
*	Source code sample
*
*	Copyright (c) 1996, Rolling Thunder Computing, Ipswich MA
*
*	e-mail: essence@rollthunder.com
*	CompuServe: 73540,3430
*	Web: http://www.rollthunder.com
*
*	File Name: MFCELIZA.CPP
*
*	Purpose: Custom IEliza interface using MFC
*
*********************************************************************
*/


#include "stdafx.h"
#include "mfcipeliza.h"
#include "MfcEliza.h"
#include "winnls.h"

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

extern void Eliza (LPSTR, LPSTR) ;




/////////////////////////////////////////////////////////////////////////////
// CMfcEliza

IMPLEMENT_DYNCREATE(CMfcEliza, CCmdTarget)


CMfcEliza::CMfcEliza()
{
}

CMfcEliza::~CMfcEliza()
{
}


BEGIN_MESSAGE_MAP(CMfcEliza, CCmdTarget)
	//{{AFX_MSG_MAP(CMfcEliza)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMfcEliza message handlers


BEGIN_INTERFACE_MAP (CMfcEliza, CCmdTarget)
	INTERFACE_PART (CMfcEliza, IID_IEliza, Eliza)
END_INTERFACE_MAP( ) 

ULONG CMfcEliza::XEliza::AddRef( )
{
	METHOD_PROLOGUE (CMfcEliza, Eliza)

	return pThis->ExternalAddRef( ) ;
}

ULONG CMfcEliza::XEliza::Release( ) 
{
	METHOD_PROLOGUE (CMfcEliza, Eliza) ;

	return pThis->ExternalRelease( ) ;
}
 

long CMfcEliza::XEliza::QueryInterface (REFIID riid, LPVOID *ppv)
{
	METHOD_PROLOGUE (CMfcEliza, Eliza) ;
	return pThis->ExternalQueryInterface (&riid, ppv) ;
}


HRESULT CMfcEliza::XEliza::Complain (LPOLESTR pIn, LPOLESTR pOut)
{

	char in [512], out [512] ;
	
	if (*pIn != 0x00)
	{
		WideCharToMultiByte (CP_ACP, 0, pIn, -1, in, sizeof(in), NULL, NULL) ;
		Eliza (in, out) ;
		MultiByteToWideChar (CP_ACP, 0, out, -1, pOut, 256) ;
	}
	return S_OK ;
}

/////////////////////////////////////////////////////////////////////////////
// Special entry points required for inproc servers

STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	return  AfxDllGetClassObject(rclsid, riid, ppv);
}

STDAPI DllCanUnloadNow(void)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	return AfxDllCanUnloadNow();
}

STDAPI DllRegisterServer(void)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	COleObjectFactory::UpdateRegistryAll();
	return S_OK;
}
