如何在Delphi中调用DLL中的函数

解决方案 »

  1.   

    比如:
    library dll_fmd;{ 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. }uses
      SysUtils,
      Classes;{$R *.res}
    function EncryStr(Str: String): String;begin
     str:='dfsd';end;
    begin
    end.
    怎么调用变量str 
    在程序里通过showmessage(str); 得出str的内容
      

  2.   

    先申明,例如,function test(i: Integer): Integer; stdcall; external 'YourDllName' name 'Yourfunname';
      

  3.   

    你的str是传入的还是传出的,若是传出的参数,试试function EncryStr(var Str: String): String;这样对于str在你的函数里赋值,并通过参数返回.不过建议你用函数的返回值返回
    Result:=str;
    在你的函数后面写 Exports EncryStr name 'EncryStr';
      

  4.   

    library dll_fmd;{ 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. }uses
      SysUtils,
      Classes;{$R *.res}
    function EncryStr(Str: String): String;begin
     str:='dfsd';
    end;//---------------
    exports
    EncryStr;
    //----------------begin
    end.
      

  5.   

    上面写的有点不对,DLL工程中的函数也要加上stdcall
    function EncryStr(Str: String): String;stdcall;
    调用前先声明
    function function EncryStr(Str: String): String;stdcall;external 'XXX.dll';
      

  6.   

    如果你使用的字符不超过255 个,就使用短字符串(shortString),这样发布时
    就不用附带BorlandMM.dll
      

  7.   

    声明一下,
    function EncryStr(Str: String):String;stdcall;external 'dll_fmd' name 'EncryStr';
    如果DLL是DELPHI写的话,stdcall删掉。DLL里不要用string这种类型,用其他类型代替。