Passing Arrays Between VB and ATL COM object 
Author Message
 Passing Arrays Between VB and ATL COM object

I'm trying to pass arrays between Visual Basic and an ATL COM object.

I've declared a 2-dimensional array (100, 1) which I'm passing to C++ as
safearrays.

In the C++ method I'm adding elements to (100,0) array. and send back the
array to VB.

When I call the same function again how can I add elements to the (100,1)
array.

For example.

In my first pass I want this result

( 1, 0 ) ( 2, 0 ) ( 3, 0 ) ( 4, 0 ) ( 5, 0 ) ( 6, 0 )

In my second pass I want this result

( 1, 7 ) ( 2, 8 ) ( 3, 9 ) ( 4, 10 ) ( 5, 11 ) ( 6, 12 ).

At the moment I'm doing the first pass OK but when I do the next pass I get

( 7, 0 ) ( 8, 0 ) ( 9, 0 ) ( 10, 0 ) ( 11, 0 ) ( 12, 0 )

Can anyone help ??

Sample C++ method code

STDMETHODIMP CFunctionsWrapper::IdsingWrapper( SAFEARRAY **psaDataArray )

{

HRESULT lResult;

lResult = S_OK;

lResult = SafeArrayLock(*psaDataArray);

if (lResult)

goto Tidy;

pArrayElements = (double* ) (*psaDataArray)->pvData;

DoTheWork(pArrayElements);

lResult = SafeArrayUnlock(*psaDataArray);

if (lResult)

goto Tidy;

Quote:
}

Sample VB code

Dim MyObj As New QANTIMWRAPPERLib.FunctionsWrapper

Dim dataArray(100, 1) As Double

Dim ich As Integer

For ich = 1 To ip

MyObj.IdsingWrapper dataArray

If ich = 1 Then

PopulateListBox1 dataArray

ElseIf ich = 2 Then

PopulateListBox2 dataArray

End If

Next

PLEASE HELP !!!!!!!!!



Tue, 18 May 2004 00:46:02 GMT  
 Passing Arrays Between VB and ATL COM object
Use SafeArrayAccessData/SafeArrayUnaccessData instead.

As for your problem - you are likely not accessing the correct
offsets in the array... What is the array definition in IDL?

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> I'm trying to pass arrays between Visual Basic and an ATL COM object.

> I've declared a 2-dimensional array (100, 1) which I'm passing to C++ as
> safearrays.

> In the C++ method I'm adding elements to (100,0) array. and send back the
> array to VB.

> When I call the same function again how can I add elements to the (100,1)
> array.

> For example.

> In my first pass I want this result

> ( 1, 0 ) ( 2, 0 ) ( 3, 0 ) ( 4, 0 ) ( 5, 0 ) ( 6, 0 )

> In my second pass I want this result

> ( 1, 7 ) ( 2, 8 ) ( 3, 9 ) ( 4, 10 ) ( 5, 11 ) ( 6, 12 ).

> At the moment I'm doing the first pass OK but when I do the next pass I
get

> ( 7, 0 ) ( 8, 0 ) ( 9, 0 ) ( 10, 0 ) ( 11, 0 ) ( 12, 0 )

> Can anyone help ??

> Sample C++ method code

> STDMETHODIMP CFunctionsWrapper::IdsingWrapper( SAFEARRAY **psaDataArray )

> {

> HRESULT lResult;

> lResult = S_OK;

> lResult = SafeArrayLock(*psaDataArray);

> if (lResult)

> goto Tidy;

> pArrayElements = (double* ) (*psaDataArray)->pvData;

> DoTheWork(pArrayElements);

> lResult = SafeArrayUnlock(*psaDataArray);

> if (lResult)

> goto Tidy;

> }

> Sample VB code

> Dim MyObj As New QANTIMWRAPPERLib.FunctionsWrapper

> Dim dataArray(100, 1) As Double

> Dim ich As Integer

> For ich = 1 To ip

> MyObj.IdsingWrapper dataArray

> If ich = 1 Then

> PopulateListBox1 dataArray

> ElseIf ich = 2 Then

> PopulateListBox2 dataArray

> End If

> Next

> PLEASE HELP !!!!!!!!!



Tue, 18 May 2004 04:53:15 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. ATL COM object can't get arrays from VB in VB/VC6

2. ATL COM object can't get arrays from VB in VB/VC6

3. passing com/atl object in vb

4. Passing VB dictionaries as parameters to ATL COM objects

5. trouble passing String from VB to ATL com object expecting BSTR

6. Help: Passing strings between VB and ATL-COM objects

7. passing COM object pointers to another COM object in ATL

8. Passing an integer array from Visual Basic to an ATL COM object function

9. ATL COM - Passing ATL COM classes through another ATL COM class in the same app

10. passing objects from VB as VARIANT to COM server object failing

11. passing objects from VB as VARIANT to COM server object failing

12. COM/ATL novice:passing object pointers through methods on a COM interface

 

 
Powered by phpBB® Forum Software