Passing a Variant 2D array of Double to C from Basic via ATL 
Author Message
 Passing a Variant 2D array of Double to C from Basic via ATL

I need to make a function in Visual C that will accept an array from Visual
basic via an ATL function

I have an existing ATL function that gets a Variant from a program called
winspec
it is a 2d array of type double that contains data corresponding to the
intensity of a piel on a CCD camera. I need to get this data to C so that i
can fit it using my existing routines not ot mention that its much faster
I would like to get it there via ATL but I am not quite sure how to do it

The best way would be to pass the array, I think, would be to get a pointer
corresponding to the (0)(0) and send it to C. Is it safe to assume that
Basic makes an array from one hunk of memory?
the array is approximately 400X600. But i dont know how to get a pointer in
Basic.

The other thing to do is pass the entire array but i am not quite sure how
to that when i add a method what should the argument be

double * d1 [][] doesn't work

Any help would be greatly appreciated
Thanks
Todd Goyen



Mon, 26 Aug 2002 03:00:00 GMT  
 Passing a Variant 2D array of Double to C from Basic via ATL
: I need to make a function in Visual C that will accept an array from Visual
: basic via an ATL function

: I have an existing ATL function that gets a Variant from a program called
: winspec
: it is a 2d array of type double that contains data corresponding to the
: intensity of a piel on a CCD camera. I need to get this data to C so that i
: can fit it using my existing routines not ot mention that its much faster
: I would like to get it there via ATL but I am not quite sure how to do it

: The best way would be to pass the array, I think, would be to get a pointer
: corresponding to the (0)(0) and send it to C. Is it safe to assume that
: Basic makes an array from one hunk of memory?
: the array is approximately 400X600. But i dont know how to get a pointer in
: Basic.
<snip>

Don't do this.  Let your C/C++ routine accept a variant.  Then check the
type of the variant; it should be VT_ARRAY|VT_R8.  If so then take the
parray member of the variant and use SafeArrayAccessData to get a pointer
to the data (which you can then cast to double*).  Also make sure to check
the dimensions.  Something like this should work (but it's untested):

HRESULT function(VARIANT v)
{
    // check element type
    if( v.vt != (VT_ARRAY|VT_R8) )
        return E_INVALIDARG;

    // check # of dimensions
    SAFEARRAY * psa = v.parray;
    if( psa->cDims != 2 )
        return E_INVALIDARG;

    // get dimensions
    unsigned long height = psa->rgsabound[0].cElements;
    unsigned long width = psa->rgsabound[1].cElements;

    // get array contents
    HRESULT hr;
    void * pData;
    hr = SafeArrayAccessData( psa, &pData );
    if( FAILED(hr) )
        return hr;
    double * pDoubleData = static_cast<double*>(pData);

    // now access array elements as pDoubleData[ y * height + x ]

    // release array contents
    (void) SafeArrayUnaccessData(psa);

    return S_OK;

Quote:
}

Please don't cross-post so widely.  I hope this message is relevant to the
newsgroups I've left in.

--
Any opinions expressed are my own and not necessarily those of Laser-Scan.



Tue, 27 Aug 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How to get back an array of struct via a variant fron VC++ ATL to VB

2. Passing variant array from VBScript to ATL

3. Trying to pass a Variant Array of Doubles to ActiveX from HTML

4. returning a VARIANT array from a ATL server

5. Array to Variant and Variant to array problem

6. passing 2D array

7. Passing 2d arrays to C++ DLL

8. passing 2D array

9. Passing a 2d or 3d VB array to a DLL

10. Array of Arrays and 2D array

11. Passing variant containing byte array

12. Passing a variant array from asp to a cls and back

 

 
Powered by phpBB® Forum Software