It is certainly an interesting method of bypass and rerouting a method. Reminds me of heart surgery triple bypass performed by an icing chef ;)

Ross Levis wrote:
I just noticed a bug which I'll await Rob to fix it.  The Result value of any functions being called is not being returned to the caller (DLL).  Perhaps this is due to the parameters being shifted one position.
 
Ross.
----- Original Message -----
From: Ross Levis
Sent: Monday, July 11, 2005 11:31 PM
Subject: Re: [DUG] call a method function from outside object

It's attached.  Below are Rob's instructions for use.  I found I had to add a dummy parameter in the method declarations otherwise the parameter values were shifted one to the right.
 
To use it, start by declaring data types for your function and method
pointers:

type
   TConfigFunction = procedure(ParentWindow: HWnd); cdecl;
   TConfigMethod = procedure(ParentWindow: HWnd) of object; stdcall;

   TCanWriteFunction = function: Integer; cdecl;
   TCanWriteMethod = function: Integer of object; stdcall;

The calling conventions differ on purpose. It just makes things a lot
easier that way.

When you instantiate your object, call my MakeCdeclInstance function to
create a wrapper for your method.

type
   TWinampPlugIn = class
   private
     FConfig: TConfigFunction;
     FCanWrite: TCanWriteFunction;
     procedure Config(ParentWindow: HWnd); stdcall;
     function CanWrite: Integer; stdcall;
   public
     constructor Create;
     destructor Destroy; override;
   end;

constructor TWinampPlugIn.Create;
var
   Method: TMethod;
   ConfigMethod: TConfigMethod;
   CanWriteMethod: TCanWriteMethod;
begin
   inherited;
   ConfigMethod := Config;
   Method := TMethod(ConfigMethod);
   FConfig := MakeCdeclInstance(Method, SizeOf(HWnd));
   CanWriteMethod := CanWrite;
   Method := TMethod(CanWriteMethod);
   FCanWrite := MakeCdeclInstance(Method, 0);
end;

destructor TWinampPlugIn.Destroy;
begin
   FreeCdeclInstance(@FCanWrite);
   FreeCdeclInstance(@FConfig);
   inherited;
end;

After that, FConfig and FCanWrite are regular standalone-function
pointers. When you or the DLL call them, though, they will call the
corresponding method on a specific instance of the TWinampPlugIn class.

_______________________________________________ Delphi mailing list [email protected] http://ns3.123.co.nz/mailman/listinfo/delphi


_______________________________________________
Delphi mailing list
[email protected]
http://ns3.123.co.nz/mailman/listinfo/delphi

Reply via email to