Board index » delphi » Problem with passing variant array from DLL

Problem with passing variant array from DLL

Hi,

I have written a small DLL in Delphi which will pass me back an array
of variants.  The DLL function looks like this.

function BMSearch(pat: PChar; text: PChar; var PosList: variant):
Integer;
begin
  //
  // Details omitted
  //

  PosList := VarArrayCreate([0, N], varInteger);
  for I := 0 to N - 1  do
    PosList[I] := ListOfPos[I];
end;

Everything seems to work fine till I try to free the library from the
client program through the FreeLibrary call.  I get a
Runtime Error 216 at 00001AD2.

I have no clue as to why this is happening.  Can anybody shed some
light.

Thanks.

Kohinoor

Sent via Deja.com
http://www.deja.com/

 

Re:Problem with passing variant array from DLL


Use the VarArrayLock function to fix the variant information in the array
and pass the pointer to the fixed data instead.

<kba...@hotmail.com> schreef in bericht news:938r24$q0f$1@nnrp1.deja.com...

Quote
> Hi,

> I have written a small DLL in Delphi which will pass me back an array
> of variants.  The DLL function looks like this.

> function BMSearch(pat: PChar; text: PChar; var PosList: variant):
> Integer;
> begin
>   //
>   // Details omitted
>   //

>   PosList := VarArrayCreate([0, N], varInteger);
>   for I := 0 to N - 1  do
>     PosList[I] := ListOfPos[I];
> end;

> Everything seems to work fine till I try to free the library from the
> client program through the FreeLibrary call.  I get a
> Runtime Error 216 at 00001AD2.

> I have no clue as to why this is happening.  Can anybody shed some
> light.

> Thanks.

> Kohinoor

> Sent via Deja.com
> http://www.deja.com/

Re:Problem with passing variant array from DLL


Thanks.  It works like a charm.  Is that the only way to pass variant array
out?

Kohinoor.

Quote
"M.H. Avegaart" <avegaartNOS...@mccomm.nl> wrote in message

news:93c4i7$g05$1@porthos.nl.uu.net...
Quote
> Use the VarArrayLock function to fix the variant information in the array
> and pass the pointer to the fixed data instead.

> <kba...@hotmail.com> schreef in bericht

news:938r24$q0f$1@nnrp1.deja.com...
Quote
> > Hi,

> > I have written a small DLL in Delphi which will pass me back an array
> > of variants.  The DLL function looks like this.

> > function BMSearch(pat: PChar; text: PChar; var PosList: variant):
> > Integer;
> > begin
> >   //
> >   // Details omitted
> >   //

> >   PosList := VarArrayCreate([0, N], varInteger);
> >   for I := 0 to N - 1  do
> >     PosList[I] := ListOfPos[I];
> > end;

> > Everything seems to work fine till I try to free the library from the
> > client program through the FreeLibrary call.  I get a
> > Runtime Error 216 at 00001AD2.

> > I have no clue as to why this is happening.  Can anybody shed some
> > light.

> > Thanks.

> > Kohinoor

> > Sent via Deja.com
> > http://www.deja.com/

Other Threads