OCX from a class library?

G

Guest

I have a C# application that reads from a serial stream. This information is
parsed out and saved to an xml file, also it is displayed in an GUI. The
application actually reads data from two seperate COMM ports (one is lap
times the other is track temperature readings). We recently purchased a USB
device to read air temperatures. This device came with an OCX control. The
problem I have is, if I have to put the OCX control in my form then I will
have to use some ugly kludge to get the data from the device into the module
that actually does the saving of the data. I hate ugly code. Is there
anyway to instantiate a class from an OCX in a class library? So far I've
had no success. Thanks.

Ryan
 
N

Nicholas Paldino [.NET/C# MVP]

Ryan,

When you set a reference to the OCX, it should import wrappers for all
of the classes that are publically exposed by that OCX. You should be able
to access them now as it is.
 
G

Guest

Thanks for the quick reply. Ok. I have a C# class library project with a
reference added for the OCX (USBTEMPAXLib). There is a class exposed
(USBTEMPAXLib.USBtempAxClass). I have the following code ->

USBTEMPAXLib.USBtempAXClass airtemp = new USBtempAXClass();
double temp = airtemp.Temperature;

When it hits the second line I get 'Catastrophic Failure'.

Does the component have to be hosted on a Windows Form to work? It does
work fine that way. Thanks for the help.


Nicholas Paldino said:
Ryan,

When you set a reference to the OCX, it should import wrappers for all
of the classes that are publically exposed by that OCX. You should be able
to access them now as it is.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ryan Hunnicutt said:
I have a C# application that reads from a serial stream. This information
is
parsed out and saved to an xml file, also it is displayed in an GUI. The
application actually reads data from two seperate COMM ports (one is lap
times the other is track temperature readings). We recently purchased a
USB
device to read air temperatures. This device came with an OCX control.
The
problem I have is, if I have to put the OCX control in my form then I will
have to use some ugly kludge to get the data from the device into the
module
that actually does the saving of the data. I hate ugly code. Is there
anyway to instantiate a class from an OCX in a class library? So far I've
had no success. Thanks.

Ryan
 
N

Nicholas Paldino [.NET/C# MVP]

Ryan,

Are you trying to create this on a thread that is not the UI thread? If
so, then yes, that is a problem.

Generally though, you will have to create it on a windows form (if it is
an ActiveX control) in order for it to work. You can always hide the
window, but it has to be hosted on a form.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ryan Hunnicutt said:
Thanks for the quick reply. Ok. I have a C# class library project with a
reference added for the OCX (USBTEMPAXLib). There is a class exposed
(USBTEMPAXLib.USBtempAxClass). I have the following code ->

USBTEMPAXLib.USBtempAXClass airtemp = new USBtempAXClass();
double temp = airtemp.Temperature;

When it hits the second line I get 'Catastrophic Failure'.

Does the component have to be hosted on a Windows Form to work? It does
work fine that way. Thanks for the help.


Nicholas Paldino said:
Ryan,

When you set a reference to the OCX, it should import wrappers for
all
of the classes that are publically exposed by that OCX. You should be
able
to access them now as it is.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

message
I have a C# application that reads from a serial stream. This
information
is
parsed out and saved to an xml file, also it is displayed in an GUI.
The
application actually reads data from two seperate COMM ports (one is
lap
times the other is track temperature readings). We recently purchased
a
USB
device to read air temperatures. This device came with an OCX control.
The
problem I have is, if I have to put the OCX control in my form then I
will
have to use some ugly kludge to get the data from the device into the
module
that actually does the saving of the data. I hate ugly code. Is there
anyway to instantiate a class from an OCX in a class library? So far
I've
had no success. Thanks.

Ryan
 
G

Guest

I was afraid of that. Thanks.

Nicholas Paldino said:
Ryan,

Are you trying to create this on a thread that is not the UI thread? If
so, then yes, that is a problem.

Generally though, you will have to create it on a windows form (if it is
an ActiveX control) in order for it to work. You can always hide the
window, but it has to be hosted on a form.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ryan Hunnicutt said:
Thanks for the quick reply. Ok. I have a C# class library project with a
reference added for the OCX (USBTEMPAXLib). There is a class exposed
(USBTEMPAXLib.USBtempAxClass). I have the following code ->

USBTEMPAXLib.USBtempAXClass airtemp = new USBtempAXClass();
double temp = airtemp.Temperature;

When it hits the second line I get 'Catastrophic Failure'.

Does the component have to be hosted on a Windows Form to work? It does
work fine that way. Thanks for the help.


Nicholas Paldino said:
Ryan,

When you set a reference to the OCX, it should import wrappers for
all
of the classes that are publically exposed by that OCX. You should be
able
to access them now as it is.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

message
I have a C# application that reads from a serial stream. This
information
is
parsed out and saved to an xml file, also it is displayed in an GUI.
The
application actually reads data from two seperate COMM ports (one is
lap
times the other is track temperature readings). We recently purchased
a
USB
device to read air temperatures. This device came with an OCX control.
The
problem I have is, if I have to put the OCX control in my form then I
will
have to use some ugly kludge to get the data from the device into the
module
that actually does the saving of the data. I hate ugly code. Is there
anyway to instantiate a class from an OCX in a class library? So far
I've
had no success. Thanks.

Ryan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top