J
jack2004
Unregistered / Unconfirmed
GUEST, unregistred user!
分别用两种方法调用一个DLL,显式调用会出错,参数传递错误,程序如下,<br>button1:隐式调用<br>button2:显式调用<br><br>那位能指名错误呢????<br><br>调用程序如下:<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, ExtCtrls, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Image1: TImage;<br> Button1: TButton;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br> MySetImage= procedure(filenamechar;var ABitmap: Pointer); stdcall;<br><br>var<br> Form1: TForm1;<br><br> procedure SetImage(filenamechar;var ABitmap: Pointer); stdcall;external 'MYDLL';<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> B: TBitmap;<br> fffchar;<br>begin<br> B := TBitmap.Create;<br> FFF:=PChar('ABCD');<br> try<br> SetImage(FFF,Pointer(B));<br> Image1.Canvas.CopyRect(Rect(0,0,200,200),b.Canvas,Rect(0,0,200,200));<br> finally<br> B.Free;<br> end;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>var<br> B: TBitmap;<br> fffchar;<br> MyProc: Mysetimage;<br> MyHandle: THandle;<br>begin<br> B := TBitmap.Create;<br> FFF:=PChar('ABCD');<br><br> MyHandle := LoadLibrary(PChar('MYDLL.dll'));<br> try<br> if MyHandle > 0 then<br> begin<br> @MyProc := GetProcAddress(MyHandle, 'SetImage');<br> if Assigned(MyProc) then<br> begin<br> MyProc(FFF, Pointer(B));<br> Image1.Canvas.CopyRect(Rect(0, 0, 200, 200), b.Canvas, Rect(0, 0, 200, 200));<br> end;<br> end;<br> finally<br> B.Free;<br> Freelibrary(Myhandle);<br> end;<br>end;<br><br>end.<br>DLL程序如下:<br>library MYDLL;<br><br>uses<br> Graphics;<br><br>{$R *.res}<br>{$R ../skin/New.res}<br><br>procedure SetImage(ResName: PChar; var Value: Pointer);<br>begin<br> TBitmap(Value).LoadFromResourceName(Hinstance, ResName);<br>end;<br>exports<br> SetImage;<br>begin<br>end.