{*******************************************************}
{                                                       }
{       Tocsg.DllEntry                                  }
{                                                       }
{       Copyright (C) 2022 kku                          }
{                                                       }
{*******************************************************}

unit Tocsg.DllEntry;

interface

uses
  Tocsg.Obj, System.SysUtils, Winapi.Windows;

type
  TTgDllEntry = class(TTgObject)
  private
    dwPID_: DWORD;
    sDllPath_,
    sDllName_,
    sModulePath_,
    sModuleName_: String;
  public
    Constructor Create;
    Destructor Destroy; override;

    property PID: DWORD read dwPID_;
    property ModulePath: String read sModulePath_;
    property ModuleName: String read sModuleName_;
    property DllPath: String read sDllPath_;
    property DllName: String read sDllName_;
  end;

implementation

uses
  Tocsg.KERNEL32;

{ TTgDllEntry }

Constructor TTgDllEntry.Create;

  procedure InitInformation;
  var
    sPath: array [0..512] of Char;
    hm: HMODULE;
  begin
    dwPID_ := GetCurrentProcessId;
    GetModuleFileName(0, sPath, 512);
    sModulePath_ := sPath;
    sModuleName_ := ExtractFileName(sPath);

    sDllPath_ := '';
    sDllName_ := '';

  // 추가 16_0112 16:14:56 kku 
    if GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, 'InstallWindowActiveHook', @hm) and (hm <> 0) then
    begin
      sDllPath_ := GetModuleName(hm);
      if sDllPath_ <> '' then
      begin
        sDllName_ := ExtractFileName(sDllPath_);
        sDllPath_ := ExtractFilePath(sDllPath_);
      end;
    end;
  end;

begin
  Inherited Create;
  InitInformation;
  _Trace('[%s] DllEntry::%s.Create()', [ClassName, ModuleName]);
end;

Destructor TTgDllEntry.Destroy;
begin
  _Trace('[%s] DllEntry::%s.Destroy()', [ClassName, ModuleName]);
  Inherited;
end;

end.
