先申明
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);
就不会有错。拜托,很是着急

解决方案 »

  1.   

    你已经是静态的调用了(external 'dll_delphi.dll' ),怎么后面又动态的装载一次?
      

  2.   

    试试这样:
    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);
    ....
      

  3.   

    我试过,报错说 ‘unknown directive creatzip'
     请您留下EMAIL地址,我给您发一份我的dll,请您调试一下,我的EMAIL是 [email protected]
      

  4.   

    pchar参数送的有问题

     stdcall;定义有问题
      

  5.   

    VC的DLL默认不是  stdcall;
      

  6.   

    DLL中的函数声明是?贴出来。。
      

  7.   

    如果对应c中的char*类型,在delphi中采用什么类型?
    如果对应c中的char[n]类型,在delphi中采用什么类型?
    总之一句话,如果需要的是字符串,使用什么对应好?
    我这么调用,程序能够跑起来,也能够执行dll中的函数,并生成正确的.zip文件,就是退出时有问题,即使是在没有执行createzip函数的情况下,即我只是退出,没有点击生成按纽,就报此错。
      

  8.   

    stdcall 或 cdcel external '.dll' 换一下试试
      

  9.   

    http://community.csdn.net/Expert/topic/3601/3601714.xml?temp=.8826105
      

  10.   

    如果对应c中的char*类型,在delphi中采用什么类型?
    如果对应c中的char[n]类型,在delphi中采用什么类型?
    总之一句话,如果需要的是字符串,使用什么对应好?
    我这么调用,程序能够跑起来,也能够执行dll中的函数,并生成正确的.zip文件,就是退出时有问题,即使是在没有执行createzip函数的情况下,即我只是退出,没有点击生成按纽,就报此错。C/C++    delphi
    char*    PChar
    char[n]  array of [0..n-1] of char or PChar
    需要的字符串 用PChar对应一般比较好.
      

  11.   

    我的createzip无返回值,在c中是void类型,所以不能使用function,只能用procedure,如果用function,怎么用?
      

  12.   

    1. 高度建议用cdecl试试,貌似cdecl的函数用stdcall调用完毕以后是容易出这号问题;
    2. 既然已经静态调用了,那动态调用的loadlibrary、 GetProcAddress等语句完全没有必要(事实上你的代码里它们也没起任何作用——起码不会有什么影响)
    3. 建议贴c代码的h文件上来,看看人家怎么定义的;
      

  13.   

    unit Unit1;interfaceuses
      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.
      

  14.   

    以上就是全部代码了,form上只有一个button,直接关闭form上的关闭按纽就报错。这些是我从一个大的工程中提取出来的,只要解决了这个问题,我的问题就算解决了。
    如果那位仁兄有兴趣解决,请留下EMAIL,我将相关的DLL发送给你,如果解决了,决不食言,给你加分。快快快,有加分啦!!!