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

C# calling .dll and returning VBA.CollectionClass

Hello all and Happy New Year,

I've been having this problem for some time and thought I'd try to see
if anyone else out there has had the same problem or can give a little
help.

I'm using a website written in C# to call a .dll which in turn returns
a load of information. Most of this information is readable. However,
some of the information returned is of type VBA.CollectionClass.

I've found from Microsoft that .NET cannot understand these types of
collections and only VB6 can read them.

If the collection is a simple collection then I can get the information
out by casting. However, if the information isn't basic then the
information returned isn't readable.

Has anyone encountered this problem? I'm sure someone out there must
be calling dll's which return VBA.CollectionClasses...

Does anyone know whether the next version of .Net will be able to cope
with this?

Any help would be very much appreciated.

Ieuan Roberts

Nov 16 '05 #1
6 5485
Ieuan,

.NET can use the CollectionClass from VBA. You just have to set a
reference to MSVBVM60.dll (I believe that is it, it is in your system32
directory), and then look for it in the VBA namespace. You will find it
under the COM tab (you use it through COM interop) in the references dialog.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Ieuan" <ie*************@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hello all and Happy New Year,

I've been having this problem for some time and thought I'd try to see
if anyone else out there has had the same problem or can give a little
help.

I'm using a website written in C# to call a .dll which in turn returns
a load of information. Most of this information is readable. However,
some of the information returned is of type VBA.CollectionClass.

I've found from Microsoft that .NET cannot understand these types of
collections and only VB6 can read them.

If the collection is a simple collection then I can get the information
out by casting. However, if the information isn't basic then the
information returned isn't readable.

Has anyone encountered this problem? I'm sure someone out there must
be calling dll's which return VBA.CollectionClasses...

Does anyone know whether the next version of .Net will be able to cope
with this?

Any help would be very much appreciated.

Ieuan Roberts

Nov 16 '05 #2
Nicholas,

Thanks for the reply.

I've put in a reference to the dll you mentioned - this brings in a few
things into the references area including the VBA one you mention.

I then try to cast a VBA.CollectionClass passed back from my dll into a
VBA.Collection. This works correctly but only so far as it shows the
converted object I'm trying to look at as an object of type
VBA.CollectionClass and I can't get any further into the object. I'm
looking at this through the locals window.

If the object is a simple one dimensional array then I can manage a
foreach object in VBACollection and put the object into an arraylist.

However, I don't know what type most objects are - they could be an
array, an array of an array etc...
Any other suggestions would be most welcommed.

Ieuan

Nov 16 '05 #3
Ieuan,

The reason for this is that you need to cast it to the interface that
exposes the functionality. VB6 mucked around with COM, exposing interfaces
and trying to pass them off as classes. It's the kind of thing that causes
this mess in the first place.

Look for an interface named _Collection in the VBA namespace, and cast
to an instance of that. You should be able to access all the functionality
that you need once your CollectionClass is cast to that.

CollectionClass is a managed wrapper created by when you add the
reference which you can use to create the class instance (since you can't
create an interface).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ieuan" <ie*************@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Nicholas,

Thanks for the reply.

I've put in a reference to the dll you mentioned - this brings in a few
things into the references area including the VBA one you mention.

I then try to cast a VBA.CollectionClass passed back from my dll into a
VBA.Collection. This works correctly but only so far as it shows the
converted object I'm trying to look at as an object of type
VBA.CollectionClass and I can't get any further into the object. I'm
looking at this through the locals window.

If the object is a simple one dimensional array then I can manage a
foreach object in VBACollection and put the object into an arraylist.

However, I don't know what type most objects are - they could be an
array, an array of an array etc...
Any other suggestions would be most welcommed.

Ieuan

Nov 16 '05 #4
Ieuan,

In addition to Nicholas, did you try to set a reference to
Microsoft.VisualBasic and than use the collection in that. This would in my
opinion be compatible with the VBA collection. The Microsoft.VisualBasic
namespace is a full part of the Framework.

I never tried it, just an idea.

Cor
Nov 16 '05 #5
Nicholas,

