function GetModuleFileName(Module: HMODULE; Buffer: PChar; BufLen: Integer): Integer;
Module模块的句柄模块,其文件名是必需的。
Buffer是一个缓冲区,它接收文件的名称。
BufLen是在缓冲区的字节数。
GetModuleFileName返回写入缓冲区的字节数。
警告:GetModuleFileName并不总是成功的。在应用程序调用方式,在/ proc文件系统的存在,以及其他因素的不同,有些时候可能会返回GetModuleFileName一个不完全合格的名称,或在某些情况下,没有在所有的文件名。请务必在使用前要检查这个返回值函数的结果。
{当前项目的路径}
function GetCurrPath(IsAutoGetDll: boolean = true): string;
{当前项目的全部的路径(包括exe)}
function GetCurrDllpath: string;
{获取桌面}
function GetDeskeptPath: string;
{获取我的文档}
function GetMyDoumentpath: string;
{-------------------------------------------------------------------------------
过程名: GetCurrPath
作者: 张志峰
日期: 2010.11.23
参数: 无
返回值: String
说明: 获取当前项目的路径
-------------------------------------------------------------------------------}
function GetCurrPath(IsAutoGetDll: boolean = true): string;
var
ModName: array[0..MAX_PATH] of Char;
begin
if ModuleIsLib and IsAutoGetDll then begin
GetModuleFileName(HInstance, ModName, SizeOf(ModName)); // 取得当前项目的路径
Result := ExtractFilePath(ModName);
end
else
Result := ExtractFilePath(ParamStr(0));
end;
{-------------------------------------------------------------------------------
过程名: GetCurrDllpath
作者: 张志峰
日期: 2010.11.23
参数: 无
返回值: String
说明: 获取当前项目的路径包括exe
-------------------------------------------------------------------------------}
function GetCurrDllpath: string;
var
p: pchar;
begin
getmem(p, 255);
try
getmodulefilename(hinstance, p, 255);
result := trim(strpas(p));
finally
freemem(p, 255);
end;
end;
function GetShellFolders(strDir: string): string;
const
regPath = '\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders';
var
Reg: TRegistry;
strFolders: string;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey(regPath, false) then begin
strFolders := Reg.ReadString(strDir);
end;
finally
Reg.Free;
end;
result := strFolders;
end;
{获取桌面}
function GetDeskeptPath: string;
begin
Result := GetShellFolders('Desktop'); //是取得桌面文件夹的路径
end;
{获取我的文档}
function GetMyDoumentpath: string;
begin
Result := GetShellFolders('Personal'); //我的文档
end;