COM reference problems
COM reference problems
COM reference problems
COM reference problems
COM reference problems
COM reference problems COM reference problems COM reference problems COM reference problems COM reference problems COM reference problems COM reference problems COM reference problems
COM reference problems COM reference problems
COM reference problems
Go Back  Xtreme Visual Basic Talk > > > COM reference problems


Reply
 
Thread Tools Display Modes
  #1  
Old 04-20-2010, 08:44 AM
agentzee agentzee is offline
Newcomer
 
Join Date: Apr 2010
Location: Budapest
Posts: 8
Unhappy COM reference problems


Hi,

I m using VB 2008 express. I have added OPC.Automation as COM reference in the project properties. When i debug/watch in instance I found that the object structure is strange: an OPC.AutomationClass is on the first level and most of the properties return errors.

This reference works flawlessly in excel vba.

Moreover, I have investigated further com references and they show the same strange behavior.

Thanks for your help

Zee
Reply With Quote
  #2  
Old 04-22-2010, 07:28 AM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

Hi Zee,

Welcome to the forum.

I'm not familiar with 'OPC', unfortunately. What is this exactly?

I can only suggest one of two directions to possibly solve this:

(1) Show your code. Perhaps we can find something wrong in your code, if you show it. As for the 'OPC.AutomationClass', you should probably avoid this and utilze whatever is the class name that you use in VBA (even though it will probably show up as an interface when accessed from .NET.)

(2) If you show your code and we still can't help you, then you'll probably have to contact the manufacturer for help.

But show your code first, and we'll see what we can see...

- Mike
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
  #3  
Old 04-23-2010, 03:26 AM
agentzee agentzee is offline
Newcomer
 
Join Date: Apr 2010
Location: Budapest
Posts: 8
Default

Hi Mike,

Thanks for your help.

Unfortunately I can not show you the code as it contains some corprorate data that is not allowed to be published.

However I try to describe my problem. I guess I miss something important as this issue appears at almost every referenced component. I experienced it with the above component as well as ie. excel automation.

In the excel vb editor when I add reference and create a new instance, in the watch window I see the structure and I can access and use the instance as normal.

In the case of visual basic 2008 express i do the following:
- Add a COM reference to the project
- use the dim com001 as new ref to create new instance
Now when i open a watch window and see the content of the com001 instance, there is only one child, named after the ref with a 'class' suffix'. In excel vb I saw the top structure of the component. Under this strange refClass I can see the normal top structure.

The namespace resolution works fine, but I cannot access to a major part of the elements.

Thanks for your help
Attached Images
File Type: png vb_issue001.PNG (15.2 KB, 6 views)
Reply With Quote
  #4  
Old 04-23-2010, 06:42 AM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

Ok, well, again I am not familiar with this 'OPC.Automation' that you are using or this 'UniSimDesign' library.

I can say, though, that the "Class" suffix is actually normal. If you do Excel Automation, you can create a new Excel instance using something like this using VB.NET:

Code:
Dim excelApp As New Excel.Application
If you then pause the debugger and examine object referenced by the 'excelApp' variable, you will see that the object held is actually an 'Excel.ApplicationClass'. (See the screen shot, attached.)

The way this works is that COM works via interfaces, but .NET works via classes. The 'Excel.Application' that we are used to working with is a COM interface, not technically an object. Naming rules prevent the interface and the underlying class that implements it from having the same name. Therefore, the name "Class" is appended to the name of the class.

The last part of the mystery, is how does the expression Dim excelApp As New Excel.Application even work if Excel.Application is an interface. (One cannot make a new interface instance like this -- you normally have to tell the compiler which object that implements the interface to create.) This is done by having .NET respect the COM rules that dictate which class uses that interface as their default member. So, in this case, calling Dim excelApp As New Excel.Application actually creates a new Excel.ApplicationClass object, which implements the Excel.Application interface.

Overall, you can, and should, simply reference the interface members and use them as if they were, in fact, a class. That is, you should create variables typed As Excel.Application and not worry about the fact that the underlying type is actually Excel.ApplicationClass. You should not be referencing and creating Excel.ApplicationClass objects directly.

For more on this, see:

(1) Don't use ApplicationClass (Peter Torr)

(2) Excel interop: _Worksheet or Worksheet? (John Skeet)

So, I can't speak directly to the COM libraries that you are working with, but, best I can tell, it seems to be the same process that is going on.

Make sense?
Mike
Attached Images
File Type: png Excel.ApplicationClass Screen Shot.png (10.1 KB, 5 views)
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb

Last edited by Mike Rosenblum; 04-23-2010 at 06:53 AM.
Reply With Quote
  #5  
Old 04-26-2010, 10:17 AM
agentzee agentzee is offline
Newcomer
 
Join Date: Apr 2010
Location: Budapest
Posts: 8
Unhappy

Thanks for your help

Unfortunately it s too difficult for me so I gave it up.

Hope that new release will not be so buggy as the current one.

Cheers
Z
Reply With Quote
  #6  
Old 04-26-2010, 01:41 PM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

Have you tried contacting the manufacturer? Who makes this 'OPC' library?
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
  #7  
Old 04-27-2010, 07:49 AM
agentzee agentzee is offline
Newcomer
 
Join Date: Apr 2010
Location: Budapest
Posts: 8
Cool

Hi,

now I am trying it with VB 2010. The watch window is still messy, but the class is working fine.
Looks like this problem is solved in the new version.

Cheers
Z
Reply With Quote
  #8  
Old 04-27-2010, 08:29 AM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

Ah, great to hear!

Does make one wonder though... But if it ain't broke, don't question it.
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
Reply

Tags
com reference, visual basic 2008


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
COM reference problems
COM reference problems
COM reference problems COM reference problems
COM reference problems
COM reference problems
COM reference problems COM reference problems COM reference problems COM reference problems COM reference problems COM reference problems COM reference problems
COM reference problems
COM reference problems
 
COM reference problems
COM reference problems
 
-->