⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 disp.cpp

📁 本程序创建了一个AcitveX控件
💻 CPP
字号:
// Disp.cpp : implementation file
//

#include "stdafx.h"
#include "myMFCDll.h"
#include "Disp.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDisp

IMPLEMENT_DYNCREATE(CDisp, CCmdTarget)

CDisp::CDisp()
{
	EnableAutomation();
	
	// To keep the application running as long as an OLE automation 
	//	object is active, the constructor calls AfxOleLockApp.
	
	AfxOleLockApp();
}

CDisp::~CDisp()
{
	// To terminate the application when all objects created with
	// 	with OLE automation, the destructor calls AfxOleUnlockApp.
	
	AfxOleUnlockApp();
}


void CDisp::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(CDisp, CCmdTarget)
	//{{AFX_MSG_MAP(CDisp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BEGIN_DISPATCH_MAP(CDisp, CCmdTarget)
	//{{AFX_DISPATCH_MAP(CDisp)
	DISP_FUNCTION(CDisp, "Add", Add, VT_I4, VTS_I4 VTS_I4)
	DISP_FUNCTION(CDisp, "Upper", Upper, VT_BSTR, VTS_BSTR)
	//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()

// Note: we add support for IID_IDisp to support typesafe binding
//  from VBA.  This IID must match the GUID that is attached to the 
//  dispinterface in the .ODL file.

// {809613A8-BEB3-4C85-9C67-9C33F95148CF}
static const IID IID_IDisp =
{ 0x809613a8, 0xbeb3, 0x4c85, { 0x9c, 0x67, 0x9c, 0x33, 0xf9, 0x51, 0x48, 0xcf } };

BEGIN_INTERFACE_MAP(CDisp, CCmdTarget)
	INTERFACE_PART(CDisp, IID_IDisp, Dispatch)
END_INTERFACE_MAP()

// {4BA0C93C-E243-4374-A48B-59184603E1A0}
IMPLEMENT_OLECREATE(CDisp, "myMFCDll.Disp", 0x4ba0c93c, 0xe243, 0x4374, 0xa4, 0x8b, 0x59, 0x18, 0x46, 0x3, 0xe1, 0xa0)

/////////////////////////////////////////////////////////////////////////////
// CDisp message handlers

long CDisp::Add(long n1,long n2)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	return n1+n2;									// 返回两个参数之和
}


BSTR CDisp::Upper(LPCTSTR str)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	CString strResult(str);
	strResult.MakeUpper();							// 将字符串转换成为大写字符串
	return strResult.AllocSysString();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -