I want to encapsulate a COM+ collection (SharedPropertyGroupManager).
This collection have an enum. How can I build a VB collection with an
enum which will use the SharedPropertyGroupManager enum ?

I tried something like:

private m_objSPGM as SharedPropertyGroupManager
...
Public Property Get NewEnum() As IUnknown
Set NewEnum = m_objSPGM.[_NewEnum]
End Property

When I try to make the project, I got an error on
m_objSPGM.[_NewEnum].

Anyone have an idea ?

Thanks,
Benoit

Re: Enum in collection by MikeD

MikeD
Thu Jun 03 10:42:50 CDT 2004


"Benoit" <nospam@nospam.com> wrote in message
news:qtdub0dn2hvglejj1n00e732al4q91d1bf@4ax.com...
> I want to encapsulate a COM+ collection (SharedPropertyGroupManager).
> This collection have an enum. How can I build a VB collection with an
> enum which will use the SharedPropertyGroupManager enum ?
>
> I tried something like:
>
> private m_objSPGM as SharedPropertyGroupManager
> ...
> Public Property Get NewEnum() As IUnknown
> Set NewEnum = m_objSPGM.[_NewEnum]
> End Property
>
> When I try to make the project, I got an error on
> m_objSPGM.[_NewEnum].
>
> Anyone have an idea ?


There's one more thing (possibly two) you have to do. Open the code window
for this module and select Procedure Attributes from VB's Tools menu.
Select 'NewEnum' in the Name dropdown and click the Advanced button. Give
this property a Procedure ID of -4. In the Attributes frame, you should
also add a checkmark to 'Hide this member'.

The other possible thing you may have to do is set a reference to "OLE
Automation" in the References dialog (at the very least, double check that
this reference is set). Since you didn't state the error message (you
should ALWAYS tell us the error message), failure to set this reference
could cause an error as well. I'm thinking this is the more likely cause
since simply not setting the procedure ID to -4 wouldn't cause an error. It
just wouldn't enumerate (it would always return the first item in the
collection).

Lastly, my understanding is that the enumerator should be a method (just
change it to 'Public Function NewEnum() As IUnknown'), not a property. I
*think* it still works OK as a property, though.

If none of this solves the problem, state the exact error message you're
getting. It's important to know what the error is to give you a definitive
answer.

Mike



Re: Enum in collection by Benoit

Benoit
Thu Jun 03 11:26:26 CDT 2004

Here's my code as showed in Notepad :

VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "Collection1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True

Option Explicit

Private m_objSPGM As COMSVCSLib.SharedPropertyGroupManager

Public Function NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
Set NewEnum = m_objSPGM.[_NewEnum]
End Function

Private Sub Class_Initialize()
Set m_objSPGM = New COMSVCSLib.SharedPropertyGroupManager
End Sub

Private Sub Class_Terminate()
Set m_objSPGM = Nothing
End Sub

The error message is :
Function or interface marked as restricted, or the function uses an
Automation type not supported in Visual Basic.

The definition of COM+ SharedPropertyGroupManager interface :
http://msdn.microsoft.com/library/en-us/cossdk/htm/isharedpropertygroupmanager_0gc2.asp

I also foud that website:
http://www.mvps.org/vbvision/Super_Collections.htm

Maybe it will allow me to build an enum from scratch which will be
able to use SharedPropertyGroupManager enumerator


Re: Enum in collection by MikeD

MikeD
Thu Jun 03 13:15:14 CDT 2004


"Benoit" <nospam@nospam.com> wrote in message
news:cjjub0h0ssrra9aa9ksrc7tc0gb3u0h6nq@4ax.com...
> Here's my code as showed in Notepad :
>
> VERSION 1.0 CLASS
> BEGIN
> MultiUse = -1 'True
> Persistable = 0 'NotPersistable
> DataBindingBehavior = 0 'vbNone
> DataSourceBehavior = 0 'vbNone
> MTSTransactionMode = 0 'NotAnMTSObject
> END
> Attribute VB_Name = "Collection1"
> Attribute VB_GlobalNameSpace = False
> Attribute VB_Creatable = True
> Attribute VB_PredeclaredId = False
> Attribute VB_Exposed = True
>
> Option Explicit
>
> Private m_objSPGM As COMSVCSLib.SharedPropertyGroupManager
>
> Public Function NewEnum() As IUnknown
> Attribute NewEnum.VB_UserMemId = -4
> Set NewEnum = m_objSPGM.[_NewEnum]
> End Function
>
> Private Sub Class_Initialize()
> Set m_objSPGM = New COMSVCSLib.SharedPropertyGroupManager
> End Sub
>
> Private Sub Class_Terminate()
> Set m_objSPGM = Nothing
> End Sub
>
> The error message is :
> Function or interface marked as restricted, or the function uses an
> Automation type not supported in Visual Basic.
>
> The definition of COM+ SharedPropertyGroupManager interface :
>
http://msdn.microsoft.com/library/en-us/cossdk/htm/isharedpropertygroupmanager_0gc2.asp
>
> I also foud that website:
> http://www.mvps.org/vbvision/Super_Collections.htm
>


I don't get at all what you're trying to do now. If you want the
SharedPropertyGroupManager object exposed, then just create a public
property for it.

Public Property Get SPGM() As COMSVCSLib.SharedPropertyGroupManager
Set SPGM = m_objSPGM
End Property

Also, did you see this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cossdk/htm/isharedpropertygroupmanager_24rx.asp

which states "This property is restricted in Microsoft Visual Basic and
cannot be used.". IOW, you cannot use _NewEnum in your own code. It looks
like you need to expose SharedPropertyGroupManager as above and use a
For..Each on that.

Mike



Re: Enum in collection by Benoit

Benoit
Thu Jun 03 15:02:52 CDT 2004

On Thu, 3 Jun 2004 14:15:14 -0400, "MikeD" <nobody@nowhere.edu> wrote:

>I don't get at all what you're trying to do now. If you want the
>SharedPropertyGroupManager object exposed, then just create a public
>property for it.
>
>Public Property Get SPGM() As COMSVCSLib.SharedPropertyGroupManager
> Set SPGM = m_objSPGM
>End Property
>
>Mike
>

I know I could do it like that, but I don't want to expose it, that's
why I'm trying to wrap it.

I think I will wrap it without the enum.