#DllLoad

スクリプトの実行を開始する前に、DLLまたはEXEファイルをロードします。

#DllLoad FileOrDirName

パラメータ

FileOrDirName

型:文字列

以下に説明する、ファイルまたはディレクトリのパス。This must not contain double quotes (except for an optional pair of double quotes surrounding the parameter), wildcards or escape sequences other than semicolon (`;).

Built-in variables may be used by enclosing them in percent signs (for example, #DllLoad "%A_ScriptDir%"). 有効な変数参照の一部でないパーセント記号は、文字通りに解釈されます。A_Argsと、組み込みクラスを除く、すべての組込変数が有効です。

既知の制限:スクリプトをコンパイルする際、変数はコンパイラによって評価され、最終的に実行されたときにスクリプトが返す値とは異なる場合があります。以下の変数に対応:A_AhkPath, A_AppData, A_AppDataCommon, A_ComputerName, A_ComSpec, A_Desktop, A_DesktopCommon, A_IsCompiled, A_LineFile, A_MyDocuments, A_ProgramFiles, A_Programs, A_ProgramsCommon, A_ScriptDir, A_ScriptFullPath, A_ScriptName, A_Space, A_StartMenu, A_StartMenuCommon, A_Startup, A_StartupCommon, A_Tab, A_Temp, A_UserName, A_WinDir.

ファイル:ロードする DLL または EXE ファイルの絶対パスまたは相対パスを指定します。相対パスが指定された場合、システムの関数LoadLibraryWと同じ検索方法でファイルを検索します。注:SetWorkingDirは、スクリプトの実行を開始する前に#DllLoadが処理されるため、#DllLoadには影響しません。

ディレクトリ:DLLまたはEXEへの絶対パスを指定しない#DllLoadを実行した場合、ファイルではなくディレクトリを指定することで検索方法を変更します。新しい検索戦略は、Directoryが、システムの関数SetDllDirectoryWに渡された場合と同じです。このパラメータが省略された場合、デフォルトの検索ストラテジーが復元されます。

注:このパラメータは式ではなく、引用符(「シングル」または「ダブル」のいずれか)で囲むことができます。

備考

このディレクティブによって一度ロードされたDLLやEXEは、システムの関数FreeLibraryを呼び出すことによってアンロードすることができません。スクリプトの終了時には、ロードされたすべてのファイルが自動的にアンロードされます。

The file path may optionally be preceded by *i and a single space, which causes the program to ignore any failure to load the file. このオプションは、DLLやEXEが必須でないなど、障害があってもスクリプトが実行できる場合、またはスクリプトが障害を検出するように設計されている場合にのみ使用する必要があります。事例:

#DllLoad "*i MyDLL"
if !DllCall("GetModuleHandle", "str", "MyDLL")
    MsgBox "Failed to load MyDLL!"

If the FileOrDirName parameter specifies a DLL name without a path and the file name extension is omitted, .dll is appended to the file name. To prevent this, include a trailing period (.) in the file name.

他のディレクティブと同様に、#DllLoadは条件付きで実行することはできません。

DllCall

スクリプトの実行前に、カレントユーザーの "My Documents"フォルダーにあるDLLファイルをロードします。

#DllLoad "%A_MyDocuments%\MyDLL.dll"