Delphi 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.

相关阅读 >>

Delphi xe8 tstylebook的使用

Delphi用内存流方式获取页面验证码图片

Delphi 如何产生输出一个变形的图形及文字

Delphi判断文件夹(目录)是否存在,不存在就创建的办法

Delphi的idhttp报508 loop detected错误的原因

Delphi urldownloadtofile 支持进度条

Delphi firedac 获取 insert 记录的自增 id

Delphi 2007 使用shelltreeview控件

Delphi excel数据导入数据库表

Delphi 双击关闭pagecontrol中的一个分页

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



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...