📄 scriptutils.cpp
字号:
// ScriptUtils.cpp : implementation file
//
#include "stdafx.h"
#include "SimpleClient.h"
#include "ScriptUtils.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CScriptUtils
IMPLEMENT_DYNCREATE(CScriptUtils, CCmdTarget)
CScriptUtils::CScriptUtils()
{
EnableAutomation();
}
CScriptUtils::~CScriptUtils()
{
}
void CScriptUtils::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(CScriptUtils, CCmdTarget)
//{{AFX_MSG_MAP(CScriptUtils)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(CScriptUtils, CCmdTarget)
//{{AFX_DISPATCH_MAP(CScriptUtils)
DISP_FUNCTION(CScriptUtils, "DoSomething", DoSomething, VT_BSTR, VTS_NONE)
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
// Note: we add support for IID_IScriptUtils to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
// {17415522-22C7-4F65-B130-36B685E45804}
static const IID IID_IScriptUtils =
{ 0x17415522, 0x22c7, 0x4f65, { 0xb1, 0x30, 0x36, 0xb6, 0x85, 0xe4, 0x58, 0x4 } };
BEGIN_INTERFACE_MAP(CScriptUtils, CCmdTarget)
INTERFACE_PART(CScriptUtils, IID_IScriptUtils, Dispatch)
END_INTERFACE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScriptUtils message handlers
BSTR CScriptUtils::DoSomething()
{
CString strResult = "Comes from CScriptUtils::DoSomething";
AfxMessageBox(strResult);
return strResult.AllocSysString();
}
STDMETHODIMP CHost::GetItemInfo(LPCOLESTR pstrName,DWORD dwReturnMask,
IUnknown **ppiunkItem, ITypeInfo **ppti)
{
HRESULT hr = S_OK;
// 对于类型库的查询不进行处理
if(dwReturnMask & SCRIPTINFO_ITYPEINFO)
{
if(ppti == NULL)
return E_INVALIDARG;
*ppti = NULL;
}
//传入Unknown接口,不进行处理
if(dwReturnMask & SCRIPTINFO_IUNKNOWN)
{
if(ppiunkItem == NULL)
return E_INVALIDARG;
*ppiunkItem = NULL;
}
//查询对象名称
if(!_wcsicmp(m_pNamedItem, pstrName))
{
if(dwReturnMask & SCRIPTINFO_IUNKNOWN)
{
//返回该暴露对象的接口指针
*ppiunkItem = m_lpUnkCtrl;
static_cast<IUnknown*>(*ppiunkItem)->AddRef();
}
if(dwReturnMask & SCRIPTINFO_ITYPEINFO)
{
IProvideClassInfo* pClsInfo = NULL;
hr = m_lpUnkCtrl->QueryInterface(IID_IProvideClassInfo, (void**)&pClsInfo);
if(pClsInfo != NULL)
{
hr = pClsInfo->GetClassInfo(ppti);
pClsInfo->Release();
}
}
}
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -