📄 csdn_文档中心_com样例(四)——客户端代码.htm
字号:
ULONG
row,<BR>
WCHAR *errorString );<BR>
END_INTERFACE_PART_STATIC( ErrorReport )<BR><BR><SPAN
style="COLOR: green">// ICompanyInfo</SPAN><BR>
BEGIN_INTERFACE_PART( CompanyInfo, ICompanyInfo
)<BR> INIT_INTERFACE_PART(
CMainFrame, CompanyInfo
)<BR>
STDMETHOD(GetDataServerInfo)( WCHAR
**pLoaction,<BR>
WCHAR
**pServer,<BR>
WCHAR **pPassword );<BR>
END_INTERFACE_PART_STATIC( CompanyInfo )<BR>};<BR>
<P><BR><FONT face=楷体_GB2312
size=4><STRONG>CMainFrame::OnCreate代码</STRONG></FONT></P><SPAN
style="COLOR: blue">int</SPAN><SPAN lang=EN-US
style="FONT-FAMILY: 宋体"> CMainFrame::OnCreate( LPCREATESTRUCT
lpCreateStruct )<BR>{<BR> <SPAN
style="COLOR: blue">if</SPAN>( CFrameWnd::OnCreate( lpCreateStruct )
== -1 )<BR> <SPAN
style="COLOR: blue">return</SPAN> -1;<BR><BR><SPAN
style="COLOR: green">// 创建基本工具条及状态条</SPAN><BR>
EnableDocking( CBRS_ALIGN_ANY );<BR><BR> <SPAN
style="COLOR: blue">if</SPAN>( !m_wndToolBar.CreateEx( <SPAN
style="COLOR: blue">this</SPAN>,<BR>
TBSTYLE_FLAT,<BR>
WS_CHILD | WS_VISIBLE | CBRS_TOP
|<BR>
CBRS_GRIPPER | CBRS_TOOLTIPS
|<BR>
CBRS_FLYBY |
CBRS_SIZE_DYNAMIC,<BR>
CRect( 0, 0, 0, 0 ) )
)<BR> WriteSoftErrorLog(
__LINE__,<BR>
__WFILE__,<BR>
IDS_MAINFRM_CREATETOOLBAR );<BR> <SPAN
style="COLOR: blue">else</SPAN><BR>
{<BR>
m_wndToolBar.EnableDocking( CBRS_ALIGN_ANY
);<BR> DockControlBar(
&m_wndToolBar );<BR>
}<BR><BR> <SPAN style="COLOR: blue">if</SPAN>(
!m_wndStatusBar.Create( <SPAN style="COLOR: blue">this</SPAN> )
||<BR>
!m_wndStatusBar.SetIndicators(
indicators,<BR>
<SPAN style="COLOR: blue">sizeof</SPAN>( indicators ) / <SPAN
style="COLOR: blue">sizeof</SPAN>( UINT ) ) )<BR>
{<BR> WriteSoftErrorLog(
__LINE__,<BR>
__WFILE__,<BR>
IDS_MAINFRM_CREATESTATUSBAR
);<BR> <SPAN
style="COLOR: blue">return</SPAN> -1;<BR>
}<BR> <SPAN
style="COLOR: blue">else</SPAN><BR>
{<BR> CCmdTarget *pTarget
=
m_wndStatusBar.Initial();<BR>
<SPAN style="COLOR: blue">if</SPAN>( !pTarget
)<BR>
{<BR>
WriteSoftErrorLog( __LINE__,<BR>
__WFILE__,<BR>
IDS_MAINFRM_CREATESTATUSBAR
);<BR>
<SPAN style="COLOR: blue">return</SPAN>
-1;<BR>
}<BR> ASSERT_VALID(
pTarget );<BR><BR> <SPAN style="COLOR: green">//
设置任务管理器的指针以使得CMainFrame聚合CTaskManager</SPAN><BR>
pTarget->m_pOuterUnknown =
GetControllingUnknown();<BR>
m_pTaskManager = <SPAN
style="COLOR: blue">reinterpret_cast</SPAN>< IUnknown* >(
&pTarget->m_xInnerUnknown
);<BR> ASSERT(
m_pTaskManager );<BR> }<BR><BR><SPAN
style="COLOR: green">//
创建组件类别管理器并获得模块CLSID枚举器</SPAN><BR>
IEnumCLSID *pEnum =
NULL;<BR> ICatInformation *pCat =
NULL;<BR> CATID tempCATID[1] = { CATID_Example
};<BR><BR> <SPAN style="COLOR: blue">if</SPAN>(
FAILED( CoCreateInstance(
CLSID_StdComponentCategoriesMgr,<BR>
NULL,<BR>
CLSCTX_INPROC_SERVER,<BR>
IID_ICatInformation,<BR>
<SPAN style="COLOR: blue">reinterpret_cast</SPAN>< <SPAN
style="COLOR: blue">void</SPAN>** >( &pCat ) ) )
||<BR> FAILED(
pCat->EnumClassesOfCategories( 1, tempCATID, 0, NULL, &pEnum
) ) )<BR>
{<BR> MessageBox(
L"致命错误!系统即将退出。", g_SysCaption
);<BR> WriteHardErrorLog(
__LINE__,<BR>
__WFILE__,<BR>
IDS_KILLINGERROR );<BR>
SafeRelease( pCat );<BR>
SafeRelease( pEnum );<BR>
<SPAN style="COLOR: blue">return</SPAN> -1;<BR>
}<BR> pCat->Release();<BR><BR><SPAN
style="COLOR: green">// 枚举每个模块信息</SPAN><BR>
g_theApp.BeginWaitCursor();<BR><BR>
CLSID
clsid;<BR> CStringW
temp;<BR> TEMPSTRUCT *pStruct =
NULL;<BR> IModuleUI
*pUI = NULL;<BR>
IMenuUpdate *pMenuUp = NULL;<BR> <SPAN
style="COLOR: blue">long</SPAN>
index = -1;<BR> IModuleSite
*pSite = <SPAN
style="COLOR: blue">static_cast</SPAN>< IModuleSite*
>(<BR>
GetInterface( &IID_IModuleSite ) );<BR><BR>
pSite->AddRef();<BR> <SPAN
style="COLOR: blue">while</SPAN>( pEnum->Next( 1, &clsid,
NULL ) == S_OK )<BR>
{<BR>
++index;<BR> pStruct =
<SPAN style="COLOR: blue">new</SPAN>
TEMPSTRUCT;<BR> <SPAN
style="COLOR: blue">if</SPAN>( !pStruct
)<BR>
{<BR>
WriteSoftErrorLog(
__LINE__,<BR>
__WFILE__,<BR>
IDS_OUTOFMEMORY
);<BR>
<SPAN
style="COLOR: blue">continue</SPAN>;<BR>
}<BR><BR> <SPAN style="COLOR: green">//
创建模块对象</SPAN><BR> <SPAN
style="COLOR: blue">if</SPAN>( FAILED( CoCreateInstance(
clsid,<BR>
NULL,<BR>
CLSCTX_INPROC_SERVER,<BR>
IID_IModule,<BR>
<SPAN style="COLOR: blue">reinterpret_cast</SPAN>< <SPAN
style="COLOR: blue">void</SPAN>**
>(<BR>
&pStruct->m_pModule ) ) )
)<BR>
{<BR>
WriteSoftErrorLog(
__LINE__,<BR>
__WFILE__,<BR>
IDS_MAINFRM_CREATEMODULE
);<BR>
<SPAN style="COLOR: blue">delete</SPAN>
pStruct;<BR>
<SPAN
style="COLOR: blue">continue</SPAN>;<BR>
}<BR> pStruct->m_CLSID
= clsid;<BR><BR> <SPAN style="COLOR: green">//
初始化模块</SPAN><BR> <SPAN
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -