ホーム › Media.Multimedia › OpenDriver
OpenDriver
関数インストール可能ドライバーを開く。
シグネチャ
// WINMM.dll
#include <windows.h>
HDRVR OpenDriver(
LPCWSTR szDriverName,
LPCWSTR szSectionName,
LPARAM lParam2
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| szDriverName | LPCWSTR | in | インストール可能ドライバーのファイル名、またはそのインストール可能ドライバーに関連付けられたレジストリ値の名前を指定する、null で終わるワイド文字列のアドレスです。(この値は、ドライバーのインストール時に事前に設定されている必要があります。) |
| szSectionName | LPCWSTR | in | lpDriverName パラメーターで指定されたレジストリ値を含むレジストリキーの名前を指定する、null で終わるワイド文字列のアドレスです。lpSectionName が NULL の場合、レジストリキーは Drivers32 であると見なされます。 |
| lParam2 | LPARAM | in | 32 ビットのドライバー固有の値です。この値は、インストール可能ドライバーの DriverProc 関数に lParam2 パラメーターとして渡されます。 |
戻り値の型: HDRVR
公式ドキュメント
インストール可能ドライバーのインスタンスを開き、ドライバーの既定の設定またはドライバー固有の値を使用してインスタンスを初期化します。
戻り値
成功した場合はインストール可能ドライバーインスタンスのハンドルを返し、それ以外の場合は NULL を返します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WINMM.dll
#include <windows.h>
HDRVR OpenDriver(
LPCWSTR szDriverName,
LPCWSTR szSectionName,
LPARAM lParam2
);[DllImport("WINMM.dll", ExactSpelling = true)]
static extern IntPtr OpenDriver(
[MarshalAs(UnmanagedType.LPWStr)] string szDriverName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string szSectionName, // LPCWSTR
IntPtr lParam2 // LPARAM
);<DllImport("WINMM.dll", ExactSpelling:=True)>
Public Shared Function OpenDriver(
<MarshalAs(UnmanagedType.LPWStr)> szDriverName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> szSectionName As String, ' LPCWSTR
lParam2 As IntPtr ' LPARAM
) As IntPtr
End Function' szDriverName : LPCWSTR
' szSectionName : LPCWSTR
' lParam2 : LPARAM
Declare PtrSafe Function OpenDriver Lib "winmm" ( _
ByVal szDriverName As LongPtr, _
ByVal szSectionName As LongPtr, _
ByVal lParam2 As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
OpenDriver = ctypes.windll.winmm.OpenDriver
OpenDriver.restype = ctypes.c_void_p
OpenDriver.argtypes = [
wintypes.LPCWSTR, # szDriverName : LPCWSTR
wintypes.LPCWSTR, # szSectionName : LPCWSTR
ctypes.c_ssize_t, # lParam2 : LPARAM
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WINMM.dll')
OpenDriver = Fiddle::Function.new(
lib['OpenDriver'],
[
Fiddle::TYPE_VOIDP, # szDriverName : LPCWSTR
Fiddle::TYPE_VOIDP, # szSectionName : LPCWSTR
Fiddle::TYPE_INTPTR_T, # lParam2 : LPARAM
],
Fiddle::TYPE_VOIDP)#[link(name = "winmm")]
extern "system" {
fn OpenDriver(
szDriverName: *const u16, // LPCWSTR
szSectionName: *const u16, // LPCWSTR
lParam2: isize // LPARAM
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WINMM.dll")]
public static extern IntPtr OpenDriver([MarshalAs(UnmanagedType.LPWStr)] string szDriverName, [MarshalAs(UnmanagedType.LPWStr)] string szSectionName, IntPtr lParam2);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINMM_OpenDriver' -Namespace Win32 -PassThru
# $api::OpenDriver(szDriverName, szSectionName, lParam2)#uselib "WINMM.dll"
#func global OpenDriver "OpenDriver" sptr, sptr, sptr
; OpenDriver szDriverName, szSectionName, lParam2 ; 戻り値は stat
; szDriverName : LPCWSTR -> "sptr"
; szSectionName : LPCWSTR -> "sptr"
; lParam2 : LPARAM -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WINMM.dll"
#cfunc global OpenDriver "OpenDriver" wstr, wstr, sptr
; res = OpenDriver(szDriverName, szSectionName, lParam2)
; szDriverName : LPCWSTR -> "wstr"
; szSectionName : LPCWSTR -> "wstr"
; lParam2 : LPARAM -> "sptr"; HDRVR OpenDriver(LPCWSTR szDriverName, LPCWSTR szSectionName, LPARAM lParam2)
#uselib "WINMM.dll"
#cfunc global OpenDriver "OpenDriver" wstr, wstr, intptr
; res = OpenDriver(szDriverName, szSectionName, lParam2)
; szDriverName : LPCWSTR -> "wstr"
; szSectionName : LPCWSTR -> "wstr"
; lParam2 : LPARAM -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winmm = windows.NewLazySystemDLL("WINMM.dll")
procOpenDriver = winmm.NewProc("OpenDriver")
)
// szDriverName (LPCWSTR), szSectionName (LPCWSTR), lParam2 (LPARAM)
r1, _, err := procOpenDriver.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szDriverName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szSectionName))),
uintptr(lParam2),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HDRVRfunction OpenDriver(
szDriverName: PWideChar; // LPCWSTR
szSectionName: PWideChar; // LPCWSTR
lParam2: NativeInt // LPARAM
): THandle; stdcall;
external 'WINMM.dll' name 'OpenDriver';result := DllCall("WINMM\OpenDriver"
, "WStr", szDriverName ; LPCWSTR
, "WStr", szSectionName ; LPCWSTR
, "Ptr", lParam2 ; LPARAM
, "Ptr") ; return: HDRVR●OpenDriver(szDriverName, szSectionName, lParam2) = DLL("WINMM.dll", "void* OpenDriver(char*, char*, int)")
# 呼び出し: OpenDriver(szDriverName, szSectionName, lParam2)
# szDriverName : LPCWSTR -> "char*"
# szSectionName : LPCWSTR -> "char*"
# lParam2 : LPARAM -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "winmm" fn OpenDriver(
szDriverName: [*c]const u16, // LPCWSTR
szSectionName: [*c]const u16, // LPCWSTR
lParam2: isize // LPARAM
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc OpenDriver(
szDriverName: WideCString, # LPCWSTR
szSectionName: WideCString, # LPCWSTR
lParam2: int # LPARAM
): pointer {.importc: "OpenDriver", stdcall, dynlib: "WINMM.dll".}pragma(lib, "winmm");
extern(Windows)
void* OpenDriver(
const(wchar)* szDriverName, // LPCWSTR
const(wchar)* szSectionName, // LPCWSTR
ptrdiff_t lParam2 // LPARAM
);ccall((:OpenDriver, "WINMM.dll"), stdcall, Ptr{Cvoid},
(Cwstring, Cwstring, Int),
szDriverName, szSectionName, lParam2)
# szDriverName : LPCWSTR -> Cwstring
# szSectionName : LPCWSTR -> Cwstring
# lParam2 : LPARAM -> Int
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* OpenDriver(
const uint16_t* szDriverName,
const uint16_t* szSectionName,
intptr_t lParam2);
]]
local winmm = ffi.load("winmm")
-- winmm.OpenDriver(szDriverName, szSectionName, lParam2)
-- szDriverName : LPCWSTR
-- szSectionName : LPCWSTR
-- lParam2 : LPARAM
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WINMM.dll');
const OpenDriver = lib.func('__stdcall', 'OpenDriver', 'void *', ['str16', 'str16', 'intptr_t']);
// OpenDriver(szDriverName, szSectionName, lParam2)
// szDriverName : LPCWSTR -> 'str16'
// szSectionName : LPCWSTR -> 'str16'
// lParam2 : LPARAM -> 'intptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WINMM.dll", {
OpenDriver: { parameters: ["buffer", "buffer", "isize"], result: "pointer" },
});
// lib.symbols.OpenDriver(szDriverName, szSectionName, lParam2)
// szDriverName : LPCWSTR -> "buffer"
// szSectionName : LPCWSTR -> "buffer"
// lParam2 : LPARAM -> "isize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* OpenDriver(
const uint16_t* szDriverName,
const uint16_t* szSectionName,
intptr_t lParam2);
C, "WINMM.dll");
// $ffi->OpenDriver(szDriverName, szSectionName, lParam2);
// szDriverName : LPCWSTR
// szSectionName : LPCWSTR
// lParam2 : LPARAM
// 構造体/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 Winmm extends StdCallLibrary {
Winmm INSTANCE = Native.load("winmm", Winmm.class);
Pointer OpenDriver(
WString szDriverName, // LPCWSTR
WString szSectionName, // LPCWSTR
long lParam2 // LPARAM
);
}@[Link("winmm")]
lib LibWINMM
fun OpenDriver = OpenDriver(
szDriverName : UInt16*, # LPCWSTR
szSectionName : UInt16*, # LPCWSTR
lParam2 : LibC::SSizeT # LPARAM
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef OpenDriverNative = Pointer<Void> Function(Pointer<Utf16>, Pointer<Utf16>, IntPtr);
typedef OpenDriverDart = Pointer<Void> Function(Pointer<Utf16>, Pointer<Utf16>, int);
final OpenDriver = DynamicLibrary.open('WINMM.dll')
.lookupFunction<OpenDriverNative, OpenDriverDart>('OpenDriver');
// szDriverName : LPCWSTR -> Pointer<Utf16>
// szSectionName : LPCWSTR -> Pointer<Utf16>
// lParam2 : LPARAM -> IntPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function OpenDriver(
szDriverName: PWideChar; // LPCWSTR
szSectionName: PWideChar; // LPCWSTR
lParam2: NativeInt // LPARAM
): THandle; stdcall;
external 'WINMM.dll' name 'OpenDriver';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "OpenDriver"
c_OpenDriver :: CWString -> CWString -> CIntPtr -> IO (Ptr ())
-- szDriverName : LPCWSTR -> CWString
-- szSectionName : LPCWSTR -> CWString
-- lParam2 : LPARAM -> CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let opendriver =
foreign "OpenDriver"
((ptr uint16_t) @-> (ptr uint16_t) @-> intptr_t @-> returning (ptr void))
(* szDriverName : LPCWSTR -> (ptr uint16_t) *)
(* szSectionName : LPCWSTR -> (ptr uint16_t) *)
(* lParam2 : LPARAM -> intptr_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library winmm (t "WINMM.dll"))
(cffi:use-foreign-library winmm)
(cffi:defcfun ("OpenDriver" open-driver :convention :stdcall) :pointer
(sz-driver-name (:string :encoding :utf-16le)) ; LPCWSTR
(sz-section-name (:string :encoding :utf-16le)) ; LPCWSTR
(l-param2 :int64)) ; LPARAM
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $OpenDriver = Win32::API::More->new('WINMM',
'HANDLE OpenDriver(LPCWSTR szDriverName, LPCWSTR szSectionName, LPARAM lParam2)');
# my $ret = $OpenDriver->Call($szDriverName, $szSectionName, $lParam2);
# szDriverName : LPCWSTR -> LPCWSTR
# szSectionName : LPCWSTR -> LPCWSTR
# lParam2 : LPARAM -> LPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。