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[3]
arString[1] = 'Text1'
arString[2] = 'Text2'
arString[3] = '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[0]) ;
...
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?

Thanks, TZ

Answers


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.


Need Your Help

Symfony debug toolbar working intermittently

symfony1

I am using SF 1.3.2 with Propel ORM on Ubuntu 9.10

BizTalk: how to limit number of connections to a wcf service?

wcf biztalk throttling biztalk-2009

I developed a BizTalk application that receives as input a file that contains a bunch of messages. I use the BizTalk XML disassembler component to 'debatch' the file in sepereate messages. Each of ...