api中声明3个参数,delphi中却成了两个,怎么用拉

解决方案 »

  1.   

    可能是定义错了把,我记得wsprintf是Win32API中唯一的cdecl方式调用的,而Delphi中处理C调用方式中...的代替方法是varargs,也就是说wsprintf的声明应该是
    function wsprintf(Output: PChar; Format: PChar): Integer;varargs; cdecl;你可以使用Delphi自带的Format代替
      

  2.   

    可是我使用纯api写,不能用delphi的函数
      

  3.   

    那就自己重新声明一个,反正Delphi也是生命的系统Dll的函数,你自然也能这么做。
      

  4.   

    int wsprintf(    LPTSTR lpOut, // pointer to buffer for output 
        LPCTSTR lpFmt,  // pointer to format-control string 
        ... // optional arguments
       );
    这是从Win32 SDK中节选的,第三个可以Pass掉。
    最后一个可选参数的定义是:Specifies one or more optional arguments. The number and type of argument parameters depend on the corresponding format-control specifications in the lpFmt parameter. 依照前面的格式而定。
    你如果还有问题,可以继续说明你要输出怎样的格式。
      

  5.   

    仔细看了一下,才明白楼主的意思,
    c 支持变参,参数不固定的。
    pascal不行,所以wsprintf才弄成这样。
      

  6.   

    第三个可以Pass掉???大哥,我不太懂什么意思?
    delphi中的声明是
    function wsprintf(Output: PChar; Format: PChar): Integer; stdcall;
    只有两个参数!!!!!!!!!!
    怎么用啊。大哥
      

  7.   

    重新声明:
    function wsprintf(Output: PChar; Format: PChar): Integer;varargs; cdecl; external user32 name 'wsprintfA';演示代码:
    var Buffer:array[1..200] of char;
    begin
      wsprintf(@Buffer,'1 KByte is %xBytes',1024);
     ShowMessage(Strpas(@Buffer));
    end;
      

  8.   

    注意,看我添加的varargs,你若仔细看我回的第一个帖子就不会耽误这么长时间了.
      

  9.   

    行了,谢谢你。大哥,可是我不懂那是什么意思?varargs; cdecl; ?
    给我讲讲吧,难道是delphi有问题?我先给分了
      

  10.   

    varargs关键字是为了兼容c风格调用(cdecl)的"..."方式的,varargs也只能和cdecl一起使用,由于cdecl是调用者清楚堆栈,所以可以运行时实现可变参数传递(不知道这么说是否正确,反正你知道那个意思就行).而由于wsprintf的第三个参数是...,根据调用约定规范只能使用cdecl,所以这也是为什么wsprintf是Win32 APi中唯一一个cdecl的函数,Delphi的Windows.pas中的定义肯定错了.看Delphi帮助吧,找关键字varargs
      

  11.   

    重新声明:
    function wsprintf(Output: PChar; Format: PChar): Integer;varargs; cdecl; external user32 name 'wsprintfA';演示代码:
    var Buffer:array[1..200] of char;  *************************************
    begin
      wsprintf(@Buffer,'1 KByte is %xBytes',1024);
     ShowMessage(Strpas(@Buffer));
    end;
    对于Eastunfail(龙子龙孙)==(恶鱼杀手)给的代码标记处请改为:
    var Buffer : array[0..199] of char;因为PChar是指向以NULL结尾的字符串,而这种字符串与以0开始的字符数组才是兼容的。
      

  12.   

    倒~楼上的,你这样作无意义.不管是array[1..200] of char还是array[0..199] of char对编译器而言都是一样的不过是200个char类型.和PChar指向NULL结尾无关,也与0开始毫无关系.难道我这样作就不能得到正确结论么?事实胜于雄辩