开发者

C++ Win32 -- COM Method: equivalent C declaration

开发者_开发知识库

I've been told that every COM method callable from C++ code (take for instance IHTMLDocument2::write) has an equivalent C declaration, usable from C code...

How do I find it?

Thanks in advance!


This particular interface is documented as being provided by <mshtml.h>. Now, as it happens the second and third line of that file are:

// Include the full header file that works for C
#include "mshtmlc.h"

Looking into that file, we find the declaration

    /* [id][vararg] */ HRESULT ( STDMETHODCALLTYPE *write )( 
        IHTMLDocument2 * This,
        /* [in] */ __RPC__in SAFEARRAY * psarray);

Note that this is actually a pointer to the IHTMLDocument2::write method.

Sometimes the C declaration is the same header; sometimes the declaration isn't publicly available. But the COM standard is an ABI (a binary interface) designed such that you can always write a C declaration. Could be painful though.


Method calls of the type R Interface::Foo(T1, ..., Tn) simply translate to R Foo(Interface*, T1, ..., Tn).

They are available when compiling as C, i.e. __cplusplus not defined, or CINTERFACE is defined.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