C# IEnumerator & COM interop w/ WSH 
Author Message
 C# IEnumerator & COM interop w/ WSH

I have a C# class that I am attempting to use from some VBScript.  I made
the class COM visible, etc...  All methods appear to work fine in my VBS
client except one.  That one is the GetEnumerator method.

According to the typelib generated from the assembly the function returns an
IEnumVARIANT*
        IEnumVARIANT* GetEnumerator();

However when the following code executes I get an "object required" message
for the call to Reset.

 ' g_oCovList is the C# object being exported
 Set oFileList = g_oCovList.GetEnumerator

 ' This prints "Object" so it appears like it is an object
 WScript.Echo TypeName( oFileList  )

' This prints an error message of "Object required"
 oFileList.Reset

Does anyone have any ideas?  I'm not very familiar with using IEnumVARIANT
from VBScript so perhaps that usage is wrong.  Or perhaps it is the C#
export stuff.

With a C# client using the C# class natively it works fine.



Sun, 26 Sep 2004 08:35:44 GMT  
 C# IEnumerator & COM interop w/ WSH
Nathan,

Quote:
>Does anyone have any ideas?  I'm not very familiar with using IEnumVARIANT
>from VBScript so perhaps that usage is wrong.  Or perhaps it is the C#
>export stuff.

I don't think you can call Reset and the other methods of IEnumVARIANT
directly from a scripting language. What you probably want to do is
use a For Each loop to iterate the list you get back:

For Each item In g_oCovList
  ...

Mattias

===
Mattias Sj?gren (VB MVP)

http://www.msjogren.net/dotnet/



Sun, 26 Sep 2004 09:22:24 GMT  
 C# IEnumerator & COM interop w/ WSH
That did the trick.  Thanks


Quote:
> Nathan,

> >Does anyone have any ideas?  I'm not very familiar with using
IEnumVARIANT
> >from VBScript so perhaps that usage is wrong.  Or perhaps it is the C#
> >export stuff.

> I don't think you can call Reset and the other methods of IEnumVARIANT
> directly from a scripting language. What you probably want to do is
> use a For Each loop to iterate the list you get back:

> For Each item In g_oCovList
>   ...

> Mattias

> ===
> Mattias Sj?gren (VB MVP)

> http://www.msjogren.net/dotnet/



Mon, 27 Sep 2004 05:20:04 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Experimental Technique: automating COM class creation with C# and VB.NET command line compilers

2. Experimental Technique: automating COM class creation with C# and VB.NET command line compilers

3. WSH C# performance ?

4. How do I create a COM wrapper for C# or Jscript.NET, so I can use it in WSH?

5. jscript & COM

6. VBScript, COM Events & Safe Arrays

7. Jscript & COM

8. Strings, VBScript & COM Objects

9. Error Handling using VBScript & COM

10. Strings, VBScript & COM Objects

11. Mac&StyleScript&EPS&ClarisWorks&Ill7

 

 
Powered by phpBB® Forum Software