Board index » cppbuilder » Parameter Passing Problem with ActiveX object

Parameter Passing Problem with ActiveX object

We have a third party ActiveX object that has methods containing [out]
parameters of the form
LPSAFEARRAY *.

    After much experimentation we have determined that these out parameters
match up to VB's

    technique of passing an un-dimensioned pointer to an array i.e.

    Dim A() as long

    Call Object.Method(A())

    To use these same methods in BCB4 it is necessary to create a pointer to
a LPSAFEARRAY that
    de-references to NULL but the pointer itself is not NULL.

    i.e.

        Object->Method(LPSAFEARRAY * X) X is not NULL but *X is NULL.

    in BCB4 if you create LPSAFEARRAY X=0; // the compiler makes this NULL

    passing a pointer to this goes nowhere as it is also a NULL pointer. THe
Object's method returns immediately.

    Creating LPSAFEARRAY * X and assigning *X=0 causes a run-time error.

    Can anyone suggest a work-around for this problem??

    Thanks

    Joe Bingham

 

Re:Parameter Passing Problem with ActiveX object


Quote
"Joe Bingham" <joseph.bing...@bentech1.com> wrote:
>We have a third party ActiveX object that has methods containing [out]
>parameters of the form
>LPSAFEARRAY *.

>    After much experimentation we have determined that these out parameters
>match up to VB's

>    technique of passing an un-dimensioned pointer to an array i.e.

>    Dim A() as long

>    Call Object.Method(A())

>    To use these same methods in BCB4 it is necessary to create a pointer to
>a LPSAFEARRAY that
>    de-references to NULL but the pointer itself is not NULL.

>    i.e.

>        Object->Method(LPSAFEARRAY * X) X is not NULL but *X is NULL.

>    in BCB4 if you create LPSAFEARRAY X=0; // the compiler makes this NULL

>    passing a pointer to this goes nowhere as it is also a NULL pointer. THe
>Object's method returns immediately.

>    Creating LPSAFEARRAY * X and assigning *X=0 causes a run-time error.

>    Can anyone suggest a work-around for this problem??

I've not tried this, understand, but ...

If you're passing an out parameter, then you pass a pointer to whatever
is to be changed. This pointer itself should point to a valid
whatever-it-is.

In this case, you whatever-it-is is an LPSAFEARRAY.

So, the following might well work:

  void f()
  {
    LPSAFEARRAY X=0; // the compiler makes this NULL
    Object->Method(&X); // X is not NULL but *X is NULL.
    if (X != NULL)
    {
      ...
      // some code to safely free up X, since you now own it. Otherwise,
      // it'll leak
    }
  }

Hope this a) works, and b) helps

Alan Bellingham
--
al...@episys.com

Re:Parameter Passing Problem with ActiveX object


Thanks Alan and All:

    I have verified that BCB4 is doing everything correctly this is a
problem to be resolved between me and the Object.

    Thanks

    Joe Bingham

Other Threads