// 功能:单击按钮后,edit2中显示edit1中字符串的md5编码。// 当前目录中 md5.dll 文件存在,编译成功。procedure TForm1.Button1Click(Sender: TObject);
type
DLL_TFMD5=procedure(var S: String);
var
DLLInstance: THandle;
MD5: DLL_TFMD5;
var
temp: string;
begin
DLLInstance:=LoadLibrary('md5.dll'); if DLLInstance=0 then
begin
MessageBox(Self.Handle,'Can not load DLL file(s).','Error',MB_OK+MB_ICONERROR);
exit;
end; @MD5:=GetProcAddress(DLLInstance,'FMD5'); MD5(temp); // 这句注释后就不出错。 Edit2.Text:=temp; FreeLibrary(DLLInstance);
end;是我dll文件的问题,还是上边调用的问题。敬请帮忙改成。
type
DLL_TFMD5=procedure(var S: String);
var
DLLInstance: THandle;
MD5: DLL_TFMD5;
var
temp: string;
begin
DLLInstance:=LoadLibrary('md5.dll'); if DLLInstance=0 then
begin
MessageBox(Self.Handle,'Can not load DLL file(s).','Error',MB_OK+MB_ICONERROR);
exit;
end; @MD5:=GetProcAddress(DLLInstance,'FMD5'); MD5(temp); // 这句注释后就不出错。 Edit2.Text:=temp; FreeLibrary(DLLInstance);
end;是我dll文件的问题,还是上边调用的问题。敬请帮忙改成。
解决方案 »
- 有关Delphi调用C#编写的WebService问题
- 学习、交流ERP/MRP经验群 (16301324)
- eXescop 打开了 魔兽世界的启动文件 Launcher.exe
- 一个关于窗体创建的小问题,我想了好久,高手请帮忙
- 请问cxGrid怎么导出到Excel表呀
- 我的窗体怎么不能拖动了?
- 怎样使得TQRPreview和TQuickRep关联?
- 谁可以告诉我:CAST属于什么类?怎么定义?老鱼,你怎么说点就走?老千也是!!!
- 为何说我的变量没有初始化?(Variable 'qryTemp' might not have been initialized)
- 请问 TStrings 怎么用?
- window下sql 7.0里的数据向linux下的my sql的库里倒入,请各位帮忙---在线等
- 专家求助,ocx发布!
下面是個例子.
function RunDephiDll (pForm:TForm) :TForm; stdcall;
可能你的定義應該是這樣的.
DLL_TFMD5=procedure(var S: String); stdcall;另外你下面的語句寫成這樣試試:
@MD5:=GetProcAddress(DLLInstance,'FMD5');
->
MD5:=DLL_TFMD5(GetProcAddress(DLLInstance,'FMD5'));
MD5:=GetProcAddress(DLLInstance,'FMD5');
关键是DLL_TFMD5=procedure(var S: String); stdcall;
不然就这样吧DLL_TFMD5=procedure(var S: pchar);
2.dll中使用function可能吗?
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. }
如果為String,請注意大小寫
MD5(temp); 有问题
是它的前一句。@MD5:=GetProcAddress(DLLInstance,'FMD5');
你看看返回的是不是Nil
按钮click事件中调用成功,但在退出程序时,出现"Invalid pointer operation"异常。
2.使用动态调用
当按钮click事件中一调用完dll中的函数后,就出现"Invalid pointer operation"异常。
why?
{ 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. }
你有没有看呢,还有你的是不是标准调用,另外@MD5是不是nil,
GetProcAddress(DLLInstance,'FMD5');//里面的函数是区分大小写的
2.@md5不是nil. 3.已经注意了区分大小写。 可是,问题还是出现了。Why?