Delphi的TService 服务路径获取 Dll中获取文件路径

2022-11-25 09:10:33 作者:admin

本文整理自网络,侵删。

 Delphi的TService 服务路径获取 Dll中获取文件路径研究delphi服务的路径,试了好几个方法 ,都没取出来,最后发现,要采用取DLL路径的方法
//一、获取Dll自身路径
//1)方法一:
Function GetDllPath(sDllName:string):string;
varModuleFileName:array[0..255] of char; 
begin//{取得dll的实际位置}GetModuleFileName(GetModuleHandle(sDllName), @ModuleFileName[0], SizeOf(ModuleFileName));Result := ModuleFileName;end;
//2)方法二:
Function GetDllPath:string;
varModuleName:string;beginSetLength(ModuleName, 255);//取得Dll自身路径GetModuleFileName(HInstance, PChar(ModuleName), Length(ModuleName));Result := PChar(ModuleName);
end;

// 二、获取调用程序路径
Function GetExecutPath:string;
varModuleName:string;beginSetLength(ModuleName, 255);//取得调用Dll程序的路径GetModuleFileName(GetModuleHandle(nil), PChar(ModuleName), Length(ModuleName));Result := PChar(ModuleName);
end;
点击打开链接
Delphi遍历进程并获取进程路径
获得进程可执行文件的路径: GetModuleFileNameEx, GetProcessImageFileName, QueryFullProcessImageName
功能模块改良版:
unit UntModulePath;
interface
usesWindows, SysUtils, PsAPI;
//获取EXE、Dll模块名称 或 路径function GetModuleFileNameDef(GetPath: Boolean = True): string;
function GetWindowProcHandle(Wnd: HWND; GetPath: Boolean = True): string;
varDllPath: string;
implementation
function GetModuleFileNameDef(GetPath: Boolean = True): string;varModuleName: array [0..MAX_PATH - 1]of char;beginFillChar(ModuleName, Length(ModuleName), 0);//取得Dll自身路径GetModuleFileName(HInstance, ModuleName, Length(ModuleName));
if GetPath thenResult := ExtractFilePath(StrPas(ModuleName))elseResult := StrPas(ModuleName);end;

function GetWindowProcHandle(Wnd: HWND; GetPath: Boolean = True): string;varpID: Cardinal;hProc: THandle;ModuleName: array [0..MAX_PATH - 1]of char;begin Result := '';if Wnd= 0 thenExit;
FillChar(ModuleName, Length(ModuleName), 0);
GetWindowThreadProcessId(Wnd, pID);hProc:= OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, pID);if hProc= 0 thenExit;tryGetModuleFileNameEx(hProc, 0, ModuleName, Length(ModuleName));finallyCloseHandle(hProc);end;if GetPath thenResult := ExtractFilePath(StrPas(ModuleName))elseResult := StrPas(ModuleName);end;
initializationDllPath:= GetModuleFileNameDef;
end. 来源:https://www.cnblogs.com/zhqian/p/9994619.html

相关阅读 >>

Delphi将字符串转换成utf8编码的函数

Delphi中动态加载image控件图片的方法

Delphi 获取安卓手机wifi信息(xe8)

Delphi append 追加内容到文件中

Delphi 最简单的ttcpserver与ttcpclient通信实例

Delphi nethttpclient1 数据库查询

Delphi fmx 获取系统版本 android ios通用

Delphi copy 字符串函数

Delphi xe8 numberbox使用方法及存在的问题

Delphi内存映射 与 映射数据获取

更多相关阅读请进入《Delphi》频道 >>



在线咨询 拨打电话