Re: COM Basics
<avesty@gmail.com> schrieb im Newsbeitrag
news:1161377945.996209.12300@i3g2000cwc.googlegroups.com...
Hi,
I'm attempting to use the COM interface incorporated into PDFCreator
(http://www.pdfforge.org/node/407/964#comment-964). I'm an absolute
beginner when it comes to COM, so if someone could give me some
beginner tips that would be great.
So far I import the .exe with:
#import "C:\Program Files\PDFCreator\PDFCreator.exe"
#import places all definitions in a namespace. If you don't know its name,
look into the .tlh file to find its name or specify a name with the import
directive:
#import "..." rename_namespace("MyNamespace")
or disable the namespace (not really recomended) with
#import "..." no_namespace
In my code:
::CoInitialize(NULL);
CComPtr<__clsPDFCreator> pdfObject;
#import without the raw_interfaces_only already defines smart pointers for
all interfaces. Just use the interface name with a Ptr suffix, i.e.
MyNamespace::__clsPDCCreatorPtr pdfObject(CLSID_clsPDFCreator);
(which also does the CoCreateInstance).
if (SUCCEEDED(pdfObject.CoCreateInstance(CLSID_clsPDFCreator)))
{
//try to do stuff with pdfObject
}
In the bit where I try to do stuff with pdfObject, none of the PDF
object methods are recognised. All give a 'is not a member of...'
error.
Remember that smart pointers are pointers. You have to use "->" to access
members of an interface, not ".".
HTH
Heinz