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

📄 0,1410,23185,00.html

📁 C++builder学习资料C++builder
💻 HTML
字号:
<HTML>



<HEAD>



<TITLE>DCOM Basics:  Creating your first DCOM client/server application</TITLE>

</HEAD>

<BODY MARGINWIDTH="5" MARGINHEIGHT="5" TOPMARGIN="0" LEFTMARGIN="0" BGCOLOR="#FFFFFF">



<A NAME="top"></A>

<table>



<TR>

   <td>

  

<b>

  

<SPAN CLASS="title3">DCOM Basics:  Creating your first DCOM client/server application</SPAN> 

		 

	<BR> 

 

</b> 

 

    <P> 

<BLOCKQUOTE CLASS="abstract"><B>Abstract:</B>Tutorial for setting up a DCOM client/server application</BLOCKQUOTE><P> 

  

  </table> 

<b><u>Tutorial for creating a basic DCOM application</u></b> 

<p><b>Setting up the Project directories:</b> 

<p>&nbsp;&nbsp;&nbsp; 1.&nbsp;&nbsp;&nbsp; Navigate to where you would  

like to save your source files.  

<br>&nbsp;&nbsp;&nbsp; 2.&nbsp;&nbsp;&nbsp; Create the following directory:  

<br>&nbsp;  

<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>  

testDCOM</i>  

<p>&nbsp;&nbsp;&nbsp; 3.&nbsp;&nbsp;&nbsp; Inside the testDCOM directory,  

make the following two directories:  

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  

<i>server</i>  

<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  

<i>client</i>  

<p>&nbsp;&nbsp;&nbsp; 4.&nbsp;&nbsp;&nbsp; Now, when saving the files associated  

with your projects, you should save them into their respective directories.  

<br>&nbsp;  

<p><b>Creating the DCOM server:</b>  

<p>&nbsp;&nbsp;&nbsp; 1.&nbsp;&nbsp;&nbsp; File&nbsp; |&nbsp; Close All  

<br>&nbsp;&nbsp;&nbsp; 2.&nbsp;&nbsp;&nbsp; File&nbsp; |&nbsp; New Application  

<br>&nbsp;&nbsp;&nbsp; 3.&nbsp;&nbsp;&nbsp; File&nbsp; |&nbsp; New&nbsp;  

|&nbsp; ActiveX&nbsp; |&nbsp; Automation Object  

<br>&nbsp;&nbsp;&nbsp; 4.&nbsp;&nbsp;&nbsp; CoClass Name:&nbsp; <i>testDCOM</i>,  

then click OK  

<br>&nbsp;&nbsp;&nbsp; 5.&nbsp;&nbsp;&nbsp; In the Type Library Editor,  

select ItestDCOM, add a method and call it <i>GetName</i>  

<br>&nbsp;&nbsp;&nbsp; 6.&nbsp;&nbsp;&nbsp; Click on the Parameters tab,  

&amp; set the following Parameters:  

<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  

Name:&nbsp; <i>Value</i>;&nbsp; Type: <i>BSTR *</i>;&nbsp; Modifier:&nbsp;  

<i>&#91;out, retval&#93;</i>  

<br>&nbsp;&nbsp;&nbsp; 7.&nbsp;&nbsp;&nbsp; Save the Unit as:&nbsp; <i>maintestDCOMServer.cpp</i>  

<br>&nbsp;&nbsp;&nbsp; 8.&nbsp;&nbsp;&nbsp; Save the Project as:&nbsp;  

<i>testDCOMServer.bpr</i>  

<br>&nbsp;&nbsp;&nbsp; 9.&nbsp;&nbsp;&nbsp; Save the other files as they  

are named.  

<br>&nbsp;&nbsp;&nbsp; 10.&nbsp; In testDCOMImpl.cpp, fill in the GetName  

function as follows:  

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STDMETHODIMP  

TtestDCOMImpl::GetName(BSTR* Value)  

<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  

&#123;  

<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  

<i>*Value = WideString("TtestDCOM").Detach();</i>  

