如何模块内部获得自身路径? Exe程序 DLL程序:
发布于 2020-01-11 23:04:07
关注者
0
被浏览
354
1 个回答
-
回答: exe: application.Exename ExpandFileName 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;