Thanks for your reply again.

I tried what you suggested and had no luck.

My code looks similar to this - where ciObj is the whole thing being
returned from the dll and Fields_Names being the VBA.Collection I'm
interested in:
VBA.Collection col1 = (VBA.Collection) ciObj.Fields_Names;
VBA._Collection col2 = (VBA._Collection) ciObj.Fields_Names;
VBA.CollectionClass col3 = (VBA.CollectionClass) ciObj.Fields_Names;

Under all 3 of these castings, looking through the locals window, the
values for col1, col2 and col3 are displayed with a value of
{VBA.CollectionClass} and you can't dig down into the actual dataa held
within that class.

Any further suggestions would be most welcommed.

Ieuan

P.S.
I mentionned in my earlier mail that providing the collection held a
basic array I could read it. I do this by:
ArrayList arTemp = new ArrayList();
foreach (object obj in VBA.Collection)
{
arTemp.Add(obj.ToString());
}

This works for array's as the object comes through as a string.

However, on a more complex collection, the object comes through a
{System.__ComObject} and I can do nothing with this.

Nov 16 '05 #6
Nicholas,

Thanks for your reply again.

I tried what you suggested and had no luck.

My code looks similar to this - where ciObj is the whole thing being
returned from the dll and Fields_Names being the VBA.Collection I'm
interested in:
VBA.Collection col1 = (VBA.Collection) ciObj.Fields_Names;
VBA._Collection col2 = (VBA._Collection) ciObj.Fields_Names;
VBA.CollectionClass col3 = (VBA.CollectionClass) ciObj.Fields_Names;

Under all 3 of these castings, looking through the locals window, the
values for col1, col2 and col3 are displayed with a value of
{VBA.CollectionClass} and you can't dig down into the actual dataa held
within that class.

Any further suggestions would be most welcommed.

Ieuan

P.S.
I mentionned in my earlier mail that providing the collection held a
basic array I could read it. I do this by:
ArrayList arTemp = new ArrayList();
foreach (object obj in VBA.Collection)
{
arTemp.Add(obj.ToString());
}

This works for array's as the object comes through as a string.

However, on a more complex collection, the object comes through a
{System.__ComObject} and I can do nothing with this.

Nov 16 '05 #7

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

Similar topics

5
by: Andrew Slade | last post by:
Hello, I am making calls from one compilation unit to functions in another by pointers and I get the warnings below from gcc on 2.4.x Debian Linux. The executable seems to work fine but the...
8
by: elizabeth | last post by:
New to .NET and writing a C# ASP.Net application that needs to access a COM+ VB dll (which I was not involved in writing). The COM+ VB dll returns a VB Collection. I use VBA.CollectionClass to...
7
by: JJ | last post by:
Hi, I call a class in my windows service app and in that class I access a method that returns an OleDbReader. Now It does have records in the reader when I step through the method but when I...
4
by: Bernie Yaeger | last post by:
I'd like to run an external exe before returning to the calling app. For example: System.Diagnostics.Process.Start("f:\imcapps\xbuild\xbuild.exe") When I call this, the code beneath immediately...
3
by: Mike | last post by:
Timeout Calling Web Service I am calling a .NET 1.1 web service from an aspx page. The web service can take several minutes to complete its tasks before returning a message to the aspx page. ...
2
by: Geler | last post by:
A theoretical question: Sorry if its a beginner question. Here is a quote from the MSDN explaning the C/C++ calling convention.. It demonstrates that the calling function is responsible to clean...
3
by: Opa | last post by:
Hi , I have a form with javasript which launches a popup via the showModalDialog() method. I get the dialog to open, now I am trying to first get a reference to the calling form from the popup...
0
by: saheli | last post by:
In my C# project i call a VB 6.0 .dll which in turn returns a load of information. Most of this information is readable. However, some of the information returned is of type VBA.CollectionClass. ...
13
by: Steve | last post by:
On page 392 of "Javascript the definitive guide" a function is called like this:- <form action="processform.cgi" onsubmit="return validateForm();"> Why, in this instance, is the return...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.