The information in this article applies to:
- Standard, Professional, and Enterprise Editions of Microsoft Visual
Basic, 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.
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
- Start a new project in Visual Basic. Form1 is created by default.
- On the Visual Basic menu, click Insert and Class Module to add a new
class module.
- 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
- Change the following properties on the class module:
Instancing = 2-Createable MultiUse
Public = True
- On the Visual Basic menu, click Insert and Module to add a new Basic
code module.
- Insert the following code in the code window of the Basic code module:
Sub main()
Load Form1
End Sub
- 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
- Click OK, and then press the F5 key to run the project.
- Start another session of Visual Basic. A new Project with Form1 appears
by default.
- Place a CommandButton on Form1.
- 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
- On the Visual Basic menu, click Tools and References. Select "OLE
Collection Example" on the reference list, and then click OK.
- Run the project by pressing the F5 key and clicking on Command1. The
following error message appears:
"Invalid Procedure Call"
|