下面的代码一个是静态加载DLL,一个是动态加载DLL,静态的时候一起正常,但是动态的时候程序就有些问题了,程序也不报错,但是就是运行不成功,没有达到代码的效果,帮我看看是哪错了呢?[静态代码]
procedure InstallDll(path:string;MainFormHandle,ExplorerProcessID:THandle);stdcall;external 'install.dll';
...
var h:THandle;
h:=FindProcessName;//FindProcessName是自己写的一个函数,没有问题
if h<>0 then
InstallDll(extractfilepath(paramstr(0)),self.Handle,h);
[动态代码]
Type TProc1=procedure(path:string;MainFormHandle,ExplorerProcessID:THandle);stdcall;
Var Proc1: Tproc1;
MyHandle,h:THandle;
begin
MyHandle:=LoadLibrary ('install.dll') ;
If MyHandle<= 0 then
Raise Exception.Create
( '动态链接库调用失败,错误代码是:'+Inttostr(Getlasterror))
else
@Proc1:=GetProcAddress(MyHandle,'InstallDll');
if not Assigned(Proc1) then
Raise Exception.Create('GetProcAddress调用失败,错误代码是:'+inttostr(getlasterror))
else
begin
h:=FindProcessName;
showmessage(IntToStr(h));
//if h<>0 then
Proc1(extractfilepath(paramstr(0)),self.Handle,h);
end;
Freelibrary(Myhandle); // 卸载DLL
end;
procedure InstallDll(path:string;MainFormHandle,ExplorerProcessID:THandle);stdcall;external 'install.dll';
...
var h:THandle;
h:=FindProcessName;//FindProcessName是自己写的一个函数,没有问题
if h<>0 then
InstallDll(extractfilepath(paramstr(0)),self.Handle,h);
[动态代码]
Type TProc1=procedure(path:string;MainFormHandle,ExplorerProcessID:THandle);stdcall;
Var Proc1: Tproc1;
MyHandle,h:THandle;
begin
MyHandle:=LoadLibrary ('install.dll') ;
If MyHandle<= 0 then
Raise Exception.Create
( '动态链接库调用失败,错误代码是:'+Inttostr(Getlasterror))
else
@Proc1:=GetProcAddress(MyHandle,'InstallDll');
if not Assigned(Proc1) then
Raise Exception.Create('GetProcAddress调用失败,错误代码是:'+inttostr(getlasterror))
else
begin
h:=FindProcessName;
showmessage(IntToStr(h));
//if h<>0 then
Proc1(extractfilepath(paramstr(0)),self.Handle,h);
end;
Freelibrary(Myhandle); // 卸载DLL
end;
解决方案 »
- 郁闷啊!请问bpl中能不能实现动态加载后调用其中的自定义类与函数?并且不带包编译!
- 关于异常处理的问题
- 没有人用sreport控件吗?求助
- 如何在 TcxGrid 中嵌入一个TDBedit控件??
- 如何删除一个Cookie文件?
- Delphi5开发人员指南》1087页的例子怎样用的?
- Params.ExStyle做了什么防止闪烁?
- hook求救!!
- mmboy(雨过天晴)请进来拿分!--->“急,关于报表的,无论高手低手都一律请入,分数陆续会加到600分!分数必分,决不食言!(VB转Delphi者求助!)”(little_hero)
- 请问用 QRPreview 自定义预览时怎样实现“上一页”、“下一页”?
- 这样报表用fastreport是否可以做到?
- 我用ShellExecute执行另外一个应用程序,如何知道它已执行完毕,或者。。。
我以前也遇到过这样的问题,应该是path的类型定义不恰当。
把string改成PChar类型。关于区别看帮助吧。
程序相应的地方改动一下就可以了。
在你创建DLL进,有一段警告,你没有看到吗???