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

2 VC# COM problems

Uty
As the subject suggests, I have two questions about using COM objects in C#. I'm using two different objects, each of which is giving me a problem.

The first object ... we'll call it AppXControl. Here's some Visual Basic 6 code I've written which gets the code connected to the COM object.

Private WithEvents xControl As AppXControl.Control
Private xConnector As New AppXControl.Connector

** This line of code is in FormMain_Load()
Set xControl = xConnector.xMonitor

Basically, you instantiate two classes defined in the COM object. The first is a controller -- this is the actual object that catches triggered events and so on. The second is a connector. You instantiate it, and use xConnector.xMonitor to get an xControl object for use in doing COM with ApplicationX.

Here's the corresponding C# code:

public class Form1 : System.Windows.Forms.Form
{
private AppXControl.ControlClass xControl;
private AppXControl.ConnectorClass xConnector = new AppXControl.ConnectorClass();

....

public Form1()
{
InitializeComponent();
xControl = xConnector.xMonitor;
}

....
}

Here's the problem. In the Form1 Constructor, xConnector.xMonitor is returning an object of type AppXControl ... but what I really need here is an object of type AppXControlClass. The COM object itself has no knowledge of this AppXControlClass, it is created by C# when the object is ported to the .NET framework with tlbimp. Is there any way I can get the AppXControl object instead of AppXControlClass without asking the COM object's vendor to rewrite their code? (Which I doubt they'd do anyway.)

Now on to question 2. Basically, I have another COM object that I'm trying to work with, but when I run my application, I get an exception to the effect of "COM object with CLSID {X} not found" ... all the info that needs to be in the registry about that object is there, because my Visual Basic 6 code written for that same object works just fine. Here's what I do:

1. Get .NET interface to COM object with tlbimp.
2. Add COM reference to project.
3. Write some cool code.
4. Compile.
5. Put executable and .NET COM object wrapper on test machine.
6. Run regasm.
7. Run code.
8. Get exception, bang head against wall.

I think it's odd that this procedure works just fine for one COM object but apparently isn't good enough for another COM object. Am I missing something here? (Regsvr32.exe will not work on the COM object.

One last thing I want to point out -- both of these COM objects were written by different companies, so I can not modify them on whim

Thanks!
Nov 16 '05 #1
1 1342
Uty,

I'm not quite sure about your first question. From what I can tell, you
should just cast the return type to the Class type that you want. However,
I would recommend using the interface instead. When you create a COM
component in VB, you have a class implementation, but all of it's details
are private. In reality, VB exposes an interface that is associated with
the class type. When you pass back an instance of your type, you really are
passing an interface, a detail that VB hides for you. This is why you have
a number of interfaces with an underscore in front of them, these are the
interfaces that are actually generated.

As for your second question, you are not registering the original COM
component. You do not need to use regasm on the .NET COM wrapper. Rather,
you need to call regsvc32 (or the executable itself, if it is out of
process) to register the component. The wrapper needs no registering.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Uty" <an*******@discussions.microsoft.com> wrote in message
news:24**********************************@microsof t.com...
As the subject suggests, I have two questions about using COM objects in C#. I'm using two different objects, each of which is giving me a problem.
The first object ... we'll call it AppXControl. Here's some Visual Basic 6 code I've written which gets the code connected to the COM object.

Private WithEvents xControl As AppXControl.Control
Private xConnector As New AppXControl.Connector

** This line of code is in FormMain_Load()
Set xControl = xConnector.xMonitor

Basically, you instantiate two classes defined in the COM object. The first is a controller -- this is the actual object that catches triggered
events and so on. The second is a connector. You instantiate it, and use
xConnector.xMonitor to get an xControl object for use in doing COM with
ApplicationX.
Here's the corresponding C# code:

public class Form1 : System.Windows.Forms.Form
{
private AppXControl.ControlClass xControl;
private AppXControl.ConnectorClass xConnector = new AppXControl.ConnectorClass();
...

public Form1()
{
InitializeComponent();
xControl = xConnector.xMonitor;
}

...
}
Here's the problem. In the Form1 Constructor, xConnector.xMonitor is returning an object of type AppXControl ... but what I really need here is
an object of type AppXControlClass. The COM object itself has no knowledge
of this AppXControlClass, it is created by C# when the object is ported to
the .NET framework with tlbimp. Is there any way I can get the AppXControl
object instead of AppXControlClass without asking the COM object's vendor to
rewrite their code? (Which I doubt they'd do anyway.)

Now on to question 2. Basically, I have another COM object that I'm trying to work with, but when I run my application, I get an exception to the
effect of "COM object with CLSID {X} not found" ... all the info that needs
to be in the registry about that object is there, because my Visual Basic 6
code written for that same object works just fine. Here's what I do:
1. Get .NET interface to COM object with tlbimp.
2. Add COM reference to project.
3. Write some cool code.
4. Compile.
5. Put executable and .NET COM object wrapper on test machine.
6. Run regasm.
7. Run code.
8. Get exception, bang head against wall.

I think it's odd that this procedure works just fine for one COM object but apparently isn't good enough for another COM object. Am I missing
something here? (Regsvr32.exe will not work on the COM object.)
One last thing I want to point out -- both of these COM objects were written by different companies, so I can not modify them on whim.
Thanks!

Nov 16 '05 #2

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

Similar topics

14
by: Jim Hubbard | last post by:
Are you up to speed on the difficulties in using the 1.1 .Net framework? Not if you are unaware of the 1,596 issues listed at KBAlertz (http://www.kbalertz.com/technology_3.aspx). If you are...
1
by: 3f | last post by:
Hello; We have made a web application that people can download from our web site and installed on: Windows XP Windows 2000 Professional Windows 2003 Server Windows 2000 Server
5
by: Corky | last post by:
This works: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS INNER JOIN PROBLEMS ON PROBLEM_OBJECTS.PROBLEM_ID = PROBLEMS.PROBLEM_ID WHERE INTEGER(DAYS(CURRENT DATE) -...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
0
by: Sergistm | last post by:
Hello World, :D I have a problem that it is making me crazy, I hope you can help me. I'm trying to execute a .exe file with the Procces.Start, and there is no problem when the file is on my...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.