473,398 Members | 2,812 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,398 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 1351
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...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.