
Passing array to COM component
Kevin,
You need to use SAFEARRAYS. The help from MSDN you're quoting only works
when the object being passed the array is in-process.
The IDL for the C++ COM component needs to have a method defined as:
[helpstring("method PassArrayOfFileNames")]
PassArrayOfFileNames([in]SAFEARRAY(BSTR) fileNames);
(fileNames may have to be a *fileNames - can't remember off the top of my
head - if you get errors compiling / referencing it from VB then try
changing to *)
The C++ method is:
STDMETHOD(PassArrayOfFileNames)(/*[in]*/SAFEARRAY *fileNames);
[Note that it needs one more * than the IDL]
In VB you can call it as follows:
Dim f(0 to 4) as String
f(0) = ...
f(1) = ....
etc
' Assume x is the object implementing the method above
x.PassArrayOfFileNames(f)
In the C++ code you will need to use the SAFEARRAY structure and APIs to
access the data. I wrote a wrapper class that makes it easier to use' if
you're using MFC then there's a CSafeArray you could try.
Regards,
Nick
Quote:
>Does anybody know how to pass an entire array as a parameter in a COM
>component method?
>I am trying to pass an array of filenames. The COM component is a MTS
>component written in VC++. I found some help on the MSDN cd that mentioned
>that to pass an entire integer array just pass the 1st subscript like
>strFiles(1). When I do that with my string array then my component crashes
>every time I access the second subscript in the com componet. re is a
>snippet of my asp code and the error msg I receive in the browser:
><% Option Explicit
>dim objTest
>dim strFiles(2)
>strFiles(1) = "c:\\temp\\test.dll"
>strFiles(2) = "c:\\temp\\hello.txt"
>call objTest.exeCabMgr( strFiles(), 2, "c:\\temp", 10000, "100", "" )
>Error Message:
>Microsoft VBScript runtime error '800a0009'
>Subscript out of range
>/test.asp, line 18
>If I pass the first subscript then I crash in my mts component:
>dim objTest
>dim strFiles(2)
>strFiles(1) = "c:\\temp\\test.dll"
>strFiles(2) = "c:\\temp\\hello.txt"
>call objTest.exeCabMgr( strFiles(1), 2, "c:\\temp", 10000, "100", "" )
>Thanks in advance!!!