I have a legacy COM/ActiveX component (an OCX) that I need
to interface with from C# and the .NET framework.
Ordinarily, I would just add a reference to the OCX or add
it to the Toolbox (both of which work in their own ways),
but I need more control over the interfacing, and to that
end I am trying to write my own wrapper class, based on
what the IDE turns out, unfortunately all attempts have
failed.
Here is what I know so far:
When added as an ActiveX component to the Toolbox, I can
interface with it without problem, if I try to import it
as a standard COM component by adding a reference in the
Solution Explorer, I am able to create a new instance of
the object, but immediately after I call any method of the
component I get a COMException style unhandled exception
with the telling additional information of
simply "Catastrophic failure".
What strikes me as odd is that when adding the component
to the toolbar, both an ActiveX wrapper, as well as the
COM wrapper are built and this latter wrapper is identical
to the wrapper built when I simply add a reference. Like
the original, when I use it I get the 'catastrophic
failure message', despite the fact that the ActiveX
wrapper also uses the COM wrapper for it's interfacing to
the OCX.
Needing more control over the actual interface of the
wrapper, I started building my own from scratched based on
the code generated by the earlier steps and the .NET
Reflector. Unfortunately I am not even able to instantiate
this class. Should I try to do so I receive a
COMException, with the additional information of "COM
object with CLSID {0ABFE4A5-75E8-4268-9FBF-30F092863F4A}
is either not valid or not registered."
I have verified that the above CLSID (aka GUID) is that of
the OCX I am trying to interface with and that it is
properly installed and registered on the system.
The class name its self is defined as:
[ComImport, Guid("0ABFE4A5-75E8-4268-9FBF-30F092863F4A"),
TypeLibType((short) 0x1010)]
public class MyOCXTestClass
And it's methods all look very similar to the following:
[PreserveSig, MethodImpl
(MethodImplOptions.InternalCall,
MethodCodeType=MethodCodeType.Runtime), DispId(0x3e)]
public virtual extern void Versions(ref int Ocx, ref
int Driver, ref int ChipVersion);
I am looking for a way to fix my existing wrapper class
(the one I have written in code) so that it is able to
properly interface with the OCX in question. Unfortunately
using the IDE's automatic wrappers will not do the job for
me as I will later be using several other OCX's with
nearly identical interfaces and will need to be able to
build a simple C# interface for them all (a job that is
far easier than the current issue).
I am at a loss as to what is causing these issues and hope
someone here has an idea that might fix this problem. 2 2142
Brendan,
I don't quite understand what you really need here. COM interop will
provide you with all of the interface definitions that are implemented on
the type, and you should be able to get direct access to the ActiveX control
through the GetOcx method on the wrapper that is created for your control.
Once you have that, you should be able to cast it to any interface that the
control implements (including your own), and do what you wish with it.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Brendan" <an*******@discussions.microsoft.com> wrote in message
news:3e****************************@phx.gbl... I have a legacy COM/ActiveX component (an OCX) that I need to interface with from C# and the .NET framework.
Ordinarily, I would just add a reference to the OCX or add it to the Toolbox (both of which work in their own ways), but I need more control over the interfacing, and to that end I am trying to write my own wrapper class, based on what the IDE turns out, unfortunately all attempts have failed.
Here is what I know so far:
When added as an ActiveX component to the Toolbox, I can interface with it without problem, if I try to import it as a standard COM component by adding a reference in the Solution Explorer, I am able to create a new instance of the object, but immediately after I call any method of the component I get a COMException style unhandled exception with the telling additional information of simply "Catastrophic failure".
What strikes me as odd is that when adding the component to the toolbar, both an ActiveX wrapper, as well as the COM wrapper are built and this latter wrapper is identical to the wrapper built when I simply add a reference. Like the original, when I use it I get the 'catastrophic failure message', despite the fact that the ActiveX wrapper also uses the COM wrapper for it's interfacing to the OCX.
Needing more control over the actual interface of the wrapper, I started building my own from scratched based on the code generated by the earlier steps and the .NET Reflector. Unfortunately I am not even able to instantiate this class. Should I try to do so I receive a COMException, with the additional information of "COM object with CLSID {0ABFE4A5-75E8-4268-9FBF-30F092863F4A} is either not valid or not registered."
I have verified that the above CLSID (aka GUID) is that of the OCX I am trying to interface with and that it is properly installed and registered on the system.
The class name its self is defined as:
[ComImport, Guid("0ABFE4A5-75E8-4268-9FBF-30F092863F4A"), TypeLibType((short) 0x1010)] public class MyOCXTestClass
And it's methods all look very similar to the following:
[PreserveSig, MethodImpl (MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime), DispId(0x3e)] public virtual extern void Versions(ref int Ocx, ref int Driver, ref int ChipVersion);
I am looking for a way to fix my existing wrapper class (the one I have written in code) so that it is able to properly interface with the OCX in question. Unfortunately using the IDE's automatic wrappers will not do the job for me as I will later be using several other OCX's with nearly identical interfaces and will need to be able to build a simple C# interface for them all (a job that is far easier than the current issue).
I am at a loss as to what is causing these issues and hope someone here has an idea that might fix this problem.
Thanks for the prompt reply Nicholas, unfortunately
typecasting will work in a very limited sense because the
common interfaces required are not defined within the COM
components themselves, let me try to explain this better.
We'll call my current component Foo. Later, I will need to
access a second component called Bar. Both Foo and Bar
have very similar interfaces, ideally they would have
inherited from the same interface to begin with, but
because of their history that is not possible.
What I want to be able to do is write a custom COM wrapper
for each, and have both wrappers inherit from the same
interface so that I can create an instance of Foo or Bar,
and not care which it is. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Patrick |
last post by:
I am almost certain that I could use HTTP Post/Get to submit XML Web Service
call (over SSL as well, if using Version 3 of MSXML2) from an ASP
Application?
However, would I only be able to call...
|
by: Chango V. |
last post by:
Hello,
We seem to need a PIA for MSXML 4. According to the documentation, only the
original publisher of a COM type library is supposed to create a .NET PIA.
As far as I know, Microsoft hasn't...
|
by: Bob N5 |
last post by:
I am working on an application that uses interop to do some simple operations
with both Excel and Word. I have most of functionality working, but ran into
issues on making things work with both...
|
by: Greg Bacon |
last post by:
I have two C# projects: a production project and NUnit tests for it.
I've recently added a test that causes a call into a registered COM
component, and now the test fails with a TypeLoadException...
|
by: tcarvin |
last post by:
If you are not in the mood for a rant, then leave now...
I figure most VB.NET programmers have a VB6 background, so I hope you all
don't mind the semi-VB.NET related Interop posting.
Like most...
|
by: SiJP |
last post by:
I've been having a few issues recently in creating a vb.net class
library (using vs.net 2003), registering it for com interop and then
invoking its functions from an object in VB6.
The error I...
|
by: Brent |
last post by:
I'm trying to open and manipulate an Excel spreadsheet from C#. To that
end, I've referenced Interop.EXCEL9.dll, which I have on my machine. All
of the examples I've read say to do something like...
|
by: Peter Ritchie [C# MVP] |
last post by:
I've purposely been ignoring a CA2122 warning in some C++ interop code I've
been working on for quite some time. I've just recently had the cycles to
investigate the warning. The warning message...
|
by: muriwai |
last post by:
Hi,
I have a C# assembly project under Visual Stuio 2008 Pro on Windows Server
2008. I converted the project from VS 2005.
The project references COM->Microsoft CDO for Windows 2000 Library...
|
by: Bhrionn |
last post by:
Hello World,
I am working on implementing a build for my companies application. The scenario implemeted is producing the error:
‘Class does not support automation or does not support expected...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
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$) {
}
...
|
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...
|
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...
|
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
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |