📄 0,1410,23185,00.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> 1. Navigate to where you would
like to save your source files.
<br> 2. Create the following directory:
<br>
<br> <i>
testDCOM</i>
<p> 3. Inside the testDCOM directory,
make the following two directories:
<p>
<i>server</i>
<br>
<i>client</i>
<p> 4. Now, when saving the files associated
with your projects, you should save them into their respective directories.
<br>
<p><b>Creating the DCOM server:</b>
<p> 1. File | Close All
<br> 2. File | New Application
<br> 3. File | New
| ActiveX | Automation Object
<br> 4. CoClass Name: <i>testDCOM</i>,
then click OK
<br> 5. In the Type Library Editor,
select ItestDCOM, add a method and call it <i>GetName</i>
<br> 6. Click on the Parameters tab,
& set the following Parameters:
<br>
Name: <i>Value</i>; Type: <i>BSTR *</i>; Modifier:
<i>[out, retval]</i>
<br> 7. Save the Unit as: <i>maintestDCOMServer.cpp</i>
<br> 8. Save the Project as:
<i>testDCOMServer.bpr</i>
<br> 9. Save the other files as they
are named.
<br> 10. In testDCOMImpl.cpp, fill in the GetName
function as follows:
<p> STDMETHODIMP
TtestDCOMImpl::GetName(BSTR* Value)
<br>
{
<br>
<i>*Value = WideString("TtestDCOM").Detach();</i>
<br><i>
return S_OK;</i>
<br>
}
<p> 11. Project | Build All Projects
<br> 12. Finally, run the server (this will register
the server and let it appear in the dcomcnfg.exe utility
<br> 13. File | Save All
<br> 14. Close All.
<br>
<p><b>Creating the DCOM Client:</b>
<p> 1. File | Close All
<br> 2. File | New Application
<br> 3. Project | Add to
Project... | Choose, <i>testDCOMServer_TLB.cpp</i> (located
where you saved the server project)
<br> 4. Save the Unit as: <i>maintestDCOMClient.cpp</i>
<br> 5. Save the Project as:
<i>testDCOMClient.bpr</i>
<br> 6. Add the following to the top
of maintestDCOMClient.cpp:
<p> <i>#include
"testDCOMServer_TLB.h"</i>
<p> 7. Add the following to maintestDCOMClient.h
in the private section (class TForm1):
<p> <i>TCOMItestDCOM
Server;</i>
<p> 8. Save the Unit as: <i>maintestDCOMClient.cpp</i>
<br> 9. Save the Project as: <i>testDCOMClient.bpr</i>
<br> 10. Add a <i>TButton</i> and a <i>TEdit</i>
to the form.
<br> 11. Change the Button Caption to "<i>Remote</i>"
<br> 12. Change the Edit Caption to "<i>Computer</i>"
<br> 13. Double click the button and add the event
code below:
<p> void __fastcall TForm1::Button1Click(TObject
*Sender)
<br> {
<br> <i>
Server = CotestDCOM::CreateRemote(WideString(Edit1->Text));</i>
<br><i>
Form1->Caption = Server->GetName();</i>
<br> }
<p> 14. Now, you may run the test. 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. 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> 15. File | Save All
<br>
</body>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -