Board index » delphi » DLL's and Delphi 2.0

DLL's and Delphi 2.0

i have a Borland C++ 5.0B DLL which passes a 11 character alpha string
back to my delphi form , the problem is that the variable doesn't get
updated in the delphi form :

my delphi code is :

function TRANDEL( p : pchar ) : Integer ; far ; external 'EDI';

...

procedure TDNoteForm.TransBtnClick(Sender: TObject);
var
  p : pchar;
begin

  p := '000000000';  
  TRANDEL(p);
  filename := strpas(p);
  showmessage('Delphi '+filename);

end;

when i perform the show message , it has whatever i pass to the DLL in p
( ie. in this case 00000000 ) I know it's not my DLL because it works if
i use Paradox for Windows 7 to test it.

Any ideas ?

TIA
Peter

Peter Robinson   << EMail : pe...@vyper.demon.co.uk >>

Colonial Software Limited

 

Re:DLL's and Delphi 2.0


Quote
Peter Robinson wrote:

> i have a Borland C++ 5.0B DLL which passes a 11 character alpha string
> back to my delphi form , the problem is that the variable doesn't get
> updated in the delphi form :

> my delphi code is :

> function TRANDEL( p : pchar ) : Integer ; far ; external 'EDI';

This took me a long time to figure out since it is not documented very
well in the manuals.  Since Delphi 2 is 32 bits, the 'far' keyword is no
longer needed.  In its place, though, add the keyword 'stdcall' to force
Delphi to use standard passing of variables rather then default register
calling.  Hope this helps.

-Pierre

Re:DLL's and Delphi 2.0


In article <31A648D6....@hpl.hp.com>, Pierre Mertz <pme...@hpl.hp.com>
writes

Quote

>> function TRANDEL( p : pchar ) : Integer ; far ; external 'EDI';

>This took me a long time to figure out since it is not documented very
>well in the manuals.  Since Delphi 2 is 32 bits, the 'far' keyword is no
>longer needed.  In its place, though, add the keyword 'stdcall' to force
>Delphi to use standard passing of variables rather then default register
>calling.  Hope this helps.

>-Pierre

Thanks Pierre , but if i substitute stdcall for far , i get the
following message
Access Viloation of address 00522F32. Write of address 0049119C.

when it try to showmessage or strpas the pchar variable .

Peter
................................................................
..  Peter Robinson   e-mail  < pe...@vyper.demon.co.uk>       ..
................................................................

Re:DLL's and Delphi 2.0


Quote
Peter Robinson wrote:

> i have a Borland C++ 5.0B DLL which passes a 11 character alpha string
> back to my delphi form , the problem is that the variable doesn't get
> updated in the delphi form :

> my delphi code is :

> function TRANDEL( p : pchar ) : Integer ; far ; external 'EDI';

> ...

> procedure TDNoteForm.TransBtnClick(Sender: TObject);
> var
>   p : pchar;
> begin

>   p := '000000000';
>   TRANDEL(p);
>   filename := strpas(p);
>   showmessage('Delphi '+filename);

> end;

> when i perform the show message , it has whatever i pass to the DLL in p
> ( ie. in this case 00000000 ) I know it's not my DLL because it works if
> i use Paradox for Windows 7 to test it.

> Any ideas ?

> TIA
> Peter

> Peter Robinson   << EMail : pe...@vyper.demon.co.uk >>

> Colonial Software Limited

Hello, Peter

I think you are having the same trouble a couple of other people have
been having, i.e., sorting out the calling conventions between Delphi
and C++. There is a pretty good overview of this at the following URL:

        http://www.borland.com/News/techlib/brick.html

Regards.                                ...edn

Re:DLL's and Delphi 2.0


Quote
Pierre Mertz wrote:

> Peter Robinson wrote:

> > i have a Borland C++ 5.0B DLL which passes a 11 character alpha string
> > back to my delphi form , the problem is that the variable doesn't get
> > updated in the delphi form :

> > my delphi code is :

> > function TRANDEL( p : pchar ) : Integer ; far ; external 'EDI';

> This took me a long time to figure out since it is not documented very
> well in the manuals.  Since Delphi 2 is 32 bits, the 'far' keyword is no
> longer needed.  In its place, though, add the keyword 'stdcall' to force
> Delphi to use standard passing of variables rather then default register
> calling.  Hope this helps.

> -Pierre

Make sure that the BC DLL is using the same calling convention as well. I
think the default for BC is cdecl. You can apply this keyword to the Delphi
code if need be. Once again, check out this URL for a little more information:

        http://www.borland.com/News/techlib/brick.html

...edn

Re:DLL's and Delphi 2.0


Quote
Peter Robinson <pe...@vyper.demon.co.uk> writes:

Try to use stdcall in import declaration

function TRANDEL( p : pchar ) : Integer ; stdcall;far ; external 'EDI';

Other Threads