怎样设计DLL,使得此DLL能被C++、PB或其他各种Windows中能用的程序调用要达到这个要求,
1、如何在设计DLL时以何种类型,何种方式进行参数传递和返回
2、同时在函数中怎样使用Delphi中已有的函数
3、主要是字符串的操作、传递和返回如下函数:
function myString(pInString,pOutString:PChar):Integer;stdcall;
begin
  StrCopy(pOutString,pInString);
//  ShowmessageFMT('%X %X',[Longint(pInstring),Longint(poutstring)]);
  StrCat(pOutString,PChar('What Can I Help You(我能帮你什么忙吗?)'));
  result:=Length(pOutString);
end;
在Delphi编译的程序中能正确执行
字串结果是:pInString+'What Can I Help You(我能帮你什么忙吗?)'
在PB编译的程序中不能正确执行
字串结果是:什么也没有何故?请各位大姐小姐大哥小哥告知如何操作或到什么地方查相关的资料?此小类中的有关DLL的最新的贴子我都已经看过了,但还是没有解决问题,
特来请大家帮忙,先谢谢了。

解决方案 »

  1.   

    如果是传出字符,张须是传一个符合WINDOWS的指针,而不是OBJECT PASCAL的STRING或简单的CHAR
      

  2.   

    pb中是如下声明的,
    function integer myString(string pInString,pOutString) libary 'm.dll'
      

  3.   

    ?是否是因为pOutString的空间长度问题?
    strcopy strcat都不会进行长度检查
      

  4.   

    TO:firetoucher(风焱) 
    如果不考虑pOutString的空间长度,
    mystring函数就您看来是否在Windows中"通用"?
      

  5.   

    设计成标准DLL,而且变量必须是标准的。如下面一段:为DELPHI的动态库的声明:
    function AutoFile(AHandle: THandle; IsWin,IPAddr,UserNM,PassWD,FileNM:AnsiString):Longint;StdCall;
    exports
      AutoFile;
    其中:
    THandle类型相当于VB的LONG,在VB中用this变量。
    AnsiString类型相当于VB的string。
    VB的引用为:
    Public Declare Function AutoFile Lib "E:\CalendarLib.dll" (ByVal AHandle As Long, ByVal IsWin As String, ByVal IPAddr As String, ByVal UserNM As String, ByVal PassWD As String, ByVal FileNM As String) As Long ', ByVal Proxy As String, ByVal ProxyPort As String--我是花了很多心血得出结论。
      

  6.   

    只要stdcall
    还有就是不能有string 这些东西,要用pchar
      

  7.   

    function myString(pInString:string;var 'pOutString:PChar):Integer;stdcall;
    begin
      StrCopy(pOutString,pInString);
    //  ShowmessageFMT('%X %X',[Longint(pInstring),Longint(poutstring)]);
      StrCat(pOutString,PChar('What Can I Help You(我能帮你什么忙吗?)'));
      result:=Length(pOutString);
    end;
      

  8.   

    针对如下函数,本人结贴结果如下:该函数基本上能适应所有的程序调用,
    但必须在调用程序中定义传出字串变量,同时给此变量分配存储空间,
    因为定义变量时,此变量没有实际的存储空间。另外传出字串变量在调用程序
    中应定义成传地址调用而不是值调用。
    DLL中的函数:
    function myString(pInString,pOutString:PChar):Integer;stdcall;
    begin
      StrCopy(pOutString,pInString);
    //  ShowmessageFMT('%X %X',[Longint(pInstring),Longint(poutstring)]);
      StrCat(pOutString,PChar('What Can I Help You(我能帮你什么忙吗?)'));
      result:=Length(pOutString);
    end;
    [Delphi]中定义(调用程序)
        function myString(pInString,pOutString:PChar):Integer;stdcall;external 'm.dll'
     使用:
     var vs:String;
     begin
       setlength(vs,200); // 200仅为示例,意为必须保证空间足够
       myString(PChar('Hello,测试字串',PChar(vs));
     end;
    [PowerBuild]中定义(调用程序)
       String vS
       integer vI
       vS = space(200)    // 200仅为示例,意为必须保证空间足够
       vI = myString('Hello,测试字串',vS)
       同时在定义函数原型时应如下定义:
            function Integer myString(string pString,ref string pOutString) library 'm.dll'
       就是说要传出的字串变量必须定义成传址调用(ref)修饰符
      

  9.   

    有什么好的想法或意见,请与我交流
    email:  [email protected]