Delphi的Dll中获取文件路径

//一、获取Dll自身路径

//1)方法一:

Function GetDllPath(sDllName:string):string;

var
  ModuleFileName:array[0..255] of char; 

begin
  //{取得dll的实际位置}
  GetModuleFileName(GetModuleHandle(sDllName), @ModuleFileName[0], SizeOf(ModuleFileName));
  Result := ModuleFileName;
end;

//2)方法二:

Function GetDllPath:string;

var
  ModuleName:string;
begin
  SetLength(ModuleName, 255);
  //取得Dll自身路径
  GetModuleFileName(HInstance, PChar(ModuleName), Length(ModuleName));
   Result := PChar(ModuleName);

end;


//  二、获取调用程序路径

Function GetExecutPath:string;

var
  ModuleName:string;
begin
  SetLength(ModuleName, 255);
  //取得调用Dll程序的路径
  GetModuleFileName(GetModuleHandle(nil), PChar(ModuleName), Length(ModuleName));
   Result := PChar(ModuleName);

end;

点击打开链接
相关文章
相关标签/搜索