Board index » cppbuilder » ActiveX Control : How can I call dynamically at run time

ActiveX Control : How can I call dynamically at run time

Hello Everybody

How can we call an activeX control in a Window of our own. I have only
(HWND) hWnd reference with me.

Thanks and regards

--
Pritpal Bedi, India
Vouch, the software that grows with you
http://www.vouchcac.com
vouch...@hotmail.com
(x)Harbour Demo  :
http://www.vouchcac.com/harbour/harbour.htm

 

Re:ActiveX Control : How can I call dynamically at run time


I'm not sure what you mean.  Do you mean the ActiveX control has already
been created ?  If so, how was it created and how did you get a reference to
the control ?

If the ActiveX control has not already been created, then if you know the
CLSID of the ActiveX control, you can use the TOleContainer control to
dynamically create and host the ActiveX control.  Once you have create the
ActiveX control using the TOleContainer it is then possible to query the
control for the COM interface on which you want to make method calls.

Phil.

Re:ActiveX Control : How can I call dynamically at run time


Phil

Quote
> If the ActiveX control has not already been created, then if you know the

CLSID of the ActiveX control, you can use the TOleContainer control to
dynamically create and host the ActiveX control.  Once you have create the
ActiveX control using the TOleContainer it is then possible to query the
control for the COM interface on which you want to make method calls .

Quote

Can you please forward small code example?

regards

--
Pritpal Bedi, India
Vouch, the software that grows with you
http://www.vouchcac.com
vouch...@hotmail.com
(x)Harbour Demo  :
http://www.vouchcac.com/harbour/harbour.htm

Re:ActiveX Control : How can I call dynamically at run time


Something like this...

First you will have to add a TOleContainer to your form, in the case of this
example named 'MyOleContainer'.  The following code would then create the
ActiveX control with the specified CLSID and query this control for an
interface and return the interface reference.

