Send an array of strings from vfp to a dll created on delphi
I've created a DLL in Delphi that has to receive among other parameters, an array of strings from Visual Fox Pro.
I've tried different ways to send the data, but usually what i get is a "Declare DLL call caused an exception", and I'm not sure if the problem is the type of variable I'm sending on VFP or the type I'm receiving on Delphi.
We've tried sending an array of strings from VFP
Local arString arString = 'Text1' arString = 'Text2' arString = 'Text3' Declare integer callDLL in (dllfile) string, string, string CallDLL('firstvar', 'secondvar', arString)
and on Delphi:
type Str: Array[1..3] of string; function CallDLL(firstvar, secondvar: PAnsiChar; S: Str):Integer; stdcall ; begin ShowMessage(S) ; ... end; exports CallDLL ;
Before I added the array of strings, the DLL worked correctly, so it's not the overall construction of the other parameters.
Any idea of what I'm doing wrong?
The simple bits first:
- Your Delphi function needs to return an integer.
- The string parameters are wrong. Delphi string is a managed private Delphi type. Those params should be PAnsiChar, pointer to null-terminated B bit character array.
Now to the string array. From @TLama's link it appears that arrays cannot be marshaled. So, you'll have to concatenate them, perhaps using double null-terminated strings. Or call the function multiple times and allow the DLL to collect the strings into an array or list.