Tutorial for creating a basic DCOM application
Setting up the Project directories:
1. Navigate to where you would
like to save your source files.
2. Create the following directory:
testDCOM
3. Inside the testDCOM directory,
make the following two directories:
server
client
4. Now, when saving the files associated
with your projects, you should save them into their respective directories.
Creating the DCOM server:
1. File | Close All
2. File | New Application
3. File | New
| ActiveX | Automation Object
4. CoClass Name: testDCOM,
then click OK
5. In the Type Library Editor,
select ItestDCOM, add a method and call it GetName
6. Click on the Parameters tab,
& set the following Parameters:
Name: Value; Type: BSTR *; Modifier:
[out, retval]
7. Save the Unit as: maintestDCOMServer.cpp
8. Save the Project as:
testDCOMServer.bpr
9. Save the other files as they
are named.
10. In testDCOMImpl.cpp, fill in the GetName
function as follows:
STDMETHODIMP
TtestDCOMImpl::GetName(BSTR* Value)
{
*Value = WideString("TtestDCOM").Detach();
return S_OK;
}
11. Project | Build All Projects
12. Finally, run the server (this will register
the server and let it appear in the dcomcnfg.exe utility
13. File | Save All
14. Close All.
Creating the DCOM Client:
1. File | Close All
2. File | New Application
3. Project | Add to
Project... | Choose, testDCOMServer_TLB.cpp (located
where you saved the server project)
4. Save the Unit as: maintestDCOMClient.cpp
5. Save the Project as:
testDCOMClient.bpr
6. Add the following to the top
of maintestDCOMClient.cpp:
#include
"testDCOMServer_TLB.h"
7. Add the following to maintestDCOMClient.h
in the private section (class TForm1):
TCOMItestDCOM
Server;
8. Save the Unit as: maintestDCOMClient.cpp
9. Save the Project as: testDCOMClient.bpr
10. Add a TButton and a TEdit
to the form.
11. Change the Button Caption to "Remote"
12. Change the Edit Caption to "Computer"
13. Double click the button and add the event
code below:
void __fastcall TForm1::Button1Click(TObject
*Sender)
{
Server = CotestDCOM::CreateRemote(WideString(Edit1->Text));
Form1->Caption = Server->GetName();
}
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).
Remember, the server must be first run on any machine that you intend
to establish a remote DCOM connection.
15. File | Save All
Connect with Us