大家帮忙看一下啊,在下不胜感激啊
源码:
Function func_test(Var InStr,InBz,OutStr:ShortString):ShortString;
type  Lfunc1=Function (Var _InStr, _InBz , _OutStr:ShortString):ShortString;stdcall;
Var
  Lib1:Thandle;
  Lsfunc1 : Lfunc1;
begin
  Lib1 := Loadlibrary('test.dll');
  If Lib1 >= 32 then
  begin
    try
      @Lsfunc1 :=GetProcAddress(Lib1 ,'_DataDown_sp@12');
      if @Lsfunc1 <> nil then
        Result := Lsfunc1(InStr,InBz,OutStr)
      Else
        Result := '动态链接库加载错误';
    finally
      FreeLibrary(Lib1);
    end;
  end
  Else
  Begin
    Result := '动态链接库加载错误';
  End;
End;不知道哪儿错了,执行时总提示地址出错

解决方案 »

  1.   

    我只用delphi 写过dll 给 pb调用
    反过来的没有试过,试下:
    检查:@Lsfunc1 :=GetProcAddress(Lib1 ,'_DataDown_sp@12');
    这句能 get 到吗?ShortString
    改为
    pchar
      

  2.   

    Function func_test(InStr,InBz,OutStr: PCHAR): PCHAR;
    type Lfunc1 = Function (_InStr, _InBz , _OutStr: PCHAR): PCHAR; stdcall;
    Var
      Lib1: Thandle;
      Lsfunc1: Lfunc1;
    begin
     Lib1 := Loadlibrary('test.dll');
      If Lib1 >= 32 then
      begin
        try
          @Lsfunc1 :=GetProcAddress(Lib1 ,'_DataDown_sp@12'); //函数名字区分大小写
          if @Lsfunc1 <> nil then
            Result := Lsfunc1(InStr,InBz,OutStr) //这三个参数中,如果在PB中更改,必须定义变量并StrAlloc分配空间,别忘了释放空间
          Else
            Result := '动态链接库加载错误';
        finally
          FreeLibrary(Lib1);
        end;
      end
      Else
      Begin
        Result := '动态链接库加载错误';
      End;
    End;