473,327 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

ActiveX in DLL

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
6 8011
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
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
<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
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
<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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: AnalogKid | last post by:
Short question: What's the difference between SingleUse and MultiUse ? Long question: I've been writing some sample code to see how different Instancing values and threading models work. I...
1
by: wang xiaoyu | last post by:
Hello: i want use activex in wxpython program,but when i use MakeActiveXClass an exception occurs. this is my source code dealing the DICOM ocx.I must note that in this program "hwtxcontrol" is...
2
by: Fie Fie Niles | last post by:
This one XP machine (with IE 6) is having a problem viewing any ActiveX controls (created on VB6) on the Internet Explorer browser. I put the same ActiveX control in a VB program, and when I run...
6
by: Pippen | last post by:
I'm getting a little confused about what is supported in MS-SQL ActiveX and what is Visual Basic and what is VBScript. Can someone please point me to a website, recommend a book or if I've missed...
12
by: A.M. | last post by:
Hi at all, how can I do to insert into a HTML page a file .txt stored in the same directory of the server where is the html file that must display the text file.txt? Thank you very much P.Pietro
0
by: Ike | last post by:
I have an Activex Control created in VB6, which, displays no problem on any machine I have, but, on some machines of others, it does not. All machines are running either XP or Windows 2000, and all...
18
by: DartmanX | last post by:
Is there a simple way to determine if someone using Internet Explorer has completely disabled ActiveX controls? Jason
7
by: Jarod_24 | last post by:
I just downloaded a activex control that was written in C# and tried to view it on my PDA's Internet Explorer. At my regular PC it displayed just fine, but nothing showed up on the pda. Do...
4
by: Wilfried Mestdagh | last post by:
Hi, I have a C# application (VS2005) with Microsoft Mappoint activeX control on a form. At a certain moment I want to create a second one temporary in code. This seems not to work, when I try to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.