ホーム › Graphics.Printing › GetPrinterDriverDirectoryW
GetPrinterDriverDirectoryW
関数プリンタドライバの格納ディレクトリパスを取得する(Unicode版)。
シグネチャ
// winspool.drv (Unicode / -W)
#include <windows.h>
BOOL GetPrinterDriverDirectoryW(
LPCWSTR pName, // optional
LPCWSTR pEnvironment, // optional
DWORD Level,
BYTE* pDriverDirectory, // optional
DWORD cbBuf,
DWORD* pcbNeeded
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pName | LPCWSTR | inoptional |
| pEnvironment | LPCWSTR | inoptional |
| Level | DWORD | in |
| pDriverDirectory | BYTE* | outoptional |
| cbBuf | DWORD | in |
| pcbNeeded | DWORD* | out |
戻り値の型: BOOL
各言語での呼び出し定義
// winspool.drv (Unicode / -W)
#include <windows.h>
BOOL GetPrinterDriverDirectoryW(
LPCWSTR pName, // optional
LPCWSTR pEnvironment, // optional
DWORD Level,
BYTE* pDriverDirectory, // optional
DWORD cbBuf,
DWORD* pcbNeeded
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool GetPrinterDriverDirectoryW(
[MarshalAs(UnmanagedType.LPWStr)] string pName, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string pEnvironment, // LPCWSTR optional
uint Level, // DWORD
IntPtr pDriverDirectory, // BYTE* optional, out
uint cbBuf, // DWORD
out uint pcbNeeded // DWORD* out
);<DllImport("winspool.drv", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function GetPrinterDriverDirectoryW(
<MarshalAs(UnmanagedType.LPWStr)> pName As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> pEnvironment As String, ' LPCWSTR optional
Level As UInteger, ' DWORD
pDriverDirectory As IntPtr, ' BYTE* optional, out
cbBuf As UInteger, ' DWORD
<Out> ByRef pcbNeeded As UInteger ' DWORD* out
) As Boolean
End Function' pName : LPCWSTR optional
' pEnvironment : LPCWSTR optional
' Level : DWORD
' pDriverDirectory : BYTE* optional, out
' cbBuf : DWORD
' pcbNeeded : DWORD* out
Declare PtrSafe Function GetPrinterDriverDirectoryW Lib "winspool.drv" ( _
ByVal pName As LongPtr, _
ByVal pEnvironment As LongPtr, _
ByVal Level As Long, _
ByVal pDriverDirectory As LongPtr, _
ByVal cbBuf As Long, _
ByRef pcbNeeded 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
GetPrinterDriverDirectoryW = ctypes.windll.LoadLibrary("winspool.drv").GetPrinterDriverDirectoryW
GetPrinterDriverDirectoryW.restype = wintypes.BOOL
GetPrinterDriverDirectoryW.argtypes = [
wintypes.LPCWSTR, # pName : LPCWSTR optional
wintypes.LPCWSTR, # pEnvironment : LPCWSTR optional
wintypes.DWORD, # Level : DWORD
ctypes.POINTER(ctypes.c_ubyte), # pDriverDirectory : BYTE* optional, out
wintypes.DWORD, # cbBuf : DWORD
ctypes.POINTER(wintypes.DWORD), # pcbNeeded : DWORD* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('winspool.drv')
GetPrinterDriverDirectoryW = Fiddle::Function.new(
lib['GetPrinterDriverDirectoryW'],
[
Fiddle::TYPE_VOIDP, # pName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pEnvironment : LPCWSTR optional
-Fiddle::TYPE_INT, # Level : DWORD
Fiddle::TYPE_VOIDP, # pDriverDirectory : BYTE* optional, out
-Fiddle::TYPE_INT, # cbBuf : DWORD
Fiddle::TYPE_VOIDP, # pcbNeeded : DWORD* out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "winspool.drv")]
extern "system" {
fn GetPrinterDriverDirectoryW(
pName: *const u16, // LPCWSTR optional
pEnvironment: *const u16, // LPCWSTR optional
Level: u32, // DWORD
pDriverDirectory: *mut u8, // BYTE* optional, out
cbBuf: u32, // DWORD
pcbNeeded: *mut u32 // DWORD* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("winspool.drv", CharSet = CharSet.Unicode)]
public static extern bool GetPrinterDriverDirectoryW([MarshalAs(UnmanagedType.LPWStr)] string pName, [MarshalAs(UnmanagedType.LPWStr)] string pEnvironment, uint Level, IntPtr pDriverDirectory, uint cbBuf, out uint pcbNeeded);
"@
$api = Add-Type -MemberDefinition $sig -Name 'winspool.drv_GetPrinterDriverDirectoryW' -Namespace Win32 -PassThru
# $api::GetPrinterDriverDirectoryW(pName, pEnvironment, Level, pDriverDirectory, cbBuf, pcbNeeded)#uselib "winspool.drv"
#func global GetPrinterDriverDirectoryW "GetPrinterDriverDirectoryW" wptr, wptr, wptr, wptr, wptr, wptr
; GetPrinterDriverDirectoryW pName, pEnvironment, Level, varptr(pDriverDirectory), cbBuf, varptr(pcbNeeded) ; 戻り値は stat
; pName : LPCWSTR optional -> "wptr"
; pEnvironment : LPCWSTR optional -> "wptr"
; Level : DWORD -> "wptr"
; pDriverDirectory : BYTE* optional, out -> "wptr"
; cbBuf : DWORD -> "wptr"
; pcbNeeded : DWORD* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "winspool.drv" #cfunc global GetPrinterDriverDirectoryW "GetPrinterDriverDirectoryW" wstr, wstr, int, var, int, var ; res = GetPrinterDriverDirectoryW(pName, pEnvironment, Level, pDriverDirectory, cbBuf, pcbNeeded) ; pName : LPCWSTR optional -> "wstr" ; pEnvironment : LPCWSTR optional -> "wstr" ; Level : DWORD -> "int" ; pDriverDirectory : BYTE* optional, out -> "var" ; cbBuf : DWORD -> "int" ; pcbNeeded : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "winspool.drv" #cfunc global GetPrinterDriverDirectoryW "GetPrinterDriverDirectoryW" wstr, wstr, int, sptr, int, sptr ; res = GetPrinterDriverDirectoryW(pName, pEnvironment, Level, varptr(pDriverDirectory), cbBuf, varptr(pcbNeeded)) ; pName : LPCWSTR optional -> "wstr" ; pEnvironment : LPCWSTR optional -> "wstr" ; Level : DWORD -> "int" ; pDriverDirectory : BYTE* optional, out -> "sptr" ; cbBuf : DWORD -> "int" ; pcbNeeded : DWORD* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetPrinterDriverDirectoryW(LPCWSTR pName, LPCWSTR pEnvironment, DWORD Level, BYTE* pDriverDirectory, DWORD cbBuf, DWORD* pcbNeeded) #uselib "winspool.drv" #cfunc global GetPrinterDriverDirectoryW "GetPrinterDriverDirectoryW" wstr, wstr, int, var, int, var ; res = GetPrinterDriverDirectoryW(pName, pEnvironment, Level, pDriverDirectory, cbBuf, pcbNeeded) ; pName : LPCWSTR optional -> "wstr" ; pEnvironment : LPCWSTR optional -> "wstr" ; Level : DWORD -> "int" ; pDriverDirectory : BYTE* optional, out -> "var" ; cbBuf : DWORD -> "int" ; pcbNeeded : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetPrinterDriverDirectoryW(LPCWSTR pName, LPCWSTR pEnvironment, DWORD Level, BYTE* pDriverDirectory, DWORD cbBuf, DWORD* pcbNeeded) #uselib "winspool.drv" #cfunc global GetPrinterDriverDirectoryW "GetPrinterDriverDirectoryW" wstr, wstr, int, intptr, int, intptr ; res = GetPrinterDriverDirectoryW(pName, pEnvironment, Level, varptr(pDriverDirectory), cbBuf, varptr(pcbNeeded)) ; pName : LPCWSTR optional -> "wstr" ; pEnvironment : LPCWSTR optional -> "wstr" ; Level : DWORD -> "int" ; pDriverDirectory : BYTE* optional, out -> "intptr" ; cbBuf : DWORD -> "int" ; pcbNeeded : DWORD* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winspool_drv = windows.NewLazySystemDLL("winspool.drv")
procGetPrinterDriverDirectoryW = winspool_drv.NewProc("GetPrinterDriverDirectoryW")
)
// pName (LPCWSTR optional), pEnvironment (LPCWSTR optional), Level (DWORD), pDriverDirectory (BYTE* optional, out), cbBuf (DWORD), pcbNeeded (DWORD* out)
r1, _, err := procGetPrinterDriverDirectoryW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pEnvironment))),
uintptr(Level),
uintptr(pDriverDirectory),
uintptr(cbBuf),
uintptr(pcbNeeded),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetPrinterDriverDirectoryW(
pName: PWideChar; // LPCWSTR optional
pEnvironment: PWideChar; // LPCWSTR optional
Level: DWORD; // DWORD
pDriverDirectory: Pointer; // BYTE* optional, out
cbBuf: DWORD; // DWORD
pcbNeeded: Pointer // DWORD* out
): BOOL; stdcall;
external 'winspool.drv' name 'GetPrinterDriverDirectoryW';result := DllCall("winspool.drv\GetPrinterDriverDirectoryW"
, "WStr", pName ; LPCWSTR optional
, "WStr", pEnvironment ; LPCWSTR optional
, "UInt", Level ; DWORD
, "Ptr", pDriverDirectory ; BYTE* optional, out
, "UInt", cbBuf ; DWORD
, "Ptr", pcbNeeded ; DWORD* out
, "Int") ; return: BOOL●GetPrinterDriverDirectoryW(pName, pEnvironment, Level, pDriverDirectory, cbBuf, pcbNeeded) = DLL("winspool.drv", "bool GetPrinterDriverDirectoryW(char*, char*, dword, void*, dword, void*)")
# 呼び出し: GetPrinterDriverDirectoryW(pName, pEnvironment, Level, pDriverDirectory, cbBuf, pcbNeeded)
# pName : LPCWSTR optional -> "char*"
# pEnvironment : LPCWSTR optional -> "char*"
# Level : DWORD -> "dword"
# pDriverDirectory : BYTE* optional, out -> "void*"
# cbBuf : DWORD -> "dword"
# pcbNeeded : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。