VB-like VC ++ Development (3)-# Import

Source: Internet
Author: User

In VB, you can add the COM component to be used through "Reference". In VC ++, you can use the "# import" statement to add the COM component. Using "# import", VC ++ will automatically generate all the packaging classes of interfaces in COM components, and encapsulate the handling of COM exceptions, so that we can call them in a strongly typed way. Of course, "# import" is not necessary, for example, when we access the COM component through the idispatch or idispatchex interface.

 

# Import Syntax:

 # import "FILENAME" [attributes] filename can be a file containing a Type Library, such. olb ,. TLB ,. the DLL file filename can also be the guid of the Type Library, or the COM component id 
 

for example:

 // import the mshtml component # pragma warning (Disable: 4192) // avoid a large number of compilation warnings # import "mshtml. TLB "RENAME (" translateaccelerator "," translateaccelerator_html ") // import the MSXML component # import" progid: msxml2.domdocument "// import the ADODB component # import" id lib: 00000205-0000-0010-8000-00aa006d2ea4 "/Rename (" EOF "," endoffile ")/Rename (" error "," adoerror ") 
 

when developing a component for pimshell, the following suggestions are provided:

  1. try to import components through # import instead of using interfaces provided by Windows SDK. For example, the ixmldomdocument interface of ihtmldocument2 and MSXML components in the mshtml component is provided in the Windows SDK. As we mentioned earlier, when "# import" is used, VC ++ will automatically generate all packaging classes for interfaces in COM components and encapsulate the processing of COM exceptions.
  2. Use namespaces whenever possible. In this way, you can avoid conflicts with the interfaces provided by the Windows SDK, and make full use of the advantages of VC ++.
  3. reasonable use of # pragma warning reduces a lot of compilation warnings and accelerates project compilation.

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.