Board index » cppbuilder » what's wrong with this picture?

what's wrong with this picture?

Hi,
I'm new to BCB4 and COM, and I need help understanding what's wrong with
the following code:

    ICRemoteRegManager* pp = NULL;
    CoCRemoteRegManager::CoCreateInstance(CLSID_CRemoteRegManager,
                                          IID_ICRemoteRegManager,(void
**)&pp);

    pp->SetParam1 ((wchar_t*)"NANANA");

The appropriate type lib was imported.
pp stays NULL after the call to CoCreateInstance.

Am I using the right method?

Thanks.

 

Re:what's wrong with this picture?


Quote
Yariv wrote:

> Hi,
> I'm new to BCB4 and COM, and I need help understanding what's wrong with
> the following code:

>     ICRemoteRegManager* pp = NULL;
>     CoCRemoteRegManager::CoCreateInstance(CLSID_CRemoteRegManager,
>                                           IID_ICRemoteRegManager,(void
> **)&pp);

>     pp->SetParam1 ((wchar_t*)"NANANA");

That would be correct if you were using straight COM, but there are
wrapper classes.

You should do:

TCOMIRemoteRegManager mymanager =
CORemoteRegManager::CreateRemote(blah,blah,blah).
(Or, if you're doing it local, CORemoteRegManager::Create).

TCOMIRemoteRegManager and CORemoteRegManager will be defined in the
_TLB.H file generated when you import the type library.

Please note that the RemoteRegManager typelib MUST be instantiated on the remote
machine, as well.

Re:what's wrong with this picture?


Thanks.
now my code looks like this:
    TCOMICRemoteRegManager mngRemoteReg=CoCRemoteRegManager::Create ();
    mngRemoteReg.SetParam1 ((wchar_t*)"NANANA");

and when trying to run and use the object I get the following error:
"Create(intfObj):no such interface supported"

As far as I could tell, the Create method gets no parameters, so what is intfObj?

Quote
aphrael wrote:
> Yariv wrote:

> > Hi,
> > I'm new to BCB4 and COM, and I need help understanding what's wrong with
> > the following code:

> >     ICRemoteRegManager* pp = NULL;
> >     CoCRemoteRegManager::CoCreateInstance(CLSID_CRemoteRegManager,
> >                                           IID_ICRemoteRegManager,(void
> > **)&pp);

> >     pp->SetParam1 ((wchar_t*)"NANANA");

> That would be correct if you were using straight COM, but there are
> wrapper classes.

> You should do:

> TCOMIRemoteRegManager mymanager =
> CORemoteRegManager::CreateRemote(blah,blah,blah).
> (Or, if you're doing it local, CORemoteRegManager::Create).

> TCOMIRemoteRegManager and CORemoteRegManager will be defined in the
> _TLB.H file generated when you import the type library.

> Please note that the RemoteRegManager typelib MUST be instantiated on the remote
> machine, as well.

Other Threads