Re: Using COM from Ansi C
- From: "Igor Tandetnik" <itandetnik@xxxxxxxx>
- Date: Wed, 12 Oct 2005 16:42:32 -0400
Colin <Colin@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> In my organization, we still have products based on obsolete watcom C
> compiler and ansi C.
>
> I would like to use MSXML in one of our applications. To do this, I
> need to use COM 100% through win32 API because I can not support
> classes and interfaces using the ANSI C compiler.
Actually, COM interfaces can be used from C. It's boring and tedious,
but it can be done. E.g. a QueryInterface call would look like this:
IUnknown* pUnk; // initialized somehow
ISomeInterface* pSI;
pUnk->lpVtbl->QueryInterface(pUnk, &IID_ISomeInterface, (void**)&pSI);
// Do something with pSI
pSI->lpVtbl->Release(pSI);
All COM headers are compilable by either C++ or C compiler.
MIDL-generated headers also define helpful macros for use in C programs
if you define COBJMACROS macro before including them. E.g. this is an
excerpt from msxml.h:
#define IXMLDOMNode_get_nodeName(This,name) \
(This)->lpVtbl -> get_nodeName(This,name)
so you can write
IXMLDOMNode* pNode;
BSTR name = 0;
IXMLDOMNode_get_nodeName(pNode, &name);
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
.
- Prev by Date: Re: COM Overhead vs. Standard DLL
- Next by Date: COM sometimes turns exceptions into HRESULTs, sometimes doesn't - why?
- Previous by thread: Adding a webbrowser control to an IRichEditOle Windowless RichEdit
- Next by thread: Re: Using COM from Ansi C
- Index(es):
Relevant Pages
|