Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / November 2005

Tip: Looking for answers? Try searching our database.

using VB6 Collections in c#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
asanford - 10 Nov 2005 22:34 GMT
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!
"Peter Huang" [MSFT] - 11 Nov 2005 06:34 GMT
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

Signature

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

asanford - 11 Nov 2005 14:49 GMT
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!

> Hi
>
[quoted text clipped - 21 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" [MSFT] - 12 Nov 2005 02:46 GMT
Hi

I am glad my suggestion helps you!
Cheers! :)

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.