473,385 Members | 1,562 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,385 software developers and data experts.

OCX from a class library?

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
Nov 17 '05 #1
4 2860
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]
- mv*@spam.guard.caspershouse.com

"Ryan Hunnicutt" <Ryan Hu*******@discussions.microsoft.com> wrote in message
news:AC**********************************@microsof t.com...
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

Nov 17 '05 #2
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Ryan Hunnicutt" <Ryan Hu*******@discussions.microsoft.com> wrote in message
news:AC**********************************@microsof t.com...
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


Nov 17 '05 #3
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]
- mv*@spam.guard.caspershouse.com

"Ryan Hunnicutt" <Ry***********@discussions.microsoft.com> wrote in message
news:D5**********************************@microsof t.com...
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Ryan Hunnicutt" <Ryan Hu*******@discussions.microsoft.com> wrote in
message
news:AC**********************************@microsof t.com...
>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


Nov 17 '05 #4
I was afraid of that. Thanks.

"Nicholas Paldino [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Ryan Hunnicutt" <Ry***********@discussions.microsoft.com> wrote in message
news:D5**********************************@microsof t.com...
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Ryan Hunnicutt" <Ryan Hu*******@discussions.microsoft.com> wrote in
message
news:AC**********************************@microsof t.com...
>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


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Patrick | last post by:
Following earlier discussions about invoking a .NET class library via ..NET-COM Interop (using regasm /tlb) at...
4
by: Brian Shannon | last post by:
I am playing around with class libraries trying to understand how they work. I created a class library, library.vb. I placed the library.dll into the bin directory and set my reference. If I...
3
by: eBob.com | last post by:
I have several applications which mine web sites for personal information which they publish. They publish the info in one form, I transform the info into Excel spreadsheets. So all these...
4
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project...
5
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project...
0
by: tony | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. In this user control we have a class...
0
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something...
5
by: Jesper Schmidt | last post by:
When does CLR performs initialization of static variables in a class library? (1) when the class library is loaded (2) when a static variable is first referenced (3) when... It seems that...
0
by: drawing in aspnet | last post by:
Question about putting the data layer in a separate class library. I keep reading that the data layer should be separated from the presentation layer and put in its own class library. I am...
4
by: Steve Baer | last post by:
I've already tested this with C# and it works, but I'm being paranoid and I wanted to also check here. Our application has a large class library written in C++/CLI for plug-in projects. The...
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.