CnPack Forum


 
Subject: CnCommon单元SearchPath函数的参数有问题?
yinsim
新警察
Rank: 1



UID 50783
Digest Posts 0
Credits 48
Posts 16
点点分 48
Reading Access 10
Registered 2010-8-17
Status Offline
Post at 2010-8-18 10:30  Profile | Blog | P.M. 
CnCommon单元SearchPath函数的参数有问题?



// 调用 SearchFile 在当前目录、系统目录和 PATH 变量中查找指定扩展名的文件。
// FileName 为不带扩展名的文件名,Ext 为扩展名,成功返回全路径文件名,失败返回空。
function CnSearchFile(const FileName: string; const Ext: string = '.exe'): string;
var
  fn: array[0..MAX_PATH] of Char;
  pc: PChar;
begin
  if SearchPath(nil, PChar(FileName), PChar(Ext), SizeOf(fn), fn, pc) <> 0 then
    Result := fn;
end;



DWORD SearchPath(
  LPCTSTR lpPath,
  LPCTSTR lpFileName,
  LPCTSTR lpExtension,
  DWORD nBufferLength,
  LPTSTR lpBuffer,
  LPTSTR* lpFilePart
);

nBufferLength
[in] The size of the buffer that receives the valid path and file name, in TCHARs.

SearchPath的最四个参数是缓冲区大小,CnCommon单元使用的是SizeOf()函数,而个人觉得取字符数组的长度应该用Length().
在Delphi2010 的Unicode 环境下,使用CnCommon的CnSearchFile会引起内存非法访问,并导致程序退出.使用Length()则没有问题.
显然这里没有处理好双字节的问题.同样的原因,FindExecFile函数也会有此问题.麻烦开发组人员帮忙检查下.

[ 本帖最后由 yinsim 于 2010-8-18 10:32 编辑 ]
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6750
Posts 3551
点点分 6750
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2010-8-20 22:07  Profile | Blog | P.M. 
感谢指出,已修正并提交至SVN。
Top
 




All times are GMT++8, the time now is 2024-3-29 19:45

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.006209 second(s), 7 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP