如何模块内部获得自身路径? Exe程序 DLL程序:

发布于 2020-01-11 23:04:07
关注者
0
被浏览
354
1 个回答
  • 面试哥
    面试哥 2020-01-11
    为面试而生,有面试问题,就找面试哥。

    回答: 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;
    
    

     

知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看