IMyExampleInterface* TMyForm::CreateActiveX(CLSID& aClassID)
{
   TCreateInfo createInfo;        // note: I'm not sure if all these are
required.
   createInfo.CreateType = ctNewObject;
   createInfo.ShowAsIcon = false;
   createInfo.IconMetaPict = 0;
   createInfo.FileName = "";
   createInfo.DataObject = NULL;

   createInfo.ClassID = aClassID;

   // create the ActiveX control

    // Note: I don't remember if this throws an exception on failure to
create
    // or if there is another way of checking for a failure here - you will
have to look into this yourself.
   MyOleContainer->CreateObjectFromInfo(createInfo);

    // Now query for the interface we want to make calls on:
   IMyExampleInterface* tmpInterface;

   HRESULT hr =
MyOleContainer->OleObjectInterface->QueryInterface(IID_IMyExampleInterface,
(void**)&tmpInterface);

    if(FAILED(hr)) throw Exception("Failed on query interface for
IMyExampleInterface");

    return tmpInterface;

Quote
}
"Pritpal Bedi" <vouch...@hotmail.com> wrote in message

news:3d1beb3f_1@dnews...
Quote
> Phil

> Can you please forward small code example?

> regards

> --
> Pritpal Bedi, India
> Vouch, the software that grows with you
> http://www.vouchcac.com
> vouch...@hotmail.com
> (x)Harbour Demo  :
> http://www.vouchcac.com/harbour/harbour.htm

Re:ActiveX Control : How can I call dynamically at run time


Thanks Phil

I will try to incorporate it.

Pritpal Bedi, India
Vouch, the software that grows with you
http://www.vouchcac.com
vouch...@hotmail.com
(x)Harbour Demo  :
http://www.vouchcac.com/harbour/harbour.htm

Quote
Phil Parker <par...@sensormatic.com> wrote in message

news:3d1c7e49$1_2@dnews...
Quote
> Something like this...

> First you will have to add a TOleContainer to your form, in the case of
this
> example named 'MyOleContainer'.  The following code would then create the
> ActiveX control with the specified CLSID and query this control for an
> interface and return the interface reference.

> IMyExampleInterface* TMyForm::CreateActiveX(CLSID& aClassID)
> {
>    TCreateInfo createInfo;        // note: I'm not sure if all these are
> required.
>    createInfo.CreateType = ctNewObject;
>    createInfo.ShowAsIcon = false;
>    createInfo.IconMetaPict = 0;
>    createInfo.FileName = "";
>    createInfo.DataObject = NULL;

>    createInfo.ClassID = aClassID;

>    // create the ActiveX control

>     // Note: I don't remember if this throws an exception on failure to
> create
>     // or if there is another way of checking for a failure here - you
will
> have to look into this yourself.
>    MyOleContainer->CreateObjectFromInfo(createInfo);

>     // Now query for the interface we want to make calls on:
>    IMyExampleInterface* tmpInterface;

>    HRESULT hr =

MyOleContainer->OleObjectInterface->QueryInterface(IID_IMyExampleInterface,

- Show quoted text -

Quote
> (void**)&tmpInterface);

>     if(FAILED(hr)) throw Exception("Failed on query interface for
> IMyExampleInterface");

>     return tmpInterface;
> }

> "Pritpal Bedi" <vouch...@hotmail.com> wrote in message
> news:3d1beb3f_1@dnews...
> > Phil

> > Can you please forward small code example?

> > regards

> > --
> > Pritpal Bedi, India
> > Vouch, the software that grows with you
> > http://www.vouchcac.com
> > vouch...@hotmail.com
> > (x)Harbour Demo  :
> > http://www.vouchcac.com/harbour/harbour.htm

Re:ActiveX Control : How can I call dynamically at run time


Quote
"Pritpal Bedi" <vouch...@hotmail.com> wrote in message

news:3d1da4b5_1@dnews...

Quote
> Thanks Phil

> I will try to incorporate it.

You're welcome.  One thing I forgot:

You need to activate the activex control.  I don't remember why this is
necessary (and I think there are limitations on when you can do the
activation - if I remember correctly the form must be visible at the time).

You will need the following:

MyOleContainer->DoVerb(ovPrimary);

or alternatively you may be able to set the TOleContainer's AutoActivate
property to aaGetFocus.

Phil.

Re:ActiveX Control : How can I call dynamically at run time


Hello Everybody

How can we call an activeX control in a Window of our own. I have only
(HWND) hWnd reference with me.

Thanks and regards

--
Pritpal Bedi, India
Vouch, the software that grows with you
http://www.vouchcac.com
vouch...@hotmail.com
(x)Harbour Demo  :
http://www.vouchcac.com/harbour/harbour.htm

Re:ActiveX Control : How can I call dynamically at run time


I'm not sure what you mean.  Do you mean the ActiveX control has already
been created ?  If so, how was it created and how did you get a reference to
the control ?

If the ActiveX control has not already been created, then if you know the
CLSID of the ActiveX control, you can use the TOleContainer control to
dynamically create and host the ActiveX control.  Once you have create the
ActiveX control using the TOleContainer it is then possible to query the
control for the COM interface on which you want to make method calls.

Phil.

Re:ActiveX Control : How can I call dynamically at run time


Phil

Quote
> If the ActiveX control has not already been created, then if you know the

CLSID of the ActiveX control, you can use the TOleContainer control to
dynamically create and host the ActiveX control.  Once you have create the
ActiveX control using the TOleContainer it is then possible to query the
control for the COM interface on which you want to make method calls .

Quote

Can you please forward small code example?

regards

--
Pritpal Bedi, India
Vouch, the software that grows with you
http://www.vouchcac.com
vouch...@hotmail.com
(x)Harbour Demo  :
http://www.vouchcac.com/harbour/harbour.htm

Re:ActiveX Control : How can I call dynamically at run time


Something like this...

First you will have to add a TOleContainer to your form, in the case of this
example named 'MyOleContainer'.  The following code would then create the
ActiveX control with the specified CLSID and query this control for an
interface and return the interface reference.

IMyExampleInterface* TMyForm::CreateActiveX(CLSID& aClassID)
{
   TCreateInfo createInfo;        // note: I'm not sure if all these are
required.
   createInfo.CreateType = ctNewObject;
   createInfo.ShowAsIcon = false;
   createInfo.IconMetaPict = 0;
   createInfo.FileName = "";
   createInfo.DataObject = NULL;

   createInfo.ClassID = aClassID;

   // create the ActiveX control

    // Note: I don't remember if this throws an exception on failure to
create
    // or if there is another way of checking for a failure here - you will
have to look into this yourself.
   MyOleContainer->CreateObjectFromInfo(createInfo);

    // Now query for the interface we want to make calls on:
   IMyExampleInterface* tmpInterface;

   HRESULT hr =
MyOleContainer->OleObjectInterface->QueryInterface(IID_IMyExampleInterface,
(void**)&tmpInterface);

    if(FAILED(hr)) throw Exception("Failed on query interface for
IMyExampleInterface");

    return tmpInterface;

Quote
}
"Pritpal Bedi" <vouch...@hotmail.com> wrote in message

news:3d1beb3f_1@dnews...
Quote
> Phil

> Can you please forward small code example?

> regards

> --
> Pritpal Bedi, India
> Vouch, the software that grows with you
> http://www.vouchcac.com
> vouch...@hotmail.com
> (x)Harbour Demo  :
> http://www.vouchcac.com/harbour/harbour.htm

Other Threads