use*_*348 4 delphi winapi filesize delphi-10.4-sydney
在 Delphi 10.4 中,当尝试使用Winapi.ShLwApi.StrFormatByteSize64将Int64文件大小值转换为格式化字符串时,出现运行时错误:
var
ThisSize: Int64;
pszBuf: PWideChar;
cchBuf: Cardinal;
Winapi.ShLwApi.StrFormatByteSize64(ThisSize, pszBuf, cchBuf);
Run Code Online (Sandbox Code Playgroud)
错误信息:
--------------------------- MyApp.exe - 未找到入口点
--------------- ------------ 在 DLL "C:\DELPHI\MyApp\Win32\Debug\MyApp.exe" 中找不到过程入口点 "StrFormatByteSize64W"。
- - - - - - - - - - - - - - 好的
如何解决这个问题呢?
StrFormatByteSize64 可用于 ANSI 或 Unicode 字符。但是,虽然可以直接调用 StrFormatByteSize64A,但未定义 StrFormatByteSize64W。当使用 Unicode 值调用 StrFormatByteSize64 时,将使用 StrFormatByteSizeW。
Delphi 导入声明为:
function StrFormatByteSize64; external shlwapi32 name 'StrFormatByteSize64W';
Run Code Online (Sandbox Code Playgroud)
换句话说,这是 Delphi RTL 中的一个翻译错误。StrFormatByteSize64W中不存在该函数shlwapi.dll。
正如文档所说,请StrFormatByteSize改为调用。这是由 Windows 头文件为您处理的,但 Embarcadero 在翻译它们时没有发现这种细微差别。
该程序演示:
{$APPTYPE CONSOLE}
uses
System.SysUtils,
Winapi.ShLwApi;
procedure Main;
var
ThisSize: Int64;
szBuf: array[0..255] of Char;
cchBuf: Cardinal;
begin
ThisSize := Int64(1024)*1024*1024*256;
cchBuf := Length(szBuf);
Winapi.ShLwApi.StrFormatByteSize(ThisSize, szBuf, cchBuf);
Writeln(szBuf);
end;
begin
try
Main;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.
Run Code Online (Sandbox Code Playgroud)
输出:
256 GB
我已将此报告给 Embarcadero:https : //quality.embarcadero.com/browse/RSP-29943
| 归档时间: |
|
| 查看次数: |
120 次 |
| 最近记录: |