Hi Rob

There are infact 27 functions and procedures that the DLL calls.  Here 
is a sample

TWinampInputPlugin = record
  Version : Integer;
  Description : PChar;
  ID : Integer;
  HwndParent : THandle;
  DLLInstance : HINST;
  procedure Config(ParentWindow: THandle); cdecl;
  procedure About (ParentWindow: THandle); cdecl;
  function Write(Buf: Pointer; Len: Integer):Integer; cdecl;
  function CanWrite: Integer; cdecl;
  ....
end;

PWinAmpInputPlugin = ^TWinampInputPlugin;
TWinampInput = function: PWinAmpInputPlugin; cdecl;


// define global procedures & functions
procedure MyConfig(ParentWindow: THandle); cdecl;
etc
....

var
  WinampInput: TWinampInput;
begin
  ....
  @WinampInput := GetProcAddress(DLLHandle, 'winampGetInModule2');
  // assign pointers to my global functions
  WinampInput.Config := MyConfig;
  etc

MyConfig is then accessed when the DLL calls Config

How to do this OOP?

Many thanks,
Ross.

----- Original Message ----- 
From: "Rob Kennedy" <[EMAIL PROTECTED]>
To: "Borland's Delphi Discussion List" <[email protected]>
Sent: Wednesday, July 06, 2005 3:28 PM
Subject: Re: TMethod.Code


Ross Levis wrote:
>> It's possible to convert a method into a standalone procedure at run
>> time so the DLL could call it with all the right parameters in the
>> expected places, but it's a bit of work, so it's best avoided.
>
> It may be beneficial in my case.  The DLL definately only supports
> standard procedures and functions.  There is no user-data parameter.

OK. You'll need to tell me the signature for the function, as the DLL
expects it (the standalone procedure). Something like this:

function DLLCallbackFunction(param1: PAnsiChar; param2: Integer):
LongBool; stdcall;

> I suppose I could have an "array of procedure" and "array of function"
> and an array of TMyObject and each object instance created would 
> assign
> a sequential number as the array subscript and use this to access the
> DLL pointers etc.  Sound feesible?

The object could simply keep its own pointers to those procedures as
fields. No need to introduce global arrays.

As it is, the code I'm going to give you will require the same thing.
You'll call a function, which will take a method pointer from the object
and return a regular procedure pointer, which the DLL can call. Each
instance of your class will need to call my function-generating 
function,
and when an object gets freed, it will need to call a corresponding
function-destroying function.

-- 
Rob


_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to