<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
It is certainly an interesting method of bypass and rerouting a method.
Reminds me of heart surgery triple bypass performed by an icing chef ;)<br>
<br>
Ross Levis wrote:
<blockquote cite="mid013601c5860e$c4bc8340$5100a8c0@levis4" type="cite">
  <title></title>
  <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
  <meta content="MSHTML 6.00.2900.2668" name="GENERATOR">
  <style></style>
  <div><font face="Arial" size="2">I just noticed a bug&nbsp;which I'll
await Rob to fix it.&nbsp; The Result value of any functions being called is
not being returned to the caller (DLL).&nbsp; Perhaps this is&nbsp;due to the
parameters being shifted one position.</font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">Ross.</font></div>
  <blockquote
 style="border-left: 2px solid rgb(0, 0, 0); padding-right: 0px; padding-left: 5px; margin-left: 5px; margin-right: 0px;"
 dir="ltr">
    <div
 style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">-----
Original Message ----- </div>
    <div
 style="background: rgb(228, 228, 228) none repeat scroll 0%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>From:</b>
    <a title="ross@stationplaylist.com"
 href="mailto:ross@stationplaylist.com">Ross Levis</a> </div>
    <div
 style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>To:</b>
    <a title="delphi@ns3.123.co.nz" href="mailto:delphi@ns3.123.co.nz">NZ
Borland Developers Group - Delphi List</a> </div>
    <div
 style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>Sent:</b>
Monday, July 11, 2005 11:31 PM</div>
    <div
 style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>Subject:</b>
Re: [DUG] call a method function from outside object</div>
    <div><br>
    </div>
    <div><font face="Arial" size="2">It's attached.&nbsp; Below are Rob's
instructions for use.&nbsp; I found I had to add a dummy parameter in the
method declarations otherwise the parameter values were shifted one to
the right.</font></div>
    <div>&nbsp;</div>
    <div>To use it, start by declaring data types for your function and
method <br>
pointers:<br>
    <br>
type<br>
&nbsp;&nbsp; TConfigFunction = procedure(ParentWindow: HWnd); cdecl;<br>
&nbsp;&nbsp; TConfigMethod = procedure(ParentWindow: HWnd) of object; stdcall;<br>
    <br>
&nbsp;&nbsp; TCanWriteFunction = function: Integer; cdecl;<br>
&nbsp;&nbsp; TCanWriteMethod = function: Integer of object; stdcall;<br>
    <br>
The calling conventions differ on purpose. It just makes things a lot <br>
easier that way.<br>
    <br>
When you instantiate your object, call my MakeCdeclInstance function to
    <br>
create a wrapper for your method.<br>
    <br>
type<br>
&nbsp;&nbsp; TWinampPlugIn = class<br>
&nbsp;&nbsp; private<br>
&nbsp;&nbsp;&nbsp;&nbsp; FConfig: TConfigFunction;<br>
&nbsp;&nbsp;&nbsp;&nbsp; FCanWrite: TCanWriteFunction;<br>
&nbsp;&nbsp;&nbsp;&nbsp; procedure Config(ParentWindow: HWnd); stdcall;<br>
&nbsp;&nbsp;&nbsp;&nbsp; function CanWrite: Integer; stdcall;<br>
&nbsp;&nbsp; public<br>
&nbsp;&nbsp;&nbsp;&nbsp; constructor Create;<br>
&nbsp;&nbsp;&nbsp;&nbsp; destructor Destroy; override;<br>
&nbsp;&nbsp; end;<br>
    <br>
constructor TWinampPlugIn.Create;<br>
var<br>
&nbsp;&nbsp; Method: TMethod;<br>
&nbsp;&nbsp; ConfigMethod: TConfigMethod;<br>
&nbsp;&nbsp; CanWriteMethod: TCanWriteMethod;<br>
begin<br>
&nbsp;&nbsp; inherited;<br>
&nbsp;&nbsp; ConfigMethod := Config;<br>
&nbsp;&nbsp; Method := TMethod(ConfigMethod);<br>
&nbsp;&nbsp; FConfig := MakeCdeclInstance(Method, SizeOf(HWnd));<br>
&nbsp;&nbsp; CanWriteMethod := CanWrite;<br>
&nbsp;&nbsp; Method := TMethod(CanWriteMethod);<br>
&nbsp;&nbsp; FCanWrite := MakeCdeclInstance(Method, 0);<br>
end;<br>
    <br>
destructor TWinampPlugIn.Destroy;<br>
begin<br>
&nbsp;&nbsp; FreeCdeclInstance(@FCanWrite);<br>
&nbsp;&nbsp; FreeCdeclInstance(@FConfig);<br>
&nbsp;&nbsp; inherited;<br>
end;<br>
    <br>
After that, FConfig and FCanWrite are regular standalone-function <br>
pointers. When you or the DLL call them, though, they will call the <br>
corresponding method on a specific instance of the TWinampPlugIn class.</div>
  </blockquote>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
Delphi mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</a>
<a class="moz-txt-link-freetext" href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</a>
  </pre>
</blockquote>
</body>
</html>