Ken Kozman wrote:
> > Um, COM *does* provide a spec for this, because you have to be
> > able to use COM objects across compiler boundaries. AFAIK this
> > is done as part of the declaration specification magic. And again
> > AFAIK (get me if i'm wrong) XPCOM does this as well -- I assume
> > it's folded into NSI_EXPORT or whatever the declaration magic
> > is for methods that are exported from a DLL ...
> >
> > But by all means, don't believe me. Go look at the symbol
> > table yourself. MS used to ship a utility called QuickView (or
> > maybe it came with VC++) that could look at the symbols a dll
> > provides ...
>
> It is my belief that COM does NOT provide this sort of mapping when you are
> exporting a class from a DLL, just when you are passing pointers to classes.
> The reason is the pointers only refer to the methods by an offset number
> (the virtual table) whereas the DLL exportation is done via a name (in this
> case a mangled name.) I'm about 99% sure of this, but I've never really been
> 100% sure of anything.
You are both right in some ways. There is some declarable attribute that
you can give to a class on some compilers to make their virtual tables
comply with the COM standard (thus enabling passing around pointers to
those objects).
Regular header+library still won't work, because of C++ unspecified ABI.
BUT...
Nothing forces you to use the COM class attribute (like "comobject" in
Code Warrior I think) only on COM classes! And using 'extern "C"' will
circumvent C++ mangling and let you declare a function that is callable
from just about any compiler.
Example:
--- foo.h ---
/* doesn't inherit from nsISupports */
class Foo __declspec(comobject) {
public:
/* only pure virtual methods here */
};
extern "C" static Foo* NewFoo();
--- fooimpl.h ---
#include "foo.h"
class FooImpl: public Foo {
public:
/* declare the implementation of the Foo pure virtuals */
};
--- foo.cpp ---
#include "fooimpl.h"
Foo* NewFoo() {
return new FooImpl;
}
/* implement FooImpl */
--
Pierre Phaneuf
http://www3.sympatico.ca/pphaneuf/