Create and call DCOM

Source: Internet
Author: User

By using ATL, you can easily create DLL (in-process components) EXE and service (out-of-process components)
I think this is easy to handle.

It is also easy to insert simple COM objects into the project, but there is a small problem:
When creating DCOM, you need a DLL that generates a proxy/stub. This is a problem.

The procedure I have tried is to output the file to be created in the directory through the vc6 project.
A makefile with the extension of. mk.
CMD enter the Directory and then nmake-F <File Name>. mk will generate the proxy/stub DLL file.

Or, according to Zhang Haitao's article in vchelp, write it in project-> Setting post-build step.
Enter the nmake-F command <File Name>. mk. After writing, remember to output the MK file. Otherwise
The setting of the MK file post-build step does not work in the directory.

After the proxy/stub is configured, compile it, And then register the generated proxy/stub.
Regsvr32 <File Name>. dll
Register the generated DCOM as the server <File Name>. EXE regserver
In addition, configure DCOM attributes
Run dcomcnfg and find the DCOM to be configured.
Then, you can view its attributes and set it to the interactive user. Keep others by default. My System
Windows XP Professional SP2

Then you can create a client and create an MFC dialog box.
Then add # DEFINE _ win32_dcom to stdafx. h.
<Afxwin. h>
In this way, the pre-processor will
This definition is used to selectively introduce the header files required by DCOM.
The corresponding cocreateinstanceex and other functions are also supported.

Then copy the. h file in the DCOM server to the root directory.

Then you need to include this file
Copy clsid iid in. C to the project.
Then
Add such a short piece of code and connect to the server if there is no error.
Generally, the error is caused by the server IP address and access permission settings.
There is no intermediate proxy COM component registered with proxy/stub. In fact, communication between the two parties is through this proxy component.
.

// Todo: add extra initialization here
HR = coinitialize (null );
If (failed (HR ))
{
MessageBox ("Component Library Loading failed ");
Return false;
}

HR = coinitializesecurity (
Null, // points to Security Descriptor
-1, // count of entries in asauthsvc
Null, // array of names to register
Null, // reserved for future use
Rpc_c_authn_level_default, // The default authentication level for proxies
Rpc_c_imp_level_identify, // The default impersonation level for proxies
Null, // reserved; must be set to null
0, // additional client or server-side capabilities
Null // reserved for future use
);

/* Use conserverinfo to configure the server billgates as the server name or IP address */
Coserverinfo serverinfo = {0, l "billgates", null, 0 };
Multi_qi = {& iid_iunknown, null, noerror };
HR = cocreateinstanceex (clsid_idcom, null, clsctx_remote_server, & serverinfo, 1, & multi_qi );

If (failed (HR ))
{
MessageBox ("failed to create instance .");
Return false;
}

Punknown = (iunknown *) multi_qi.pitf;
HR = punknown-> QueryInterface (iid_iidcom, (void **) & DCOM );
Punknown-> release ();
Then you can use
The DCOM interface of the query is the iid_iidcom interface.
The actual interface varies depending on the project name you created and the inserted component name.
Iid_iidcom is a simple object component I have inserted.

Http://www.vchelp.net/itbookreview/view_paper.asp? Paper_id = 1156 [original]
Com books
Com technical insider
COM/DCOM programming guide
Principles and Applications of COM
After three books, you will find that although there are few Chinese books in COM, the content is definitely not as difficult as that in C ++. In addition, you will find that the more books you read, the more chaotic the original intention. Therefore, it is best to complete the junior high school as much as possible. Some experts may be able to focus on a large number of exercises and filter out other things, of course, their comprehension and logic abilities are slightly higher than ordinary people, but no matter what high people are, they are also based on the correct learning methods and hard work.
Its advanced and skilled skills are often just a moment. After this moment, we will immediately find our own shortcomings and work on them. That is why computer technology is developing so fast.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.