FIX: "Invalid Procedure Call" Referencing Collection Item

ID: Q159410


The information in this article applies to:
  • Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 16-bit and 32-bit, for Windows, version 4.0


SYMPTOMS

If you reference a collection object created by an out-of-process OLE server with a variable index and the index variable is specified as an Integer or Long in a Dimension statement, the following error appears:

"Invalid Procedure Call"


RESOLUTION

Make sure that the index variable is specified as Variant in the Dimension statement.


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in Visual Basic 6.0.


MORE INFORMATION

The out-of-process OLE server (EXE server) that created the collection object receives the index through remote procedure call (RPC). This data is marshaled across the processes and received as a Variant data type only.

This behavior does not occur if the collection object is created in an in-process server because RPC is in the same process and is not needed to transmit the data between the two different processes.

Steps to Reproduce Behavior

  1. Start a new project in Visual Basic. Form1 is created by default.


  2. On the Visual Basic menu, click Insert and Class Module to add a new class module.


  3. Insert the following code into the class module code window:
    
       Dim x As New Collection
    
       Public Function PassCollection() As Collection
                x.Add "Item 1"
                x.Add "Item 2"
                x.Add "Item 3"
    
                Set PassCollection = x
       End Function
     


  4. Change the following properties on the class module:
    
       Instancing = 2-Createable MultiUse
       Public = True
     


  5. On the Visual Basic menu, click Insert and Module to add a new Basic code module.


  6. Insert the following code in the code window of the Basic code module:
    
       Sub main()
                Load Form1
       End Sub
     


  7. On the Visual Basic menu, click Tools and Options. On the Project tab, change the following fields:

    Startup Form = Sub Main
    Project Name = OLECOL
    StartMode = OLE Server
    Application Description = OLE Collection Example


  8. Click OK, and then press the F5 key to run the project.


  9. Start another session of Visual Basic. A new Project with Form1 appears by default.


  10. Place a CommandButton on Form1.


  11. Insert the following code into the General Declaration section of the code window for Form1:
    
        Private Sub Command1_Click()
                 Dim c As Collection
                 Dim o As New OLECOL.Class1
                 Dim i As Long
    
                 Set c = o.PassCollection
    
                 For i = 1 To c.Count
        MsgBox c(i)
                 Next i
        End Sub
     


  12. On the Visual Basic menu, click Tools and References. Select "OLE Collection Example" on the reference list, and then click OK.


  13. Run the project by pressing the F5 key and clicking on Command1. The following error message appears:
    "Invalid Procedure Call"


Additional query words: kbVBp400bug kbVBp600fix kbVBp kbdsd kbDSupport kbVBA

Keywords : kbGrpVB
Version :
Platform : NT WINDOWS
Issue type : kbprb


Last Reviewed: January 5, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.