delphi中关于利用动态创链接库创建组件(100)

  • 主题发起人 主题发起人 spyder
  • 开始时间 开始时间
S

spyder

Unregistered / Unconfirmed
GUEST, unregistred user!
编译通过了!可是运行时弹出了showmessage(‘11’),说明没有调用这个函数啊!!大家帮忙看看!主程序代码!unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;type TGetCaption = function:pchar; stdcall; //tshowdllform=function(father:Tpanel): boolean;stdcall; TMyPlugin=class caption:string; end; TForm1 = class(TForm) Panel1: TPanel; Button1: TButton; ComboBox1: TComboBox; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; father:tpanel; //showdllform:tshowdllform; getcaption:tgetcaption;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var dllname:string; hinst:thandle; fpointer:tfarproc; MyPlugin: TMyPlugin;begin myPlugin := TMyPlugin.Create; father:=panel1; getdir(0,dllname); dllname:=dllname+'/project1.dll'; hinst:=safeloadlibrary(dllname); if hinst>0 then try //Fpointer:=getprocaddress(hinst,'showdllform'); fpointer:=getprocaddress(hinst,'getcaption'); if (fpointer<>nil)then begin //showdllform(fpointer); getcaption:=tgetcaption(fpointer); getcaption; myPlugin.caption:=getcaption; combobox1.Items.Add(myplugin.caption); end else showmessage('11'); finally freelibrary(hinst); end else showmessage('22');end;end.DLL函数代码:library Project1;{ Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. }uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, ComCtrls;{$R *.res}function GetCaption:pchar; stdcall;begin Result:='FA506';end;function ShowDLLForm(father:Tpanel): boolean;stdcall;var aa:tedit;begin result:=true; aa:=tedit.create(nil); aa.parent:=father; aa.top:=20; aa.left:=20;end;exports GetCaption,ShowDLLForm;end.
 
这个问题是需要解决主程序怎么调用DLL,解决这个问题那里面的EDIT自然就成了。调用DLL网上也有实例。
 
调用解决了,但是DLL中封装的创建edit的代码编译时提示edit定义不明确啊!
 
帮忙看看啊!
 
后退
顶部