先申明
procedure creatzip(year:Integer; month:Integer; date: Integer;hour: Integer;
minute: Integer;second: Integer; softver:pchar;
softfilename :pchar;targertfilename :pchar);
stdcall;external 'dll_delphi.dll' ; 在buttonclick过程中调用 if libhandle = 0 then
begin
libhandle:=LoadLibrary(pchar(FPath));
if libhandle = 0 then
raise Exception.Create('相关Dll 不存在压缩失败')
else
aptr:=GetprocAddress(libhandle,'creatzip');
end; creatzip(t_year,t_mon,t_day, t_hour, t_min,t_sec ,m_softver , m_softfilename, m_targetfilename); if libhandle<>0 then
begin
try
FreeLibrary(libhandle);
except
end;
end;
问:为何我退出程序时报错--OX10212427指令引用的内存不能为“read”,我的调用有问题吗?如果我屏蔽
// creatzip(t_year,t_mon,t_day, t_hour, t_min,t_sec ,m_softver , m_softfilename, m_targetfilename);
就不会有错。拜托,很是着急
procedure creatzip(year:Integer; month:Integer; date: Integer;hour: Integer;
minute: Integer;second: Integer; softver:pchar;
softfilename :pchar;targertfilename :pchar);
stdcall;external 'dll_delphi.dll' ; 在buttonclick过程中调用 if libhandle = 0 then
begin
libhandle:=LoadLibrary(pchar(FPath));
if libhandle = 0 then
raise Exception.Create('相关Dll 不存在压缩失败')
else
aptr:=GetprocAddress(libhandle,'creatzip');
end; creatzip(t_year,t_mon,t_day, t_hour, t_min,t_sec ,m_softver , m_softfilename, m_targetfilename); if libhandle<>0 then
begin
try
FreeLibrary(libhandle);
except
end;
end;
问:为何我退出程序时报错--OX10212427指令引用的内存不能为“read”,我的调用有问题吗?如果我屏蔽
// creatzip(t_year,t_mon,t_day, t_hour, t_min,t_sec ,m_softver , m_softfilename, m_targetfilename);
就不会有错。拜托,很是着急
Type MyCreateZip = procedure creatzip(year:Integer; month:Integer; date: Integer;hour: Integer;minute: Integer;second: Integer; softver:pchar;softfilename :pchar;targertfilename :pchar);stdcall;
....
@MyCreateZip := GetprocAddress(libhandle,'creatzip');
if Assigned(TCreateZip) then
MyCreateZip(t_year,t_mon,t_day, t_hour, t_min,t_sec ,m_softver , m_softfilename, m_targetfilename);
....
请您留下EMAIL地址,我给您发一份我的dll,请您调试一下,我的EMAIL是 [email protected]
或
stdcall;定义有问题
如果对应c中的char[n]类型,在delphi中采用什么类型?
总之一句话,如果需要的是字符串,使用什么对应好?
我这么调用,程序能够跑起来,也能够执行dll中的函数,并生成正确的.zip文件,就是退出时有问题,即使是在没有执行createzip函数的情况下,即我只是退出,没有点击生成按纽,就报此错。
如果对应c中的char[n]类型,在delphi中采用什么类型?
总之一句话,如果需要的是字符串,使用什么对应好?
我这么调用,程序能够跑起来,也能够执行dll中的函数,并生成正确的.zip文件,就是退出时有问题,即使是在没有执行createzip函数的情况下,即我只是退出,没有点击生成按纽,就报此错。C/C++ delphi
char* PChar
char[n] array of [0..n-1] of char or PChar
需要的字符串 用PChar对应一般比较好.
2. 既然已经静态调用了,那动态调用的loadlibrary、 GetProcAddress等语句完全没有必要(事实上你的代码里它们也没起任何作用——起码不会有什么影响)
3. 建议贴c代码的h文件上来,看看人家怎么定义的;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;PROCEDURE creatzip(year:Integer; month:Integer; date: Integer;hour: Integer;minute: Integer;
second: Integer; softver:pchar;softfilename :pchar;targertfilename :pchar);cdecl ;
external 'dll_delphi.dll' ;
var
Form1: TForm1;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
FPath:string;
aptr: TFarproc;
libhandle: THandle;
begin
FPath:=ExtractFilePath(application.ExeName)+'dll_delphi.dll'; if libhandle = 0 then
begin
libhandle:=LoadLibrary(pchar(FPath));
end; IF libhandle <>0 THEN
BEGIN
aptr := GetprocAddress(libhandle,'creatzip'); END; if libhandle<>0 then
begin
try
FreeLibrary(libhandle);
except
end;
end;end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
close;
end;end.
如果那位仁兄有兴趣解决,请留下EMAIL,我将相关的DLL发送给你,如果解决了,决不食言,给你加分。快快快,有加分啦!!!