> Now I'm trying to write a tiny VC client to do the same as the VB
> client, but I've come unstuck.
>
> I've #imported the .tlb file and am trying to use the smart pointer
> created therein, like this:
>
> IFooPtr pFoo ;
>
> ::CoInitialize(NULL);
>
> if (SUCCEEDED(pFoo.CreateInstance(_uuidof(IFoo) ) ) )
^^^^^^^^^^^^^
There the problem lies, I guess.
See, IFoo is an interface, and it's UUID is an interface UUID, which is
known as an IID. But _com_ptr_t::CreateInstance expects a CLSID, which is a
COM Class UUID. A COM class is what you see under the title of coclass in
the IDL. And if you have not done something weird, then the CLSID for the
Foo class must be obtainable via __uuidof(Foo) or CLSID_Foo.
> {
> pFoo->Bar(...);
>
> The problem is, CreateInstance() returns (rather, the smart pointer
> records when the function fails) REGDB_E_CLASSNOTREG, described by
> MSDN as follows:
Yes. CoCreateInstance( ) looks for a class with UUID __uuidof(IFoo) which
can't be found naturally, since __uuidof(IFoo) is an IID, not a CLSID.
> "A specified class is not registered in the registration database.
> Also can indicate that the type of server you requested in the CLSCTX
> enumeration is not registered or the values for the server types in
> the registry are corrupt. "
>
> Now, since CreateInstance() on a smart pointer doesn't give me a
> choice of CLSCTX_ constant, that isn't my problem; I traced into the
> code and it uses CLSCTX_ALL as it happens.
>
> The problem, I see from tracing the code, is when it tries to call
> CoCreateInstance() asking for IUnkown - then it returns this code and
> bombs out.
>
> But I don't understand why, if the VB client can use it quite happily?
Something else: in your COM server, you may have either created a dual
interface, or a pure IDispatch interface. A dual interface is an interface
derived from IDispatch. Its methods and properties can be called either
through IDispatch::Invoke( ) or the derived interface directly. Whereas a
pure IDispatch interface's methods can't be called through any derived
interface (because there isn't one) so you need to use IDispatch::Invoke( )
(or something like CComDispatchDriver) directly.
A dual interface is defined like this in the IDL:
[ ... ] interface IFoo : IDispatch {};
A pure IDispatch interface is defined like this in the IDL:
[ ... ] dispinterface IFoo {};
> I've hit so many brick walls in coding these last few weeks I feel
> like a crash test dummy!
We all have those days, don't we? :-)
-------------
Ehsan Akhgari
Farda Technology (www.farda-tech.com)
List Owner: [EMAIL PROTECTED]
[ Email: [EMAIL PROTECTED] ]
[ WWW: http://www.beginthread.com/Ehsan ]
You had not yet sought yourselves: then you found me. So do all believers;
thus all belief matters so little.
-Thus Spoke Zarathustra, F. W. Nietzsche