本篇文章介绍了如何写一个简单的DCOM服务端(EXE模式)。
1、VC新建工程,ATL->ATL Project(名称为ATLExe)->类型选择Executable(EXE)->Finish
2、工程视图,ATLExe工程,右键->Add->Class->ATL->ATL Simple Object->类名为JustATestExe,ProgID为ATLExe.JustATestExe
3、切换到类视图,ATLExe项目下的IJustATestExe接口上右键Add Method
名称:Add
参数1:[in]LONG a
参数2:[in]LONG b
参数3:[out,retval]LONG* c
4、类视图,ATLExe项目下的IJustATestExe接口上右键Add Method
名称:SayHiTo
参数1:[in]BSTR someOne
参数2:[out,retval]BSTR* retValue
5、打开JustATestExe.cpp完成两个函数
STDMETHODIMP CJustATestExe::Add(LONG a, LONG b, LONG* c)
{
// TODO: Add your implementation code here
*c = a+b;
return S_OK;
}
STDMETHODIMP CJustATestExe::SayHiTo(BSTR someOne, BSTR* retValue)
{
// TODO: Add your implementation code here
CComBSTR sResult("Hi ");
CComBSTR sName(someOne);
CComBSTR sMark("!");
sResult.AppendBSTR(sName);
sResult.AppendBSTR(sMark);
*retValue = sResult.Copy();
return S_OK;
}
6、编译
7、注册
ATLExe.exe /regserver
8、反注册
ATLExe.exe /unregserver