// 功能:单击按钮后,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文件的问题,还是上边调用的问题。敬请帮忙改成。

解决方案 »

  1.   

    首先你的dll中可能有問題.一般函數類型是的
    下面是個例子.
    function RunDephiDll (pForm:TForm) :TForm; stdcall;
    可能你的定義應該是這樣的.
    DLL_TFMD5=procedure(var S: String); stdcall;另外你下面的語句寫成這樣試試:
    @MD5:=GetProcAddress(DLLInstance,'FMD5');
    ->
    MD5:=DLL_TFMD5(GetProcAddress(DLLInstance,'FMD5'));
      

  2.   

    TFMD5=procedure(var S: String); stdcall;
    MD5:=GetProcAddress(DLLInstance,'FMD5');
      

  3.   

    up 
    关键是DLL_TFMD5=procedure(var S: String); stdcall;
      

  4.   

    加sharemem单元了么,可不要说你没加阿
    不然就这样吧DLL_TFMD5=procedure(var S: pchar);
      

  5.   

    几个小问题:1.dll中可以使用对象吗?
    2.dll中使用function可能吗?
      

  6.   

    DLL_TFMD5=procedure(var S: String);加sharemem单元了{ 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. }
      

  7.   

    那了闷了,我在dll里只有一个函数,它返回个int型数据,编译成功。在exe里有调用。就这么简单个事就是出错:当点击按钮时调用成功(我把返回结果放在edit1.text里,成功显示了),然后跳出个错误,f9继续,这时程序不能运行,但当我关闭窗口时(点击右上角X),又出错,f9继续,跳出个"runtime error 217"错误。请帮助解释一下,谢谢。
      

  8.   

    可能有你DLL中的函數或過程變量的某個類型不匹配
    如果為String,請注意大小寫
      

  9.   

    dll中的函數名字和你程式中應用的名字必須一樣
      

  10.   

    我想关键不是
    MD5(temp);  有问题
    是它的前一句。@MD5:=GetProcAddress(DLLInstance,'FMD5');
    你看看返回的是不是Nil
      

  11.   

    1.使用静态调用
      按钮click事件中调用成功,但在退出程序时,出现"Invalid pointer operation"异常。
    2.使用动态调用
      当按钮click事件中一调用完dll中的函数后,就出现"Invalid pointer operation"异常。
    why?
      

  12.   

    跟你说了,用string类型要uses ShareMem;
    { 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');//里面的函数是区分大小写的
      

  13.   

    楼上的哥哥,如果GetProcAddress(DLLInstance,'FMD5')返回的是Nil 那么和你说的use ShareMem还有关系吗?用WideString会和他有关系吗?
      

  14.   

    To:ljmanage(过客)   首先,谢谢你的留言,帮助。    1.dll和exe中都已经使用了sharemem.
     
        2.@md5不是nil.    3.已经注意了区分大小写。  可是,问题还是出现了。Why?
      

  15.   

    感谢 abue(阿布) 朋友!信已经收到,现在我正在修改我的程序。