zoukankan      html  css  js  c++  java
  • WinAPI: GetModuleFileName、GetModuleHandle

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FormCreate(Sender: TObject);
    var
      buf: array[0..MAX_PATH] of Char;
      hinst: HMODULE;
    begin
      {获取指定模块的句柄}
      hinst := GetModuleHandle('gdi32.dll');
    
      {获取模块的路径}
      GetModuleFileName(hinst, buf, Length(buf));
      ShowMessage(buf); {C:\WINDOWS\system32\GDI32.dll}
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      buf: array[0..MAX_PATH] of Char;
    begin
      {当 GetModuleFileName 的第一个参数为 0 或 HInstance 时, 会获取当前模块路径}
      GetModuleFileName(0, buf, Length(buf));
      ShowMessage(buf);
    
      GetModuleFileName(HInstance, buf, Length(buf));
      ShowMessage(buf);
    
      {获取当前程序路径的常用方法}
      ShowMessage(Application.ExeName);
      ShowMessage(ParamStr(0));
    end;
    
    end.
    
  • 相关阅读:
    C语言知识
    Java课程设计——个人
    Java大作业
    DAO模式代码阅读及应用
    有理数设计
    泛型 -Java
    集合框架之ArrayList -Java
    图总结
    树、二叉树、查找算法总结
    编辑器、编译器、文件、IDE等常见概念辨析
  • 原文地址:https://www.cnblogs.com/del/p/1223681.html
Copyright © 2011-2022 走看看