Board index » delphi » How to Call VC DLL in Delphi

How to Call VC DLL in Delphi

Hi all,
I use a Vc .dll to get a long string and return it. That dll runs right
in VC, but I call it from delphi will cause some error.

My dll in c:
int WINAPI Lmain( char* gettype, char *buf, int len)
{
//using "gettype" to get a string and send to buf, its length limits to len;
//the result stored in "buf"

Quote
}

In delphi:
function GetSourceDoc(gettype: PChar; var Buf: PChar; len:integer):integer;
         external 'demo.dll' name 'Lmain';

procedure TForm1.BitBtn1Click(Sender: TObject);
var a, b: PChar;
begin
     a := '166';
     GetMem(b,65536);
     GetSourceDoc(a,b,65536);
     FreeMem(b);
end;

It will cause access violation.

I don't know how to get the result in Delphi because of different variable
type in c and pascal.

Who can give me some advice?

Thanks a lot.

Ouyang

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading

 

Re:How to Call VC DLL in Delphi


You passed the second Pchar by reference (var buf: pchar), which is
equivalent to C's char **buf.

Use buf: pchar (which you did correctly for the first pchar. Why did you
change strategy for the second, one wonders... ;-)

JdV!!

Quote
mouy...@yahoo.com wrote:

> Hi all,
> I use a Vc .dll to get a long string and return it. That dll runs right
> in VC, but I call it from delphi will cause some error.

> My dll in c:
> int WINAPI Lmain( char* gettype, char *buf, int len)
> {
> //using "gettype" to get a string and send to buf, its length limits to len;
> //the result stored in "buf"
> }

> In delphi:
> function GetSourceDoc(gettype: PChar; var Buf: PChar; len:integer):integer;
>          external 'demo.dll' name 'Lmain';

> procedure TForm1.BitBtn1Click(Sender: TObject);
> var a, b: PChar;
> begin
>      a := '166';
>      GetMem(b,65536);
>      GetSourceDoc(a,b,65536);
>      FreeMem(b);
> end;

> It will cause access violation.

> I don't know how to get the result in Delphi because of different variable
> type in c and pascal.

> Who can give me some advice?

> Thanks a lot.

> Ouyang

> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/   Now offering spam-free web-based newsreading

--
========================================================================
Jan de Visser                          etmj...@aom.ericsson.se
M?/ETX/A/B NMAC Team SAC
tel. +46 31 74 71890                   ECN 865 71890
                    Vette pech voor de kabouters!
========================================================================

Other Threads