ホーム › System.LibraryLoader › GetDllDirectoryA
GetDllDirectoryA
関数現在のDLL検索ディレクトリをANSI文字列で取得する。
シグネチャ
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
DWORD GetDllDirectoryA(
DWORD nBufferLength,
LPSTR lpBuffer // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| nBufferLength | DWORD | in |
| lpBuffer | LPSTR | outoptional |
戻り値の型: DWORD
各言語での呼び出し定義
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
DWORD GetDllDirectoryA(
DWORD nBufferLength,
LPSTR lpBuffer // optional
);[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern uint GetDllDirectoryA(
uint nBufferLength, // DWORD
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpBuffer // LPSTR optional, out
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetDllDirectoryA(
nBufferLength As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPStr)> lpBuffer As System.Text.StringBuilder ' LPSTR optional, out
) As UInteger
End Function' nBufferLength : DWORD
' lpBuffer : LPSTR optional, out
Declare PtrSafe Function GetDllDirectoryA Lib "kernel32" ( _
ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetDllDirectoryA = ctypes.windll.kernel32.GetDllDirectoryA
GetDllDirectoryA.restype = wintypes.DWORD
GetDllDirectoryA.argtypes = [
wintypes.DWORD, # nBufferLength : DWORD
wintypes.LPSTR, # lpBuffer : LPSTR optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
GetDllDirectoryA = Fiddle::Function.new(
lib['GetDllDirectoryA'],
[
-Fiddle::TYPE_INT, # nBufferLength : DWORD
Fiddle::TYPE_VOIDP, # lpBuffer : LPSTR optional, out
],
-Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn GetDllDirectoryA(
nBufferLength: u32, // DWORD
lpBuffer: *mut u8 // LPSTR optional, out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern uint GetDllDirectoryA(uint nBufferLength, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpBuffer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetDllDirectoryA' -Namespace Win32 -PassThru
# $api::GetDllDirectoryA(nBufferLength, lpBuffer)#uselib "KERNEL32.dll"
#func global GetDllDirectoryA "GetDllDirectoryA" sptr, sptr
; GetDllDirectoryA nBufferLength, varptr(lpBuffer) ; 戻り値は stat
; nBufferLength : DWORD -> "sptr"
; lpBuffer : LPSTR optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global GetDllDirectoryA "GetDllDirectoryA" int, var ; res = GetDllDirectoryA(nBufferLength, lpBuffer) ; nBufferLength : DWORD -> "int" ; lpBuffer : LPSTR optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global GetDllDirectoryA "GetDllDirectoryA" int, sptr ; res = GetDllDirectoryA(nBufferLength, varptr(lpBuffer)) ; nBufferLength : DWORD -> "int" ; lpBuffer : LPSTR optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD GetDllDirectoryA(DWORD nBufferLength, LPSTR lpBuffer) #uselib "KERNEL32.dll" #cfunc global GetDllDirectoryA "GetDllDirectoryA" int, var ; res = GetDllDirectoryA(nBufferLength, lpBuffer) ; nBufferLength : DWORD -> "int" ; lpBuffer : LPSTR optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD GetDllDirectoryA(DWORD nBufferLength, LPSTR lpBuffer) #uselib "KERNEL32.dll" #cfunc global GetDllDirectoryA "GetDllDirectoryA" int, intptr ; res = GetDllDirectoryA(nBufferLength, varptr(lpBuffer)) ; nBufferLength : DWORD -> "int" ; lpBuffer : LPSTR optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGetDllDirectoryA = kernel32.NewProc("GetDllDirectoryA")
)
// nBufferLength (DWORD), lpBuffer (LPSTR optional, out)
r1, _, err := procGetDllDirectoryA.Call(
uintptr(nBufferLength),
uintptr(lpBuffer),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction GetDllDirectoryA(
nBufferLength: DWORD; // DWORD
lpBuffer: PAnsiChar // LPSTR optional, out
): DWORD; stdcall;
external 'KERNEL32.dll' name 'GetDllDirectoryA';result := DllCall("KERNEL32\GetDllDirectoryA"
, "UInt", nBufferLength ; DWORD
, "Ptr", lpBuffer ; LPSTR optional, out
, "UInt") ; return: DWORD●GetDllDirectoryA(nBufferLength, lpBuffer) = DLL("KERNEL32.dll", "dword GetDllDirectoryA(dword, char*)")
# 呼び出し: GetDllDirectoryA(nBufferLength, lpBuffer)
# nBufferLength : DWORD -> "dword"
# lpBuffer : LPSTR optional, out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。