By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,423 Members | 1,601 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,423 IT Pros & Developers. It's quick & easy.

ActiveX in DLL

P: n/a
I have an ActiveX component that I want to use in a library that I am
writing. As a first test I used the ActiveX component in a windows
form application. Adding the component created:

Ax[ActiveXName].dll
[ActiveXName].dll

I can not call the functions in the ActiveX component. In the next
step I tried to use the ActiveX component in a class library. I simply
added a reference to the corresponding COM component. This this only
[ActiveXName].dll was created. I assume this is ok because the
Ax...dll is just wrapping the component in a control (which I don't
need).

Now I have the following code:

ActiveXClassName class = new ActiveXClassName; //Note there is no Ax
in front of the class
class.DoSomething();

The second command produces and error: "COMException was unhandled.
Catastrphic failure (Exception from HRESULT:
0x8000FFFF(E_UNEXPECTED))"

I then added the following after instantiating the class:

((System.ComponentModel.ISupportInitialize)(class) ).BeginInit();

This produces the error: "Unable to cast COM object of type 'xxx' to
interface type 'System.ComponentModel.ISupportInitialize'. This
operation failed because the QueryInterface call on the COM component
for the interface with IID '{CF793A55-B9DD-30C2-A484-360AF143C228}'
failed due to the following error: No such interface supported
(Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."

So what do I need to do to use this ActiveX component in my class
library?

Thanks

Feb 2 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
In article <11**********************@v33g2000cwv.googlegroups .com>,
hu*******@yahoo.com says...
I have an ActiveX component that I want to use in a library that I am
writing. As a first test I used the ActiveX component in a windows
form application. Adding the component created:

Ax[ActiveXName].dll
[ActiveXName].dll
This looks like an ActiveX control. Is that what it is -- or is it an
ActiveX DLL? Two different things.
I can not call the functions in the ActiveX component.
Can you clarify that some more?

In the next
step I tried to use the ActiveX component in a class library. I simply
added a reference to the corresponding COM component. This this only
[ActiveXName].dll was created. I assume this is ok because the
Ax...dll is just wrapping the component in a control (which I don't
need).
If I recall, you're going to have a difficult time using a wrapped
ActiveX control in a class library since an ActiveX control is usually
designed to be hosted on a windows form that has a standard windows
message pump running. Without that message pump, the ActiveX control
will not work properly inside a class library.
--
Patrick Steele
http://weblogs.asp.net/psteele
Feb 2 '07 #2

P: n/a
On Feb 2, 6:17 am, Patrick Steele <patr...@mvps.orgwrote:
In article <1170402719.020557.302...@v33g2000cwv.googlegroups .com>,
hufaun...@yahoo.com says...
I have an ActiveX component that I want to use in a library that I am
writing. As a first test I used the ActiveX component in a windows
form application. Adding the component created:
Ax[ActiveXName].dll
[ActiveXName].dll

This looks like an ActiveX control. Is that what it is -- or is it an
ActiveX DLL? Two different things.
I can not call the functions in the ActiveX component.

Can you clarify that some more?
In the next
step I tried to use the ActiveX component in a class library. I simply
added a reference to the corresponding COM component. This this only
[ActiveXName].dll was created. I assume this is ok because the
Ax...dll is just wrapping the component in a control (which I don't
need).

If I recall, you're going to have a difficult time using a wrapped
ActiveX control in a class library since an ActiveX control is usually
designed to be hosted on a windows form that has a standard windows
message pump running. Without that message pump, the ActiveX control
will not work properly inside a class library.

--
Patrick Steelehttp://weblogs.asp.net/psteele
Patrick,

Thanks a lot for the response. I am not sure what the difference is
between an ActiveX control and ActiveX DLL. One sound like a GUI
component and the other a plain DLL but aren't all ActiveX components
a GUI component?

In any case, the file extension off the control is .ocx. Also I can
drag that control onto a window. It has no functionality in a window,
though. It seems to me they just did it this way to make it easier for
the programmer who wants to use the control.

Hm, it would be too bad if an ActiveX control (one with a GUI) could
not be used in a plain class library. Can somebody confirm that?

Thanks

Feb 2 '07 #3

P: n/a
<hu*******@yahoo.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
On Feb 2, 6:17 am, Patrick Steele <patr...@mvps.orgwrote:
>In article <1170402719.020557.302...@v33g2000cwv.googlegroups .com>,
hufaun...@yahoo.com says...
I have an ActiveX component that I want to use in a library that I am
writing. As a first test I used the ActiveX component in a windows
form application. Adding the component created:
Ax[ActiveXName].dll
[ActiveXName].dll

This looks like an ActiveX control. Is that what it is -- or is it an
ActiveX DLL? Two different things.
I can not call the functions in the ActiveX component.

Can you clarify that some more?
In the next
step I tried to use the ActiveX component in a class library. I simply
added a reference to the corresponding COM component. This this only
[ActiveXName].dll was created. I assume this is ok because the
Ax...dll is just wrapping the component in a control (which I don't
need).

If I recall, you're going to have a difficult time using a wrapped
ActiveX control in a class library since an ActiveX control is usually
designed to be hosted on a windows form that has a standard windows
message pump running. Without that message pump, the ActiveX control
will not work properly inside a class library.

--
Patrick Steelehttp://weblogs.asp.net/psteele

Patrick,

Thanks a lot for the response. I am not sure what the difference is
between an ActiveX control and ActiveX DLL. One sound like a GUI
component and the other a plain DLL but aren't all ActiveX components
a GUI component?

In any case, the file extension off the control is .ocx. Also I can
drag that control onto a window. It has no functionality in a window,
though. It seems to me they just did it this way to make it easier for
the programmer who wants to use the control.

Hm, it would be too bad if an ActiveX control (one with a GUI) could
not be used in a plain class library. Can somebody confirm that?

Thanks

An ocx is an ActiveX dll, which normally contains a number of ActiveX controls. ActiveX
controls must be hosted and need an Single Threaded Apartment thread to run in.
In your case, you need to set a reference to the ocx like you did initially, and you need to
initialize the thread to Join an STA, that is, you need to set the ApartmentState of the
thread to STA before starting the thread.

Willy.

Feb 2 '07 #4

P: n/a
On Feb 2, 8:24 am, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
<hufaun...@yahoo.comwrote in message

news:11**********************@q2g2000cwa.googlegro ups.com...


On Feb 2, 6:17 am, Patrick Steele <patr...@mvps.orgwrote:
In article <1170402719.020557.302...@v33g2000cwv.googlegroups .com>,
hufaun...@yahoo.com says...
I have an ActiveX component that I want to use in a library that I am
writing. As a first test I used the ActiveX component in a windows
form application. Adding the component created:
Ax[ActiveXName].dll
[ActiveXName].dll
This looks like an ActiveX control. Is that what it is -- or is it an
ActiveX DLL? Two different things.
I can not call the functions in the ActiveX component.
Can you clarify that some more?
In the next
step I tried to use the ActiveX component in a class library. I simply
added a reference to the corresponding COM component. This this only
[ActiveXName].dll was created. I assume this is ok because the
Ax...dll is just wrapping the component in a control (which I don't
need).
If I recall, you're going to have a difficult time using a wrapped
ActiveX control in a class library since an ActiveX control is usually
designed to be hosted on a windows form that has a standard windows
message pump running. Without that message pump, the ActiveX control
will not work properly inside a class library.
--
Patrick Steelehttp://weblogs.asp.net/psteele
Patrick,
Thanks a lot for the response. I am not sure what the difference is
between an ActiveX control and ActiveX DLL. One sound like a GUI
component and the other a plain DLL but aren't all ActiveX components
a GUI component?
In any case, the file extension off the control is .ocx. Also I can
drag that control onto a window. It has no functionality in a window,
though. It seems to me they just did it this way to make it easier for
the programmer who wants to use the control.
Hm, it would be too bad if an ActiveX control (one with a GUI) could
not be used in a plain class library. Can somebody confirm that?
Thanks

An ocx is an ActiveX dll, which normally contains a number of ActiveX controls. ActiveX
controls must be hosted and need an Single Threaded Apartment thread to run in.
In your case, you need to set a reference to the ocx like you did initially, and you need to
initialize the thread to Join an STA, that is, you need to set the ApartmentState of the
thread to STA before starting the thread.

Willy.- Hide quoted text -

- Show quoted text -
Excuse my ignorence but I am new to this ActiveX stuff and despite
reading up it I don't really have a handle on it yet.

Just for reference, I have an interface IMyInterface and several class
libraries that implement this interface (i.e. no GUI). One of these
class libraries needs to call functions from an ActiveX control (ocx).
This ActiveX control has a GUI who's only purpose probably is to
easily create a message handler. My class library then can be used
from a Windows Form, a console application, etc.

I am able to use this ActiveX control in a Windows Form application
but not in my class library. How would I do that?

Currently, I only reference [ActiveXName].dll in my class library. I
wonder if I would need to reference Ax[ActiveXName].dll instead and
use the class in that dll. I assume that would create a thread for me.
I was not successful in doing that either, though.

Thanks

Feb 2 '07 #5

P: n/a
<hu*******@yahoo.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
On Feb 2, 8:24 am, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
><hufaun...@yahoo.comwrote in message

news:11**********************@q2g2000cwa.googlegr oups.com...


On Feb 2, 6:17 am, Patrick Steele <patr...@mvps.orgwrote:
In article <1170402719.020557.302...@v33g2000cwv.googlegroups .com>,
hufaun...@yahoo.com says...
I have an ActiveX component that I want to use in a library that I am
writing. As a first test I used the ActiveX component in a windows
form application. Adding the component created:
Ax[ActiveXName].dll
[ActiveXName].dll
>This looks like an ActiveX control. Is that what it is -- or is it an
ActiveX DLL? Two different things.
I can not call the functions in the ActiveX component.
>Can you clarify that some more?
In the next
step I tried to use the ActiveX component in a class library. I simply
added a reference to the corresponding COM component. This this only
[ActiveXName].dll was created. I assume this is ok because the
Ax...dll is just wrapping the component in a control (which I don't
need).
>If I recall, you're going to have a difficult time using a wrapped
ActiveX control in a class library since an ActiveX control is usually
designed to be hosted on a windows form that has a standard windows
message pump running. Without that message pump, the ActiveX control
will not work properly inside a class library.
>--
Patrick Steelehttp://weblogs.asp.net/psteele
Patrick,
Thanks a lot for the response. I am not sure what the difference is
between an ActiveX control and ActiveX DLL. One sound like a GUI
component and the other a plain DLL but aren't all ActiveX components
a GUI component?
In any case, the file extension off the control is .ocx. Also I can
drag that control onto a window. It has no functionality in a window,
though. It seems to me they just did it this way to make it easier for
the programmer who wants to use the control.
Hm, it would be too bad if an ActiveX control (one with a GUI) could
not be used in a plain class library. Can somebody confirm that?
Thanks

An ocx is an ActiveX dll, which normally contains a number of ActiveX controls. ActiveX
controls must be hosted and need an Single Threaded Apartment thread to run in.
In your case, you need to set a reference to the ocx like you did initially, and you need
to
initialize the thread to Join an STA, that is, you need to set the ApartmentState of the
thread to STA before starting the thread.

Willy.- Hide quoted text -

- Show quoted text -

Excuse my ignorence but I am new to this ActiveX stuff and despite
reading up it I don't really have a handle on it yet.

Just for reference, I have an interface IMyInterface and several class
libraries that implement this interface (i.e. no GUI). One of these
class libraries needs to call functions from an ActiveX control (ocx).
This ActiveX control has a GUI who's only purpose probably is to
easily create a message handler. My class library then can be used
from a Windows Form, a console application, etc.

I am able to use this ActiveX control in a Windows Form application
but not in my class library. How would I do that?

Currently, I only reference [ActiveXName].dll in my class library. I
wonder if I would need to reference Ax[ActiveXName].dll instead and
use the class in that dll. I assume that would create a thread for me.
I was not successful in doing that either, though.

Thanks

The fact that you use the instance of the activeX control from a class library is
irrelevant, point is, that the class that holds the ActiveX control reference and calls it's
methods (and possibly sink it's events), needs a (1)pumping (2)STA thread to run in. You
absolutely need to pump the ActiveX controls message queue, failing to pump will block the
Finalizer thread whenever he needs to run the finalizer of the RCW.
The most obvious thread for this is the UI thread (an ActiveX control natural habitat), as
it fulfills both conditions. If you do want to use your class library from a non-UI
application, you'll have to create a *pumping* STA thread in your class library. But now you
have to answer the next question - how are the users of this class going to call the class
methods?

Willy.

Feb 3 '07 #6

P: n/a
Have you registered the ActiveX object? You'll need to do so before it will
allow instantiation.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
<hu*******@yahoo.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...
>I have an ActiveX component that I want to use in a library that I am
writing. As a first test I used the ActiveX component in a windows
form application. Adding the component created:

Ax[ActiveXName].dll
[ActiveXName].dll

I can not call the functions in the ActiveX component. In the next
step I tried to use the ActiveX component in a class library. I simply
added a reference to the corresponding COM component. This this only
[ActiveXName].dll was created. I assume this is ok because the
Ax...dll is just wrapping the component in a control (which I don't
need).

Now I have the following code:

ActiveXClassName class = new ActiveXClassName; //Note there is no Ax
in front of the class
class.DoSomething();

The second command produces and error: "COMException was unhandled.
Catastrphic failure (Exception from HRESULT:
0x8000FFFF(E_UNEXPECTED))"

I then added the following after instantiating the class:

((System.ComponentModel.ISupportInitialize)(class) ).BeginInit();

This produces the error: "Unable to cast COM object of type 'xxx' to
interface type 'System.ComponentModel.ISupportInitialize'. This
operation failed because the QueryInterface call on the COM component
for the interface with IID '{CF793A55-B9DD-30C2-A484-360AF143C228}'
failed due to the following error: No such interface supported
(Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."

So what do I need to do to use this ActiveX component in my class
library?

Thanks

Feb 4 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.