Add a bit of COM knowledge about _ com_ptr_t.

Source: Internet
Author: User

The TLB file is a description file. Through the TLB file, you can learn the COM interface in your DLL file.
And constant information, so that the user can know the interfaces and constants in your DLL.
You can use your interface. Of course, if your COM interface only needs to be used by yourself, you can not use the TLB file to tell
Other people.

When # import is used to introduce a COM component, it is automatically generated. tlh and. TLI files: These two files are the encapsulation of the COM class. tlh is the standard header file, which defines a smart pointer of the _ com_ptr_t type for each component class, And TLI isCodeFile, which encapsulates the COM component class members. You can import a msado15.dll file by yourself.

TLB often includes the following features:
Intelligent metric announcement: similar scene _ com_ptr_t refers to a smart metric. This case does not mark interface indicators, and CALLS addref and release are excluded, complex steps such as QueryInterface. In addition, it also hides the call for cocreateinstance to create a new COM object. This part uses _ com_smartptr_typedef to generate specialization version of _ com_ptr_t. For example:
_ Com_smartptr_typedef (imyinterface, _ uuidof (imyinterface ));
The compiler will expand the above program
Typedef _ com_ptr_t <_ com_iiid <imyinterface, _ uuidof (imyinterface)> imyinterfaceptr;

As mentioned above, a smart pointer is automatically added when you think about the content in. TLB. cocreateinstance is no longer needed when you create a COM object.
For example, after the library msado15.dll is introduced, the following sentence appears in the msado15.tlh file:
_ Com_smartptr_typedef (_ connection, _ uuidof (_ connection ));
This sentence will be extended by the compiler
Typedef _ com_ptr_t <_ com_iiid <_ connection, 0x0> _ connectionptr
Then you can use this smart pointer _ connectionptr. When creating a COM object

_ Connectionptr pmyconnect = NULL;
Hresult HR = Pmyconnect. createinstance (_ uuidof (connection ));

The connection in _ uuidof (connection) is a struct, which is actually like this

Struct   /**/ /*Coclass*/ Connection;

Defined in the msado15.tlh file.

Other types, such as _ recordsetptr and _ commandptr, are of the com_ptr_t type.

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.