[DUG] DLL's

Ross Levis ross at stationplaylist.com
Sat Jul 2 12:58:08 NZST 2005


I have a DLL which defines a structure for passing information 2 ways.
I need to define some functions and procedures that will be called from a 3rd party DLL that I'm loading.  I've successfully loaded the DLL and can call the functions & procedures in the DLL, but I'm not sure how to set up the reverse situation where the DLL requests information from my program.

Here is an example DLL structure and what I've done so far.

type
  PSomeDLL = ^TSomeDLL;
  TSomeDLL = record
    Init : procedure; cdecl;
    Quit : procedure; cdecl;
    GetNumber : function(FileName:PChar):Integer; cdecl;
  end;

  TDLLStruct = function: PSomeDLL; cdecl;
....
var
  DLLStruct: TDLLStruct;  
begin
  @DLLStruct := GetProcAddress(...
  DLLStruct.Init;
  ...

This is working and I can successfully call DLLStruct.Init and DLLStruct.Quit from my program, but GetNumber is actually called by the DLL, so I need to supply the result of the function.  How do I go about that?

I thought I would have to do something like this:

type
  TGenNumber = function(FileName:PChar):Integer; cdecl;

var
  GetGenNumber: TGenNumber;
...
GetGenNumber := DLLStruct.GetNumber;
...
function GetGenNumber(FileName:PChar):Integer;
  Result := 1; // something
end;

This compiles but the function GetGenNumber above is not compiled into my executable because it doesn't think it's being called.  It isn't being called within my program, the DLL will be calling it, but the compiler doesn't know that.  What as I missing?

Thanks,
Ross.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ns3.123.co.nz/pipermail/delphi/attachments/20050702/842a7517/attachment.html


More information about the Delphi mailing list