📄 fun.cpp
字号:
// Fun.cpp : Implementation of CFun
#include "stdafx.h"
#include "Simple1.h"
#include "Fun.h"
/////////////////////////////////////////////////////////////////////////////
// CFun
STDMETHODIMP CFun::Add(long n1, long n2, long *pVal)
{
*pVal = n1 + n2;
return S_OK;
}
STDMETHODIMP CFun::Cat(BSTR s1, BSTR s2, BSTR *pVal)
{
/************** 完全用 API 方式实现的 BSTR 字符串连接 ***************
int nLen1 = ::SysStringLen( s1 );
int nLen2 = ::SysStringLen( s2 );
*pVal = ::SysAllocStringLen( s1, nLen1 + nLen2 );
if( nLen2 )
{
::memcpy( *pVal + nLen1, s2, nLen2 * sizeof(WCHAR) );
// wcscat( *pVal, s2 ); // 但如果 s2 中包含 L'\0' 的话,则被截断。
}
return S_OK;
*********************************************************************/
//*************** 用 CComBSTR 包装实现 BSTR 字符串连接 ***************
CComBSTR sResult( s1 );
sResult.AppendBSTR( s2 );
*pVal = sResult.Copy(); // 产生一个副本
// *pVal = sResult.Detach(); // CComBSTR 对象和内部 BSTR 脱离,速度稍快
return S_OK;
//********************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -