Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Calling external DLL made in Delphi

Calling external DLL made in Delphi

Calling external DLL made in Delphi

I was trying to find here some example of calling Delphi procedures from VFP and I didn't found anything. That's why I spent last weekend with VFP a Delphi together.

Before I'll show you my solution I want to tell you taht my task was to display 4-byte single data type in VFP. That's why I used it that way. I don't know how usefull it can be for you, but you can see in this example returning integer values, working with pointers and some other stuff...


------ Delphi source "dllProject.pas" ------

library dllProject;

  SysUtils, dialogs;

 dllShowMessages : integer; // 0 = don't show messageboxes;

procedure dllMessage(strMess:string);
  if dllShowMessages<>0 then ShowMessage(strMess);

procedure dllStr(p:pointer); cdecl;
 // p should point to single-type variable and dllStr puts there PChar
 // calling application must prepare enough space before calling dllStr
  pSingle : ^single;
  sNum : single;
  pString : PChar;
  strNum : string;
  dllMessage('begin dllStr()');
  pSingle := p;
  sNum := pSingle^;
  dllMessage('str in: '+FloatToStr(sNum));
  pString := p;
  dllMessage('str out: '+strNum);
  dllMessage('end dllStr()');

function dllVal(p:pointer):integer; cdecl;
 // p should point to  and dllVal puts there 4-byte Single
 // dllVal also returns error code
  pString : PChar;
  valCode : integer;
  sNum : single;
  pSingle : ^single;
  dllMessage('begin dllVal()');
  pString := p;
  dllMessage('val in: '+pString);
  dllVal := valCode;
  if valCode=0 then begin
   dllMessage('val out: '+FloatToStr(sNum));
   pSingle := p;
   pSingle^ := sNum;
  end else dllMessage('chyba pri prevodu '+pString);
  dllMessage('end dllVal()');

procedure dllShow(p:pointer); cdecl;
 // p should point to 4-byte Single and dllShow shows number in messagebox
  pNum : ^single;
  sNum : single;
  dllMessage('begin dllShow()');
  pNum := p;
  sNum := pNum^;
  dllMessage('end dllShow()');

procedure dllSetDebug(iSet:integer); cdecl;
  dllShowMessages := iSet;

function dllGetDebug:integer; cdecl;
  dllGetDebug := dllShowMessages;

 dllStr index 1,
 dllVal index 2,
 dllShow index 3,
 dllSetDebug index 4,
 dllGetDebug index 5;

 dllShowMessages := 0;  // initially don't show debugging messages

------ VFP source "dllFox.prg" ------

** jakub.kasse@seznam.cz
** delphi dll

dllFile = "d:\jakub\delphi\dll\dllProject.dll"
declare dllStr in (dllFile) string
declare integer dllVal in (dllFile) string
declare dllShow in (dllFile) string
declare dllSetDebug in (dllFile) integer
declare integer dllGetDebug in (dllFile)

local cString, nError
cString = "1.256e30" + ; && number we want to store in 4 bytes
        + chr(0) + ;     && zero-end for delphi PChar
        + space(50)      && and some space at the end, because I need it for dllStr
MessageBox(cString,"leaving VFP...")
nError = dllVal(@cString)
if nError#0 then
 MessageBox("error at position: "+ltrim(str(nError)),"...delphi returned error")
 && now we have single variable stored in first four bytes of cString
MessageBox(cString,"...back in VFP")
clear dlls

------ end of example ------

RE: Calling external DLL made in Delphi

Sorry, I forgot to say that I'm using VFP 5.0 and Delphi 3.0, maybe it is important to know that.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close