Re: Using COM from Ansi C

Tech-Archive recommends: Fix windows errors by optimizing your registry



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


.



Relevant Pages

  • nmap build failure
    ... checking for C compiler default output... ... checking for cc option to accept ANSI C... ... checking host system type... ... checking sys/param.h presence... ...
    (freebsd-questions)
  • ANSI C compliance
    ... "My boss would fire me if I wrote 100% ANSI C code" ... standard which is defined by an international committee. ... as intended on all platforms for which you have an ANSI C compiler, ... Writing truly standard C as valued by the "regulars" ...
    (comp.lang.c)
  • Re: K&R Ex 1-3
    ... The ANSI C ... Standard of 1989 was a significant step forward for C. ... Given a choice between the best C compiler ever written for the Apple ...
    (comp.lang.c)
  • Re: ANSI C compliance
    ... > We are discussing whether this newsgroup should focus on 100% ANSI C ... > is a C standard which is defined by an international committee. ... behaviour of programs compiled with a C compiler, ... vendor then there are newsgroups for that too. ...
    (comp.lang.c)
  • Pre-information on Unicode in Delphi 2008
    ... with compiler warning "UTF16 to ANSI implicit ... So existing applications will no break. ... here will be many such compiler warnings. ...
    (borland.public.delphi.non-technical)