Skip to Main Content
Learning DCOM
book

Learning DCOM

by Thuan L. Thai
April 1999
Intermediate to advanced content levelIntermediate to advanced
502 pages
15h 5m
English
O'Reilly Media, Inc.
Content preview from Learning DCOM

The #import Technique

In this section, we’ll look at a different technique to communicate with OCRServer. In particular, we will use the #import technique to talk to distributed components. Visual C++ comes with a compiler directive, called #import, that works nicely with COM. Like the MFC ClassWizard, this directive reverse engineers the contents of a type library to create C++ representations of COM interfaces. You know how to add a handler for the Compiler button, so do that first and name the handler OnCompiler. In this handler, you will add code to use the IOcrProcessor interface with the #import technique.

The #import Statement

To use this technique, simply import the appropriate type library into your header or implementation file. For example, to get C++ representations of all interfaces stored within the OCRServer type library, simply add the following lines to OCRClientDlg.cpp:

#import "..\OCRServer\OCRServer.tlb"

The #import directive tells the compiler to generate C++ wrapper code from the type information stored in the indicated type library. Since type information can reside in files with extensions such as TLB, EXE, OCX, and DLL, you can use the #import directive on all these file types, as long as they have COM type information built in. This directive is pretty nifty because it comes with a number of useful attributes. By default, the reverse engineered code is wrapped within a C++ namespace[77] whose name is derived from that of the selected type library; in our case, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Windows Internals, Fifth Edition

Windows Internals, Fifth Edition

David A. Solomon Mark E. Russinovich and Alex Ionescu
Windows® via C/C++, 5th Edition

Windows® via C/C++, 5th Edition

Jeffrey Richter, Christophe Nasarre
Learning Go

Learning Go

Jon Bodner

Publisher Resources

ISBN: 9781449307011Supplemental ContentErrata Page