Passing array to COM component 
Author Message
 Passing array to COM component

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!!!



Fri, 30 Nov 2001 03:00:00 GMT  
 Passing array to COM component

Arrays in ASP are zero based, so if you dim(2), use strFiles(0)
strFiles(1)

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!!!



Fri, 30 Nov 2001 03:00:00 GMT  
 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!!!



Sat, 01 Dec 2001 03:00:00 GMT  
 Passing array to COM component
I get the following message when I try to add a new method with the
SAFEARRAY parameter in the class view:  "Unable to create the function
because the header or implementation file could not be found".  I am using
ATL.  Any idea of what header implementation file they are referring to?
Quote:

>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



Sat, 01 Dec 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Passing Arrays to COM Components

2. Passing Variant Array from ASP to COM Component

3. Passing Variant Array from ASP to COM Component

4. Passing optional object arguments from COM components

5. Passing by reference to an ATL COM component

6. pass a COM object reference to a WSC component

7. passing array as parameter to activex component

8. Passing Array of string to component

9. Passing Arrays between ASP/VBScript and ActiveX Components...

10. Passing arrays from ASP To VB-components...need help

11. passing array as parameter to activex component

12. Passing Arrays between ASP/VBScript and ActiveX Components...

 

 
Powered by phpBB® Forum Software