<br><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  

return S_OK;</i>  

<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  

&#125;  

<p>&nbsp;&nbsp;&nbsp; 11.&nbsp; Project&nbsp; |&nbsp; Build All Projects  

<br>&nbsp;&nbsp;&nbsp; 12.&nbsp; Finally, run the server (this will register  

the server and let it appear in the dcomcnfg.exe utility  

<br>&nbsp;&nbsp;&nbsp; 13.&nbsp; File&nbsp; |&nbsp; Save All  

<br>&nbsp;&nbsp;&nbsp; 14.&nbsp; Close All.  

<br>&nbsp;  

<p><b>Creating the DCOM Client:</b>  

<p>&nbsp;&nbsp;&nbsp; 1.&nbsp;&nbsp;&nbsp; File&nbsp; |&nbsp; Close All  

<br>&nbsp;&nbsp;&nbsp; 2.&nbsp;&nbsp;&nbsp; File&nbsp; |&nbsp; New Application  

<br>&nbsp;&nbsp;&nbsp; 3.&nbsp;&nbsp;&nbsp; Project&nbsp; |&nbsp; Add to  

Project...&nbsp; |&nbsp; Choose, <i>testDCOMServer_TLB.cpp</i> (located  

where you saved the server project)  

<br>&nbsp;&nbsp;&nbsp; 4.&nbsp;&nbsp;&nbsp; Save the Unit as:&nbsp; <i>maintestDCOMClient.cpp</i>  

<br>&nbsp;&nbsp;&nbsp; 5.&nbsp;&nbsp;&nbsp; Save the Project as:&nbsp;  

<i>testDCOMClient.bpr</i>  

<br>&nbsp;&nbsp;&nbsp; 6.&nbsp;&nbsp;&nbsp; Add the following to the top  

of maintestDCOMClient.cpp:  

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <i>#include  

"testDCOMServer_TLB.h"</i>  

<p>&nbsp;&nbsp;&nbsp; 7.&nbsp;&nbsp;&nbsp; Add the following to maintestDCOMClient.h  

in the private section (class TForm1):  

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <i>TCOMItestDCOM  

Server;</i>  

<p>&nbsp;&nbsp;&nbsp; 8.&nbsp;&nbsp;&nbsp; Save the Unit as:&nbsp; <i>maintestDCOMClient.cpp</i>  

<br>&nbsp;&nbsp;&nbsp; 9.&nbsp;&nbsp;&nbsp; Save the Project as: <i>testDCOMClient.bpr</i>  

<br>&nbsp;&nbsp;&nbsp; 10.&nbsp; Add a <i>TButton</i> and a <i>TEdit</i>  

to the form.  

<br>&nbsp;&nbsp;&nbsp; 11.&nbsp; Change the Button Caption to "<i>Remote</i>"  

<br>&nbsp;&nbsp;&nbsp; 12.&nbsp; Change the Edit Caption to "<i>Computer</i>"  

<br>&nbsp;&nbsp;&nbsp; 13.&nbsp; Double click the button and add the event  

code below:  

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void __fastcall TForm1::Button1Click(TObject  

*Sender)  

<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#123;  

<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>  

Server = CotestDCOM::CreateRemote(WideString(Edit1->Text));</i>  

<br><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  

Form1->Caption = Server->GetName();</i>  

<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#125;  

<p>&nbsp;&nbsp;&nbsp; 14.&nbsp; Now, you may run the test.&nbsp; When the  

form appears, type the name of the computer you would like to connect to  

in the edit box and then click the button.&nbsp; If everything is set up  

correctly, it will print the name of the DCOM object in the (client) form  

caption (TtestDCOM).  

<br>Remember, the server must be first run on any machine that you intend  

to establish a remote DCOM connection.  

<br>&nbsp;&nbsp;&nbsp; 15.&nbsp; File&nbsp; |&nbsp; Save All  

<br>&nbsp;  

</body>  

   

</HTML>  

⌨️ 快捷键说明

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