Passing array from VB to VC++ 
Author Message
 Passing array from VB to VC++

Hello -

I have a Server written in VC++ which contains a collection
called Sets. I'm having trouble using the Add method.

Type library definition:
  [id(3)]
   HRESULT Add([in] BSTR name, [in]SetObjectType type, [in]SetOptionType
otype, [in]VARIANT list, [out, retval]_IDualSetItem** prop);

Note:  SetObjectType and SetOptionType are enums.
            list is meant to hold a SAFEARRAY.

VB code:
    Dim list(1 To 2) As Integer
    Dim SCSets As MyApp.Sets
    Dim SCSet As MyApp.Set

    Set SCSets = MyApp.Sets

    list(1) = 2
    list(2) = 4
    Set SCSet = SCSets.Add("set1", stPoint, sotList, list)

The above line generates Run-time error 13 "Type mismatch error".
I suspect it is because of the array.  What's the correct method for
passing an array?

Thanks,
Drew



Sat, 29 Mar 2003 03:00:00 GMT  
 Passing array from VB to VC++
I am not sure (have not done VB in a while) but,

dim var as VARIANT
var = list
Set SCSet = SCSets.Add("set1", stPoint, sotList, var)

your list looks more like SAFEARRAY(int), not a VARIANT. I do not know if VB
will convert behind the scenes for you. Did you ever get into C++ method?
"Type Mistmach" can be caused by failing QI when Set is done.

-vlad

Quote:

> Hello -

> I have a Server written in VC++ which contains a collection
> called Sets. I'm having trouble using the Add method.

> Type library definition:
>   [id(3)]
>    HRESULT Add([in] BSTR name, [in]SetObjectType type, [in]SetOptionType
> otype, [in]VARIANT list, [out, retval]_IDualSetItem** prop);

> Note:  SetObjectType and SetOptionType are enums.
>             list is meant to hold a SAFEARRAY.

> VB code:
>     Dim list(1 To 2) As Integer
>     Dim SCSets As MyApp.Sets
>     Dim SCSet As MyApp.Set

>     Set SCSets = MyApp.Sets

>     list(1) = 2
>     list(2) = 4
>     Set SCSet = SCSets.Add("set1", stPoint, sotList, list)

> The above line generates Run-time error 13 "Type mismatch error".
> I suspect it is because of the array.  What's the correct method for
> passing an array?

> Thanks,
> Drew



Sun, 30 Mar 2003 03:00:00 GMT  
 Passing array from VB to VC++
Vlad,

I gave that a try but still get the Type Mismatch error.
I never actually get to the C++ code, so it's not a failure
of the method.  Any ither ideas?

Thanks,
Drew


Quote:
> I am not sure (have not done VB in a while) but,

> dim var as VARIANT
> var = list
> Set SCSet = SCSets.Add("set1", stPoint, sotList, var)

> your list looks more like SAFEARRAY(int), not a VARIANT. I do not know if
VB
> will convert behind the scenes for you. Did you ever get into C++ method?
> "Type Mistmach" can be caused by failing QI when Set is done.

> -vlad



Sun, 30 Mar 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Passing array from VB to VC

2. Passing array from VB to VC++

3. HELP !!! Passing arrays from VB to VC++

4. passing arrays from vb to vc

5. HELP NEEDED: Passing array from VB to VC++ and back

6. How To pass 2D String array to VB from VC++ Using Safe array

7. Passing string Arrays between VB and VC

8. Passing an array VC++ COMM => VB

9. Passing 2D array between VB And VC++

10. passing short array parameters to VC++ DLL in VB

11. HOWTO: Pass VB UDT that contains an array to VC dll

12. Pass array ByRef from VB to VC 6 DLL

 

 
Powered by phpBB® Forum Software