[DUG] call a method function from outside object

Ross Levis ross at stationplaylist.com
Mon Jul 11 23:50:43 NZST 2005


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 
  To: NZ Borland Developers Group - Delphi List 
  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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ns3.123.co.nz/pipermail/delphi/attachments/20050711/ae18116d/attachment.html


More information about the Delphi mailing list