可能是定义错了把,我记得wsprintf是Win32API中唯一的cdecl方式调用的,而Delphi中处理C调用方式中...的代替方法是varargs,也就是说wsprintf的声明应该是 function wsprintf(Output: PChar; Format: PChar): Integer;varargs; cdecl;你可以使用Delphi自带的Format代替
可是我使用纯api写,不能用delphi的函数
那就自己重新声明一个,反正Delphi也是生命的系统Dll的函数,你自然也能这么做。
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. 依照前面的格式而定。 你如果还有问题,可以继续说明你要输出怎样的格式。
仔细看了一下,才明白楼主的意思, c 支持变参,参数不固定的。 pascal不行,所以wsprintf才弄成这样。
重新声明: 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;
重新声明: 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开始的字符数组才是兼容的。
倒~楼上的,你这样作无意义.不管是array[1..200] of char还是array[0..199] of char对编译器而言都是一样的不过是200个char类型.和PChar指向NULL结尾无关,也与0开始毫无关系.难道我这样作就不能得到正确结论么?事实胜于雄辩
function wsprintf(Output: PChar; Format: PChar): Integer;varargs; cdecl;你可以使用Delphi自带的Format代替
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. 依照前面的格式而定。
你如果还有问题,可以继续说明你要输出怎样的格式。
c 支持变参,参数不固定的。
pascal不行,所以wsprintf才弄成这样。
delphi中的声明是
function wsprintf(Output: PChar; Format: PChar): Integer; stdcall;
只有两个参数!!!!!!!!!!
怎么用啊。大哥
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;
给我讲讲吧,难道是delphi有问题?我先给分了
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开始的字符数组才是兼容的。