K32GetDeviceDriverBaseNameW
関数シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
DWORD K32GetDeviceDriverBaseNameW(
void* ImageBase,
LPWSTR lpBaseName,
DWORD nSize
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ImageBase | void* | in | デバイスドライバーのロードアドレス。この値は EnumDeviceDrivers 関数を使用して取得できます。 |
| lpBaseName | LPWSTR | out | ドライバのベース名(ワイド文字列)を受け取るバッファへのポインタ。出力。 |
| nSize | DWORD | in | lpBaseName バッファーのサイズ (文字数単位)。バッファーがベース名と終端の null 文字を格納するのに十分な大きさでない場合、文字列は切り詰められます。 - lpBaseName [out]デバイスドライバーのベース名を受け取るバッファーへのポインター。 |
戻り値の型: DWORD
公式ドキュメント
指定したデバイスドライバーのベース名を取得します。(ANSI)
戻り値
関数が成功した場合、戻り値はバッファーにコピーされた文字列の長さ (終端の null 文字を含まない) を表します。
関数が失敗した場合、戻り値は 0 です。拡張エラー情報を取得するには、 GetLastError を呼び出します。
解説(Remarks)
Windows 7 および Windows Server 2008 R2 以降、Psapi.h は PSAPI 関数のバージョン番号を定めています。PSAPI のバージョン番号は、関数を呼び出すために使用する名前と、プログラムがロードする必要のあるライブラリに影響します。
PSAPI_VERSION が 2 以上の場合、この関数は Psapi.h で K32GetDeviceDriverBaseName として定義され、Kernel32.lib および Kernel32.dll でエクスポートされます。PSAPI_VERSION が 1 の場合、この関数は Psapi.h で GetDeviceDriverBaseName として定義され、K32GetDeviceDriverBaseName を呼び出すラッパーとして Psapi.lib および Psapi.dll でエクスポートされます。
Windows 7 以降のバージョンに加えて、それより前のバージョンの Windows でも動作する必要のあるプログラムは、常にこの関数を GetDeviceDriverBaseName として呼び出してください。シンボルが正しく解決されるようにするには、Psapi.lib を TARGETLIBS マクロに追加し、–DPSAPI_VERSION=1 を指定してプログラムをコンパイルします。実行時の動的リンクを使用するには、Psapi.dll をロードします。
Examples
例については、 Enumerating all Device Drivers in the System を参照してください。
psapi.h ヘッダーは GetDeviceDriverBaseName を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング非依存のエイリアスの使用を、エンコーディング非依存でないコードと混在させると、不一致が生じ、コンパイルエラーや実行時エラーの原因となる場合があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
DWORD K32GetDeviceDriverBaseNameW(
void* ImageBase,
LPWSTR lpBaseName,
DWORD nSize
);[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint K32GetDeviceDriverBaseNameW(
IntPtr ImageBase, // void*
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpBaseName, // LPWSTR out
uint nSize // DWORD
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function K32GetDeviceDriverBaseNameW(
ImageBase As IntPtr, ' void*
<MarshalAs(UnmanagedType.LPWStr)> lpBaseName As System.Text.StringBuilder, ' LPWSTR out
nSize As UInteger ' DWORD
) As UInteger
End Function' ImageBase : void*
' lpBaseName : LPWSTR out
' nSize : DWORD
Declare PtrSafe Function K32GetDeviceDriverBaseNameW Lib "kernel32" ( _
ByVal ImageBase As LongPtr, _
ByVal lpBaseName As LongPtr, _
ByVal nSize As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
K32GetDeviceDriverBaseNameW = ctypes.windll.kernel32.K32GetDeviceDriverBaseNameW
K32GetDeviceDriverBaseNameW.restype = wintypes.DWORD
K32GetDeviceDriverBaseNameW.argtypes = [
ctypes.POINTER(None), # ImageBase : void*
wintypes.LPWSTR, # lpBaseName : LPWSTR out
wintypes.DWORD, # nSize : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
K32GetDeviceDriverBaseNameW = Fiddle::Function.new(
lib['K32GetDeviceDriverBaseNameW'],
[
Fiddle::TYPE_VOIDP, # ImageBase : void*
Fiddle::TYPE_VOIDP, # lpBaseName : LPWSTR out
-Fiddle::TYPE_INT, # nSize : DWORD
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn K32GetDeviceDriverBaseNameW(
ImageBase: *mut (), // void*
lpBaseName: *mut u16, // LPWSTR out
nSize: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode)]
public static extern uint K32GetDeviceDriverBaseNameW(IntPtr ImageBase, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpBaseName, uint nSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_K32GetDeviceDriverBaseNameW' -Namespace Win32 -PassThru
# $api::K32GetDeviceDriverBaseNameW(ImageBase, lpBaseName, nSize)#uselib "KERNEL32.dll"
#func global K32GetDeviceDriverBaseNameW "K32GetDeviceDriverBaseNameW" wptr, wptr, wptr
; K32GetDeviceDriverBaseNameW ImageBase, varptr(lpBaseName), nSize ; 戻り値は stat
; ImageBase : void* -> "wptr"
; lpBaseName : LPWSTR out -> "wptr"
; nSize : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll" #cfunc global K32GetDeviceDriverBaseNameW "K32GetDeviceDriverBaseNameW" sptr, var, int ; res = K32GetDeviceDriverBaseNameW(ImageBase, lpBaseName, nSize) ; ImageBase : void* -> "sptr" ; lpBaseName : LPWSTR out -> "var" ; nSize : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global K32GetDeviceDriverBaseNameW "K32GetDeviceDriverBaseNameW" sptr, sptr, int ; res = K32GetDeviceDriverBaseNameW(ImageBase, varptr(lpBaseName), nSize) ; ImageBase : void* -> "sptr" ; lpBaseName : LPWSTR out -> "sptr" ; nSize : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD K32GetDeviceDriverBaseNameW(void* ImageBase, LPWSTR lpBaseName, DWORD nSize) #uselib "KERNEL32.dll" #cfunc global K32GetDeviceDriverBaseNameW "K32GetDeviceDriverBaseNameW" intptr, var, int ; res = K32GetDeviceDriverBaseNameW(ImageBase, lpBaseName, nSize) ; ImageBase : void* -> "intptr" ; lpBaseName : LPWSTR out -> "var" ; nSize : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD K32GetDeviceDriverBaseNameW(void* ImageBase, LPWSTR lpBaseName, DWORD nSize) #uselib "KERNEL32.dll" #cfunc global K32GetDeviceDriverBaseNameW "K32GetDeviceDriverBaseNameW" intptr, intptr, int ; res = K32GetDeviceDriverBaseNameW(ImageBase, varptr(lpBaseName), nSize) ; ImageBase : void* -> "intptr" ; lpBaseName : LPWSTR out -> "intptr" ; nSize : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procK32GetDeviceDriverBaseNameW = kernel32.NewProc("K32GetDeviceDriverBaseNameW")
)
// ImageBase (void*), lpBaseName (LPWSTR out), nSize (DWORD)
r1, _, err := procK32GetDeviceDriverBaseNameW.Call(
uintptr(ImageBase),
uintptr(lpBaseName),
uintptr(nSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction K32GetDeviceDriverBaseNameW(
ImageBase: Pointer; // void*
lpBaseName: PWideChar; // LPWSTR out
nSize: DWORD // DWORD
): DWORD; stdcall;
external 'KERNEL32.dll' name 'K32GetDeviceDriverBaseNameW';result := DllCall("KERNEL32\K32GetDeviceDriverBaseNameW"
, "Ptr", ImageBase ; void*
, "Ptr", lpBaseName ; LPWSTR out
, "UInt", nSize ; DWORD
, "UInt") ; return: DWORD●K32GetDeviceDriverBaseNameW(ImageBase, lpBaseName, nSize) = DLL("KERNEL32.dll", "dword K32GetDeviceDriverBaseNameW(void*, char*, dword)")
# 呼び出し: K32GetDeviceDriverBaseNameW(ImageBase, lpBaseName, nSize)
# ImageBase : void* -> "void*"
# lpBaseName : LPWSTR out -> "char*"
# nSize : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "kernel32" fn K32GetDeviceDriverBaseNameW(
ImageBase: ?*anyopaque, // void*
lpBaseName: [*c]u16, // LPWSTR out
nSize: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc K32GetDeviceDriverBaseNameW(
ImageBase: pointer, # void*
lpBaseName: ptr uint16, # LPWSTR out
nSize: uint32 # DWORD
): uint32 {.importc: "K32GetDeviceDriverBaseNameW", stdcall, dynlib: "KERNEL32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "kernel32");
extern(Windows)
uint K32GetDeviceDriverBaseNameW(
void* ImageBase, // void*
wchar* lpBaseName, // LPWSTR out
uint nSize // DWORD
);ccall((:K32GetDeviceDriverBaseNameW, "KERNEL32.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Ptr{UInt16}, UInt32),
ImageBase, lpBaseName, nSize)
# ImageBase : void* -> Ptr{Cvoid}
# lpBaseName : LPWSTR out -> Ptr{UInt16}
# nSize : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t K32GetDeviceDriverBaseNameW(
void* ImageBase,
uint16_t* lpBaseName,
uint32_t nSize);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.K32GetDeviceDriverBaseNameW(ImageBase, lpBaseName, nSize)
-- ImageBase : void*
-- lpBaseName : LPWSTR out
-- nSize : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const K32GetDeviceDriverBaseNameW = lib.func('__stdcall', 'K32GetDeviceDriverBaseNameW', 'uint32_t', ['void *', 'uint16_t *', 'uint32_t']);
// K32GetDeviceDriverBaseNameW(ImageBase, lpBaseName, nSize)
// ImageBase : void* -> 'void *'
// lpBaseName : LPWSTR out -> 'uint16_t *'
// nSize : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
K32GetDeviceDriverBaseNameW: { parameters: ["pointer", "buffer", "u32"], result: "u32" },
});
// lib.symbols.K32GetDeviceDriverBaseNameW(ImageBase, lpBaseName, nSize)
// ImageBase : void* -> "pointer"
// lpBaseName : LPWSTR out -> "buffer"
// nSize : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t K32GetDeviceDriverBaseNameW(
void* ImageBase,
uint16_t* lpBaseName,
uint32_t nSize);
C, "KERNEL32.dll");
// $ffi->K32GetDeviceDriverBaseNameW(ImageBase, lpBaseName, nSize);
// ImageBase : void*
// lpBaseName : LPWSTR out
// nSize : DWORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class, W32APIOptions.UNICODE_OPTIONS);
int K32GetDeviceDriverBaseNameW(
Pointer ImageBase, // void*
char[] lpBaseName, // LPWSTR out
int nSize // DWORD
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("kernel32")]
lib LibKERNEL32
fun K32GetDeviceDriverBaseNameW = K32GetDeviceDriverBaseNameW(
ImageBase : Void*, # void*
lpBaseName : UInt16*, # LPWSTR out
nSize : UInt32 # DWORD
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef K32GetDeviceDriverBaseNameWNative = Uint32 Function(Pointer<Void>, Pointer<Utf16>, Uint32);
typedef K32GetDeviceDriverBaseNameWDart = int Function(Pointer<Void>, Pointer<Utf16>, int);
final K32GetDeviceDriverBaseNameW = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<K32GetDeviceDriverBaseNameWNative, K32GetDeviceDriverBaseNameWDart>('K32GetDeviceDriverBaseNameW');
// ImageBase : void* -> Pointer<Void>
// lpBaseName : LPWSTR out -> Pointer<Utf16>
// nSize : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function K32GetDeviceDriverBaseNameW(
ImageBase: Pointer; // void*
lpBaseName: PWideChar; // LPWSTR out
nSize: DWORD // DWORD
): DWORD; stdcall;
external 'KERNEL32.dll' name 'K32GetDeviceDriverBaseNameW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "K32GetDeviceDriverBaseNameW"
c_K32GetDeviceDriverBaseNameW :: Ptr () -> CWString -> Word32 -> IO Word32
-- ImageBase : void* -> Ptr ()
-- lpBaseName : LPWSTR out -> CWString
-- nSize : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let k32getdevicedriverbasenamew =
foreign "K32GetDeviceDriverBaseNameW"
((ptr void) @-> (ptr uint16_t) @-> uint32_t @-> returning uint32_t)
(* ImageBase : void* -> (ptr void) *)
(* lpBaseName : LPWSTR out -> (ptr uint16_t) *)
(* nSize : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("K32GetDeviceDriverBaseNameW" k32-get-device-driver-base-name-w :convention :stdcall) :uint32
(image-base :pointer) ; void*
(lp-base-name :pointer) ; LPWSTR out
(n-size :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $K32GetDeviceDriverBaseNameW = Win32::API::More->new('KERNEL32',
'DWORD K32GetDeviceDriverBaseNameW(LPVOID ImageBase, LPWSTR lpBaseName, DWORD nSize)');
# my $ret = $K32GetDeviceDriverBaseNameW->Call($ImageBase, $lpBaseName, $nSize);
# ImageBase : void* -> LPVOID
# lpBaseName : LPWSTR out -> LPWSTR
# nSize : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f K32GetDeviceDriverBaseNameA (ANSI版) — デバイスドライバの基本名をANSI文字列で取得する。
- f EnumDeviceDrivers — システムにロードされたデバイスドライバを列挙する。