显式调用一个DLL,返回一个图片,如何做? ( 积分: 50 )

  • 主题发起人 主题发起人 jack2004
  • 开始时间 开始时间
J

jack2004

Unregistered / Unconfirmed
GUEST, unregistred user!
那位能提供演示代码?谢谢了!!!
 
//Dll&nbsp;部分<br>library&nbsp;Project4;<br><br>uses<br>&nbsp;&nbsp;Graphics;<br><br>{$R&nbsp;*.res}<br><br>procedure&nbsp;SetImage(var&nbsp;ABitmap:&nbsp;Pointer);<br>begin<br>&nbsp;&nbsp;TBitmap(ABitmap).LoadFromFile('c:/1.bmp');<br>end;<br><br>exports<br>&nbsp;&nbsp;SetImage;<br><br>begin<br>end.<br><br>//调用部分<br>unit&nbsp;Unit3;<br><br>interface<br><br>uses<br>&nbsp;&nbsp;Windows,&nbsp;Messages,&nbsp;SysUtils,&nbsp;Variants,&nbsp;Classes,&nbsp;Graphics,&nbsp;Controls,&nbsp;Forms,<br>&nbsp;&nbsp;Dialogs,&nbsp;StdCtrls,&nbsp;ExtCtrls;<br><br>type<br>&nbsp;&nbsp;TForm1&nbsp;=&nbsp;class(TForm)<br>&nbsp;&nbsp;&nbsp;&nbsp;Button1:&nbsp;TButton;<br>&nbsp;&nbsp;&nbsp;&nbsp;Image1:&nbsp;TImage;<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;Button1Click(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;private<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Private&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;public<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Public&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;end;<br><br>var<br>&nbsp;&nbsp;Form1:&nbsp;TForm1;<br><br>procedure&nbsp;SetImage(var&nbsp;ABitmap:&nbsp;Pointer);&nbsp;stdcall;external&nbsp;'Project4.dll';<br><br>implementation<br><br>{$R&nbsp;*.dfm}<br><br>procedure&nbsp;TForm1.Button1Click(Sender:&nbsp;TObject);<br>var<br>&nbsp;&nbsp;B:&nbsp;TBitmap;<br>begin<br>&nbsp;&nbsp;B&nbsp;:=&nbsp;TBitmap.Create;<br>&nbsp;&nbsp;try<br>&nbsp;&nbsp;&nbsp;&nbsp;SetImage(Pointer(B));<br>&nbsp;&nbsp;&nbsp;&nbsp;Image1.Canvas.CopyRect(Rect(0,0,100,100),b.Canvas,Rect(0,0,100,100));<br>&nbsp;&nbsp;finally<br>&nbsp;&nbsp;&nbsp;&nbsp;B.Free;<br>&nbsp;&nbsp;end;<br>end;<br><br>end.
 
一个字都不错的打上去了,不行啊
 
楼主不是真的打字进去吧?复制、粘贴就可以啦。<br>上面的代码在我这里很正常,楼主再检查一下。<br>如果还不行,留下&nbsp;EMail,我把我的&nbsp;Demo&nbsp;发给你吧。
 
谢谢,请发到<br>jackshi618@sina.com
 
Demo&nbsp;已经发出。
 
谢谢楼上!问题已查明,我只是去掉了Try,就出错了!真是奇怪!!望解答
 
接受答案了.
 
后退
顶部