SHGetDriveMedia
関数ドライブが対応するメディアの種類を取得する。
シグネチャ
// SHELL32.dll
#include <windows.h>
HRESULT SHGetDriveMedia(
LPCWSTR pszDrive,
DWORD* pdwMediaContent
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pszDrive | LPCWSTR | in |
| pdwMediaContent | DWORD* | out |
戻り値の型: HRESULT
各言語での呼び出し定義
// SHELL32.dll
#include <windows.h>
HRESULT SHGetDriveMedia(
LPCWSTR pszDrive,
DWORD* pdwMediaContent
);[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern int SHGetDriveMedia(
[MarshalAs(UnmanagedType.LPWStr)] string pszDrive, // LPCWSTR
out uint pdwMediaContent // DWORD* out
);<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function SHGetDriveMedia(
<MarshalAs(UnmanagedType.LPWStr)> pszDrive As String, ' LPCWSTR
<Out> ByRef pdwMediaContent As UInteger ' DWORD* out
) As Integer
End Function' pszDrive : LPCWSTR
' pdwMediaContent : DWORD* out
Declare PtrSafe Function SHGetDriveMedia Lib "shell32" ( _
ByVal pszDrive As LongPtr, _
ByRef pdwMediaContent As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SHGetDriveMedia = ctypes.windll.shell32.SHGetDriveMedia
SHGetDriveMedia.restype = ctypes.c_int
SHGetDriveMedia.argtypes = [
wintypes.LPCWSTR, # pszDrive : LPCWSTR
ctypes.POINTER(wintypes.DWORD), # pdwMediaContent : DWORD* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
SHGetDriveMedia = Fiddle::Function.new(
lib['SHGetDriveMedia'],
[
Fiddle::TYPE_VOIDP, # pszDrive : LPCWSTR
Fiddle::TYPE_VOIDP, # pdwMediaContent : DWORD* out
],
Fiddle::TYPE_INT)#[link(name = "shell32")]
extern "system" {
fn SHGetDriveMedia(
pszDrive: *const u16, // LPCWSTR
pdwMediaContent: *mut u32 // DWORD* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHELL32.dll")]
public static extern int SHGetDriveMedia([MarshalAs(UnmanagedType.LPWStr)] string pszDrive, out uint pdwMediaContent);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHGetDriveMedia' -Namespace Win32 -PassThru
# $api::SHGetDriveMedia(pszDrive, pdwMediaContent)#uselib "SHELL32.dll"
#func global SHGetDriveMedia "SHGetDriveMedia" sptr, sptr
; SHGetDriveMedia pszDrive, varptr(pdwMediaContent) ; 戻り値は stat
; pszDrive : LPCWSTR -> "sptr"
; pdwMediaContent : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHELL32.dll" #cfunc global SHGetDriveMedia "SHGetDriveMedia" wstr, var ; res = SHGetDriveMedia(pszDrive, pdwMediaContent) ; pszDrive : LPCWSTR -> "wstr" ; pdwMediaContent : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHELL32.dll" #cfunc global SHGetDriveMedia "SHGetDriveMedia" wstr, sptr ; res = SHGetDriveMedia(pszDrive, varptr(pdwMediaContent)) ; pszDrive : LPCWSTR -> "wstr" ; pdwMediaContent : DWORD* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT SHGetDriveMedia(LPCWSTR pszDrive, DWORD* pdwMediaContent) #uselib "SHELL32.dll" #cfunc global SHGetDriveMedia "SHGetDriveMedia" wstr, var ; res = SHGetDriveMedia(pszDrive, pdwMediaContent) ; pszDrive : LPCWSTR -> "wstr" ; pdwMediaContent : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT SHGetDriveMedia(LPCWSTR pszDrive, DWORD* pdwMediaContent) #uselib "SHELL32.dll" #cfunc global SHGetDriveMedia "SHGetDriveMedia" wstr, intptr ; res = SHGetDriveMedia(pszDrive, varptr(pdwMediaContent)) ; pszDrive : LPCWSTR -> "wstr" ; pdwMediaContent : DWORD* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procSHGetDriveMedia = shell32.NewProc("SHGetDriveMedia")
)
// pszDrive (LPCWSTR), pdwMediaContent (DWORD* out)
r1, _, err := procSHGetDriveMedia.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszDrive))),
uintptr(pdwMediaContent),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction SHGetDriveMedia(
pszDrive: PWideChar; // LPCWSTR
pdwMediaContent: Pointer // DWORD* out
): Integer; stdcall;
external 'SHELL32.dll' name 'SHGetDriveMedia';result := DllCall("SHELL32\SHGetDriveMedia"
, "WStr", pszDrive ; LPCWSTR
, "Ptr", pdwMediaContent ; DWORD* out
, "Int") ; return: HRESULT●SHGetDriveMedia(pszDrive, pdwMediaContent) = DLL("SHELL32.dll", "int SHGetDriveMedia(char*, void*)")
# 呼び出し: SHGetDriveMedia(pszDrive, pdwMediaContent)
# pszDrive : LPCWSTR -> "char*"
# pdwMediaContent : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。