OT: Wiring a DLL to return a collection to WSH 
Author Message
 OT: Wiring a DLL to return a collection to WSH

Sorry about posting here, but it's a crossover topic anyway and I didn't get
much of a response in the COM group on this (probably because this question
sounded confused).

Say I have an ActiveX DLL which exposes a simple collection Foo to the outside
world.

What are the mechanics of exposing this within VB? To make it really simply,
let's say that the "collection" is just the integers from 1 to 10.

I tried this:

Public Function Foo() As Collection
  For y = 1 To 10
  Foo.Add y
  Next
End Function

...which compiled fine, but I get error 91 ("Object variable or With block
variable not set") on line 2 whenever I try to call it with a script like this:

1. set o = CreateObject("Project1.Class1")
2. set a = o.Foo

What the heck am I doing wrong?



Mon, 27 Sep 2004 19:48:01 GMT  
 OT: Wiring a DLL to return a collection to WSH


Fri, 19 Jun 1992 00:00:00 GMT  
 OT: Wiring a DLL to return a collection to WSH
Alex,

You need to create a new instance of a collection object and indirectly
refer it to function.

Public Function Foo() As Collection
Dim x             As Integer
Dim colFoo    As New Collection
For x = 1 To 10
      colFoo.Add x
Next
Set Foo = colFoo
End Function
==========================================
set o = CreateObject("Project1.Class1")
For each x in o.Foo
    Wscript.Echo x
Next

Regards,
--
Gurgen Alaverdian
http://www.gurgensvbstuff.com


Quote:
> Sorry about posting here, but it's a crossover topic anyway and I didn't
get
> much of a response in the COM group on this (probably because this
question
> sounded confused).

> Say I have an ActiveX DLL which exposes a simple collection Foo to the
outside
> world.

> What are the mechanics of exposing this within VB? To make it really
simply,
> let's say that the "collection" is just the integers from 1 to 10.

> I tried this:

> Public Function Foo() As Collection
>   For y = 1 To 10
>   Foo.Add y
>   Next
> End Function

> ...which compiled fine, but I get error 91 ("Object variable or With block
> variable not set") on line 2 whenever I try to call it with a script like
this:

> 1. set o = CreateObject("Project1.Class1")
> 2. set a = o.Foo

> What the heck am I doing wrong?



Mon, 27 Sep 2004 22:24:29 GMT  
 OT: Wiring a DLL to return a collection to WSH
Alex,

You need to create a new instance of a collection object and indirectly
refer it to function.

Public Function Foo() As Collection
Dim x             As Integer
Dim colFoo    As New Collection
For x = 1 To 10
      colFoo.Add x
Next
Set Foo = colFoo
End Function
==========================================
set o = CreateObject("Project1.Class1")
For each x in o.Foo
    Wscript.Echo x
Next

Regards,
--
Gurgen Alaverdian
http://www.gurgensvbstuff.com


Quote:
> Sorry about posting here, but it's a crossover topic anyway and I didn't
get
> much of a response in the COM group on this (probably because this
question
> sounded confused).

> Say I have an ActiveX DLL which exposes a simple collection Foo to the
outside
> world.

> What are the mechanics of exposing this within VB? To make it really
simply,
> let's say that the "collection" is just the integers from 1 to 10.

> I tried this:

> Public Function Foo() As Collection
>   For y = 1 To 10
>   Foo.Add y
>   Next
> End Function

> ...which compiled fine, but I get error 91 ("Object variable or With block
> variable not set") on line 2 whenever I try to call it with a script like
this:

> 1. set o = CreateObject("Project1.Class1")
> 2. set a = o.Foo

> What the heck am I doing wrong?



Mon, 27 Sep 2004 22:26:41 GMT  
 OT: Wiring a DLL to return a collection to WSH
This works for me...

Public Function Foo() As Collection
    Dim col As New Collection
    Dim y As Integer

    For y = 1 To 10
        col.Add y
    Next

    Set Foo = col

    Set col = Nothing

End Function

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--


Quote:
> Sorry about posting here, but it's a crossover topic anyway and I didn't get
> much of a response in the COM group on this (probably because this question
> sounded confused).

> Say I have an ActiveX DLL which exposes a simple collection Foo to the outside
> world.

> What are the mechanics of exposing this within VB? To make it really simply,
> let's say that the "collection" is just the integers from 1 to 10.

> I tried this:

> Public Function Foo() As Collection
>   For y = 1 To 10
>   Foo.Add y
>   Next
> End Function

> ...which compiled fine, but I get error 91 ("Object variable or With block
> variable not set") on line 2 whenever I try to call it with a script like this:

> 1. set o = CreateObject("Project1.Class1")
> 2. set a = o.Foo

> What the heck am I doing wrong?



Mon, 27 Sep 2004 22:50:42 GMT  
 OT: Wiring a DLL to return a collection to WSH
Ugghh -

Thank you, Gurgen.  I just ran across a discussion in Google's archives which
had me nibbling around that idea and you made it completely clear!

Actually, now I'm glad I struggled with it a bit before asking in here - I would
never have understood it if someone had laid it out for me early on...

I modified it slightly as a test of whether I was catching on:

Public Function Foo() As Collection
Dim x             As Integer
Dim colFoo    As New Collection
For x = 1 To 10
      colFoo.Add MyFunc(x)
Next
Set Foo = colFoo
End Function

Public Function MyFunc(ByVal var As Long) As Long
 MyFunc = var ^ 2
End Function

This leaves me with a question about collections of classes which I will quite
happily put off for another day - I don't understand my *question* about that
even yet, which bodes ill for me understanding an answer.


Quote:
> Alex,

> You need to create a new instance of a collection object and indirectly
> refer it to function.

> Public Function Foo() As Collection
> Dim x             As Integer
> Dim colFoo    As New Collection
> For x = 1 To 10
>       colFoo.Add x
> Next
> Set Foo = colFoo
> End Function
> ==========================================
> set o = CreateObject("Project1.Class1")
> For each x in o.Foo
>     Wscript.Echo x
> Next

> Regards,
> --
> Gurgen Alaverdian
> http://www.gurgensvbstuff.com


> > Sorry about posting here, but it's a crossover topic anyway and I didn't
> get
> > much of a response in the COM group on this (probably because this
> question
> > sounded confused).

> > Say I have an ActiveX DLL which exposes a simple collection Foo to the
> outside
> > world.

> > What are the mechanics of exposing this within VB? To make it really
> simply,
> > let's say that the "collection" is just the integers from 1 to 10.

> > I tried this:

> > Public Function Foo() As Collection
> >   For y = 1 To 10
> >   Foo.Add y
> >   Next
> > End Function

> > ...which compiled fine, but I get error 91 ("Object variable or With block
> > variable not set") on line 2 whenever I try to call it with a script like
> this:

> > 1. set o = CreateObject("Project1.Class1")
> > 2. set a = o.Foo

> > What the heck am I doing wrong?



Mon, 27 Sep 2004 22:57:05 GMT  
 OT: Wiring a DLL to return a collection to WSH
One more problem...
I'm getting persistent errors with using AddressOf - which I _think_ I figured
out by reading the docs (go figure, huh?)

You can't use AddressOf in a class module; fine, I can put in a BAS.  But I see
this in the VB5 docs:

"DLL and type library functions can't be modified with AddressOf."

Is this mis-stated, or is it impossible for me to use AddressOf contained in a
non-class module in an ActiveX DLL?

And am I pushing the limit on Off-Topic, or what?



This works for me...

Public Function Foo() As Collection
    Dim col As New Collection
    Dim y As Integer

    For y = 1 To 10
        col.Add y
    Next

    Set Foo = col

    Set col = Nothing

End Function

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Quote:
> Sorry about posting here, but it's a crossover topic anyway and I didn't get
> much of a response in the COM group on this (probably because this question
> sounded confused).

> Say I have an ActiveX DLL which exposes a simple collection Foo to the outside
> world.

> What are the mechanics of exposing this within VB? To make it really simply,
> let's say that the "collection" is just the integers from 1 to 10.

> I tried this:

> Public Function Foo() As Collection
>   For y = 1 To 10
>   Foo.Add y
>   Next
> End Function

> ...which compiled fine, but I get error 91 ("Object variable or With block
> variable not set") on line 2 whenever I try to call it with a script like
this:

> 1. set o = CreateObject("Project1.Class1")
> 2. set a = o.Foo

> What the heck am I doing wrong?



Mon, 27 Sep 2004 23:13:01 GMT  
 OT: Wiring a DLL to return a collection to WSH
What's your usage context for AddressOf?  

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--


Quote:
> One more problem...
> I'm getting persistent errors with using AddressOf - which I _think_ I figured
> out by reading the docs (go figure, huh?)

> You can't use AddressOf in a class module; fine, I can put in a BAS.  But I see
> this in the VB5 docs:

> "DLL and type library functions can't be modified with AddressOf."

> Is this mis-stated, or is it impossible for me to use AddressOf contained in a
> non-class module in an ActiveX DLL?

> And am I pushing the limit on Off-Topic, or what?



> This works for me...

> Public Function Foo() As Collection
>     Dim col As New Collection
>     Dim y As Integer

>     For y = 1 To 10
>         col.Add y
>     Next

>     Set Foo = col

>     Set col = Nothing

> End Function

> --
> Michael Harris
> Microsoft.MVP.Scripting
> Seattle WA US
> --



> > Sorry about posting here, but it's a crossover topic anyway and I didn't get
> > much of a response in the COM group on this (probably because this question
> > sounded confused).

> > Say I have an ActiveX DLL which exposes a simple collection Foo to the outside
> > world.

> > What are the mechanics of exposing this within VB? To make it really simply,
> > let's say that the "collection" is just the integers from 1 to 10.

> > I tried this:

> > Public Function Foo() As Collection
> >   For y = 1 To 10
> >   Foo.Add y
> >   Next
> > End Function

> > ...which compiled fine, but I get error 91 ("Object variable or With block
> > variable not set") on line 2 whenever I try to call it with a script like
> this:

> > 1. set o = CreateObject("Project1.Class1")
> > 2. set a = o.Foo

> > What the heck am I doing wrong?



Mon, 27 Sep 2004 23:59:24 GMT  
 OT: Wiring a DLL to return a collection to WSH
hi Alex,

I have been successful with passing back a collection with the method
already mentioned, _BUT_ I was only able to "enumerate" the collection using
a "for loop" and a myColl.Item(i) syntax.

If you want to use the usual "For Each... " syntax, I believe that you will
have to code in another interface.  As to how you go about doing that, you
may wish to refer to msdn or codehound, as I have yet to venture into that
unknown territory.

cheers, jw



Quote:
> Sorry about posting here, but it's a crossover topic anyway and I didn't
get
> much of a response in the COM group on this (probably because this
question
> sounded confused).

> Say I have an ActiveX DLL which exposes a simple collection Foo to the
outside
> world.

> What are the mechanics of exposing this within VB? To make it really
simply,
> let's say that the "collection" is just the integers from 1 to 10.

> I tried this:

> Public Function Foo() As Collection
>   For y = 1 To 10
>   Foo.Add y
>   Next
> End Function

> ...which compiled fine, but I get error 91 ("Object variable or With block
> variable not set") on line 2 whenever I try to call it with a script like
this:

> 1. set o = CreateObject("Project1.Class1")
> 2. set a = o.Foo

> What the heck am I doing wrong?



Tue, 28 Sep 2004 00:49:41 GMT  
 OT: Wiring a DLL to return a collection to WSH
[Please do not mail me a copy of your followup]



Quote:
>If you want to use the usual "For Each... " syntax, I believe that you will
>have to code in another interface.  As to how you go about doing that, you
>may wish to refer to msdn or codehound, as I have yet to venture into that
>unknown territory.

I've done it for collections exposed in izfree with C++ and ATL, but I
don't use VB.  If you can grok C++/ATL, then you can see how izfree
does it -- the source is browsable through sourceforge (URL in my sig).
--
Ask me about my upcoming book on Direct3D from Addison-Wesley!
  Direct3D Book http://www.xmission.com/~legalize/book/
    izfree: Open source tools for Windows Installer
            http://izfree.sourceforge.net


Tue, 28 Sep 2004 00:49:53 GMT  
 OT: Wiring a DLL to return a collection to WSH

Quote:
> I have been successful with passing back a collection with the method
> already mentioned, _BUT_ I was only able to "enumerate" the collection using
> a "for loop" and a myColl.Item(i) syntax.

> If you want to use the usual "For Each... " syntax, I believe that you will
> have to code in another interface.  As to how you go about doing that, you
> may wish to refer to msdn or codehound, as I have yet to venture into that
> unknown territory.

???

Using the example I posted for Alex, I can run a VBScript client that can enumerate the returned collection with a For Each...In...Next loop.

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Tue, 28 Sep 2004 02:00:58 GMT  
 OT: Wiring a DLL to return a collection to WSH



Quote:
>What's your usage context for AddressOf?

About 5 years ago, John Robbins did a thing on MSDN about subclassing to get top
level windows:
http://www.microsoft.com/msj/0897/multithreading.htm

I wanted to rework his form-based code into something I could use to return a
collection of top level window names; unfortunately, I made the mistake of
pulling everything into a class before I realized that callbacks there were a
no-no.  I think I just need to start fresh and implement everything in a generic
module, then write a front end method to call it.



Tue, 28 Sep 2004 02:31:32 GMT  
 OT: Wiring a DLL to return a collection to WSH


Quote:



> >What's your usage context for AddressOf?

> About 5 years ago, John Robbins did a thing on MSDN about subclassing to
get top
> level windows:
> http://www.microsoft.com/msj/0897/multithreading.htm

> I wanted to rework his form-based code into something I could use to
return a
> collection of top level window names; unfortunately, I made the mistake of
> pulling everything into a class before I realized that callbacks there
were a
> no-no.  I think I just need to start fresh and implement everything in a
generic
> module, then write a front end method to call it.

An interesting workaround was posted by Randy Birch:
http://groups.google.com/groups?hl=en&selm=OyDZtMvw9GA.198%40uppssnew....
moswest.msn.net


Tue, 28 Sep 2004 02:51:36 GMT  
 OT: Wiring a DLL to return a collection to WSH
Wow -- that's a weekend thing then.


Quote:




> > >What's your usage context for AddressOf?

> > About 5 years ago, John Robbins did a thing on MSDN about subclassing to
> get top
> > level windows:
> > http://www.microsoft.com/msj/0897/multithreading.htm

> > I wanted to rework his form-based code into something I could use to
> return a
> > collection of top level window names; unfortunately, I made the mistake of
> > pulling everything into a class before I realized that callbacks there
> were a
> > no-no.  I think I just need to start fresh and implement everything in a
> generic
> > module, then write a front end method to call it.

> An interesting workaround was posted by Randy Birch:
> http://groups.google.com/groups?hl=en&selm=OyDZtMvw9GA.198%40uppssnew....
> moswest.msn.net



Tue, 28 Sep 2004 03:00:43 GMT  
 OT: Wiring a DLL to return a collection to WSH
Enumerating Windows Using Callbacks
http://www.mvps.org/vbnet/code/enums/enumwindows.htm

This will leave plenty of time this weekend to mow the lawn, wash the car, and everything else on your "honey do" list (assuming you are married ;-)...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--


Quote:
> Wow -- that's a weekend thing then.







> > > >What's your usage context for AddressOf?

> > > About 5 years ago, John Robbins did a thing on MSDN about subclassing to
> > get top
> > > level windows:
> > > http://www.microsoft.com/msj/0897/multithreading.htm

> > > I wanted to rework his form-based code into something I could use to
> > return a
> > > collection of top level window names; unfortunately, I made the mistake of
> > > pulling everything into a class before I realized that callbacks there
> > were a
> > > no-no.  I think I just need to start fresh and implement everything in a
> > generic
> > > module, then write a front end method to call it.

> > An interesting workaround was posted by Randy Birch:
> > http://groups.google.com/groups?hl=en&selm=OyDZtMvw9GA.198%40uppssnew....
> > moswest.msn.net



Tue, 28 Sep 2004 03:40:47 GMT  
 
 [ 17 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Use of document.all.item or .tags returns signle item not a collection of one item

2. Collection returned by document.getElementById doesn't work

3. Return an empty collection from a function

4. Return a filtered file collection

5. Error 91 (800A005B) accessing collection in an ActiveX DLL

6. Returning image to ASP from DLL

7. Cannot return objects from a VB Activex DLL

8. Wire Ticker Problem

9. Returning Recordset to ASP page from .dll

10. Returning an array from a VB dll

11. Wired event handler never invoked...

12. Empty Variant Returned from VB DLL

 

 
Powered by phpBB® Forum Software