Re: ActiveX c# Array

Tech-Archive recommends: Speed Up your PC by fixing your registry




<mitch@xxxxxxxxxxxxxxxxxx> wrote in message
news:1146730449.067529.54110@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| Is this really as hard as it seems. I've been truly suprised by the
| lack of any information/suggestions about this. It should be so simple.
|
| In c# I have:
|
| double [] data = {1.0,2.0,3.0,4.0};
|
| I need to pas this array to an ActiveX control which I have written in
| Visual Studio 6 using the ActiveX wizard.
|
| So I have full control over both sets of source code. How can I Add a
| method to the ActiveX control which I can call from the c# code to pass
| the array.
|
| I've done this countless times with MFC c++ using SAFEARRYs and
| SAEFARRAYs in a VARIANT. But I cannot get this to work from c#. Has
| anyone ever done it?
|
| Any help greatly appreciated,
| Mitch.
|

Declare your method taking a SAFEARRAY of double in IDL.

HRESULT PassDoubleArray([in] SAFEARRAY(double) arr);

implement like:

STDMETHODIMP CTest::PassDoubleArray(SAFEARRAY * arr)
{
double* temp;
SafeArrayAccessData(arr, (void**)&temp);
long ubound;
SafeArrayGetUBound(arr, 1, &ubound);
for(int i = 0; i <= ubound; i++)
// use array data
..
SafeArrayUnaccessData(arr);
return S_OK;
}




and call it from C# like this:

double[] darr = new double[5] {1.1, 2.2, 3.3, 4.44, 5.2356};

obj.PassDoubleArray(darr);

Willy.



.



Relevant Pages

  • Re: Evaluating unary *
    ... 'arr' exists, ... value can be used with the same syntax as would be used to access a 2D array of the kind you're referring to, but that 2D array is just a different way of looking as the same object that was already created by the definition of 'arr'. ... to me, it makes sense to return a pointer to the first value of an array, but to return the address of the pointer to the first value of an array, is not directly possible as such. ... lea eax, ...
    (comp.std.c)
  • Re: Evaluating unary *
    ... value can be used with the same syntax as would be used to access a 2D array of the kind you're referring to, but that 2D array is just a different way of looking as the same object that was already created by the definition of 'arr'. ... the expression &arr requires no special handling beyond insertion of the appropriate address into a suitable register. ... to me, it makes sense to return a pointer to the first value of an array, but to return the address of the pointer to the first value of an array, is not directly possible as such. ... It does create a pointer value which points at arr itself, and treats the entirety of arr as the first element in an array containing exactly one element of type int. ...
    (comp.std.c)
  • Re: multi dimensional arrays as one dimension array
    ... Are you of the opinion that one or both of memcpy(p, arr, sizeof arr) ... way of converting a two-dimensional array into a one-dimensional ... &arr) is supposed to be pointer constrained legally to range over ... arrays of character type and other objects treated as arrays ...
    (comp.lang.c)
  • Re: can .range return a 1D array?
    ... LBound of arrays that are declared like this: ... Dim ptr As Long ... ' Variant parameter that has received the array ... ' Sets Ary's LBound to NewBound, ...
    (microsoft.public.excel.programming)
  • Re: Fastest reading of large text files
    ... As I understand it, arr is an array of type Variant, which the function ... OpenTextFileToArray is populating with the contents of the named text file. ... But is it not an array in the PROGRAM? ... Dim hFile As Long ...
    (microsoft.public.excel.programming)