HighTechTalks DotNet Forums  

using VB6 Collections in c#

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss using VB6 Collections in c# in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
asanford
 
Posts: n/a

Default using VB6 Collections in c# - 11-10-2005 , 05:34 PM






I have a VB6-based COM object that I want to utilize in c# (VS2003.) I add a
reference to the COM object (which creates an interop wrapper). I then
create an instance of the wrapper class. The problem I'm having is a method
of that class returns a VB6 Collection object. By default, the generated
interop class maps this to a 'object' return type. I tried casting this
object to a VBA.CollectionClass (I got this type by adding a COM reference to
MSVBVB60.dll), which seems to work (I can call Collection.Count()), but when
I call Collection.Add(ob,key,before,after), I get a COM exception:

System.Runtime.InteropServices.COMException: Exception from HRESULT:
0x800A0005 (CTL_E_ILLEGALFUNCTIONCALL).

Any idea how to get this to work? I really only want the two-parameter
version of Add(), but I don't seem to be able to use this from c#. Here's
how I'm calling:

collection.Add(ref oItem,ref oKey,ref oBefore, ref oAfter);

Any ideas? I got the idea of casting it to the VBA.CollectionClass from this
article:

http://support.microsoft.com/?kbid=323737

Thanks!

Reply With Quote
  #2  
Old   
AT
 
Posts: n/a

Default RE: using VB6 Collections in c# - 11-11-2005 , 01:34 AM






Hi

We do not need to add reference to the vbruntime, when you add reference to
the CollectionFactory.dll, the IDE will automatically reference the VBA.
Here is the code goes which ran OK based on my test.
[STAThread]
static void Main(string[] args)
{
CollectionFactory.clsVBACollectionClass objVBACollection = new
CollectionFactory.clsVBACollectionClass();
VBA.Collection col = objVBACollection.CreateVBACollection();
object m = System.Reflection.Missing.Value;
object name ="Microsoft";
col.Add(ref name,ref m,ref m,ref m);
object i = 1;
Console.Write(col.Item(ref i));
}

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Reply With Quote
  #3  
Old   
asanford
 
Posts: n/a

Default RE: using VB6 Collections in c# - 11-11-2005 , 09:49 AM



your code snippet solved my problem: using System.Reflection.Missing.Value
for the optional fields fixed the exception! works like a charm now.

thanks a bunch!

""Peter Huang" [MSFT]" wrote:

Quote:
Hi

We do not need to add reference to the vbruntime, when you add reference to
the CollectionFactory.dll, the IDE will automatically reference the VBA.
Here is the code goes which ran OK based on my test.
[STAThread]
static void Main(string[] args)
{
CollectionFactory.clsVBACollectionClass objVBACollection = new
CollectionFactory.clsVBACollectionClass();
VBA.Collection col = objVBACollection.CreateVBACollection();
object m = System.Reflection.Missing.Value;
object name ="Microsoft";
col.Add(ref name,ref m,ref m,ref m);
object i = 1;
Console.Write(col.Item(ref i));
}

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.



Reply With Quote
  #4  
Old   
AT
 
Posts: n/a

Default RE: using VB6 Collections in c# - 11-11-2005 , 09:46 PM



Hi

I am glad my suggestion helps you!
Cheers!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.