Win32 API 日本語リファレンス
ホームMedia.Multimedia › mciGetDeviceIDA

mciGetDeviceIDA

関数
デバイス名からMCIデバイスIDを取得する(ANSI版)。
DLLWINMM.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

// WINMM.dll  (ANSI / -A)
#include <windows.h>

DWORD mciGetDeviceIDA(
    LPCSTR pszDevice
);

パラメーター

名前方向説明
pszDeviceLPCSTRinデバイスIDを取得する対象のデバイス名またはエイリアス文字列(ANSI)。

戻り値の型: DWORD

各言語での呼び出し定義

// WINMM.dll  (ANSI / -A)
#include <windows.h>

DWORD mciGetDeviceIDA(
    LPCSTR pszDevice
);
[DllImport("WINMM.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint mciGetDeviceIDA(
    [MarshalAs(UnmanagedType.LPStr)] string pszDevice   // LPCSTR
);
<DllImport("WINMM.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function mciGetDeviceIDA(
    <MarshalAs(UnmanagedType.LPStr)> pszDevice As String   ' LPCSTR
) As UInteger
End Function
' pszDevice : LPCSTR
Declare PtrSafe Function mciGetDeviceIDA Lib "winmm" ( _
    ByVal pszDevice As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

mciGetDeviceIDA = ctypes.windll.winmm.mciGetDeviceIDA
mciGetDeviceIDA.restype = wintypes.DWORD
mciGetDeviceIDA.argtypes = [
    wintypes.LPCSTR,  # pszDevice : LPCSTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WINMM.dll')
mciGetDeviceIDA = Fiddle::Function.new(
  lib['mciGetDeviceIDA'],
  [
    Fiddle::TYPE_VOIDP,  # pszDevice : LPCSTR
  ],
  -Fiddle::TYPE_INT)
#[link(name = "winmm")]
extern "system" {
    fn mciGetDeviceIDA(
        pszDevice: *const u8  // LPCSTR
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WINMM.dll", CharSet = CharSet.Ansi)]
public static extern uint mciGetDeviceIDA([MarshalAs(UnmanagedType.LPStr)] string pszDevice);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINMM_mciGetDeviceIDA' -Namespace Win32 -PassThru
# $api::mciGetDeviceIDA(pszDevice)
#uselib "WINMM.dll"
#func global mciGetDeviceIDA "mciGetDeviceIDA" sptr
; mciGetDeviceIDA pszDevice   ; 戻り値は stat
; pszDevice : LPCSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WINMM.dll"
#cfunc global mciGetDeviceIDA "mciGetDeviceIDA" str
; res = mciGetDeviceIDA(pszDevice)
; pszDevice : LPCSTR -> "str"
; DWORD mciGetDeviceIDA(LPCSTR pszDevice)
#uselib "WINMM.dll"
#cfunc global mciGetDeviceIDA "mciGetDeviceIDA" str
; res = mciGetDeviceIDA(pszDevice)
; pszDevice : LPCSTR -> "str"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winmm = windows.NewLazySystemDLL("WINMM.dll")
	procmciGetDeviceIDA = winmm.NewProc("mciGetDeviceIDA")
)

// pszDevice (LPCSTR)
r1, _, err := procmciGetDeviceIDA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pszDevice))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function mciGetDeviceIDA(
  pszDevice: PAnsiChar   // LPCSTR
): DWORD; stdcall;
  external 'WINMM.dll' name 'mciGetDeviceIDA';
result := DllCall("WINMM\mciGetDeviceIDA"
    , "AStr", pszDevice   ; LPCSTR
    , "UInt")   ; return: DWORD
●mciGetDeviceIDA(pszDevice) = DLL("WINMM.dll", "dword mciGetDeviceIDA(char*)")
# 呼び出し: mciGetDeviceIDA(pszDevice)
# pszDevice : LPCSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "winmm" fn mciGetDeviceIDA(
    pszDevice: [*c]const u8 // LPCSTR
) callconv(std.os.windows.WINAPI) u32;
proc mciGetDeviceIDA(
    pszDevice: cstring  # LPCSTR
): uint32 {.importc: "mciGetDeviceIDA", stdcall, dynlib: "WINMM.dll".}
pragma(lib, "winmm");
extern(Windows)
uint mciGetDeviceIDA(
    const(char)* pszDevice   // LPCSTR
);
ccall((:mciGetDeviceIDA, "WINMM.dll"), stdcall, UInt32,
      (Cstring,),
      pszDevice)
# pszDevice : LPCSTR -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t mciGetDeviceIDA(
    const char* pszDevice);
]]
local winmm = ffi.load("winmm")
-- winmm.mciGetDeviceIDA(pszDevice)
-- pszDevice : LPCSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WINMM.dll');
const mciGetDeviceIDA = lib.func('__stdcall', 'mciGetDeviceIDA', 'uint32_t', ['str']);
// mciGetDeviceIDA(pszDevice)
// pszDevice : LPCSTR -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WINMM.dll", {
  mciGetDeviceIDA: { parameters: ["buffer"], result: "u32" },
});
// lib.symbols.mciGetDeviceIDA(pszDevice)
// pszDevice : LPCSTR -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t mciGetDeviceIDA(
    const char* pszDevice);
C, "WINMM.dll");
// $ffi->mciGetDeviceIDA(pszDevice);
// pszDevice : LPCSTR
// 構造体/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, W32APIOptions.ASCII_OPTIONS);
    int mciGetDeviceIDA(
        String pszDevice   // LPCSTR
    );
}
@[Link("winmm")]
lib LibWINMM
  fun mciGetDeviceIDA = mciGetDeviceIDA(
    pszDevice : UInt8*   # LPCSTR
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef mciGetDeviceIDANative = Uint32 Function(Pointer<Utf8>);
typedef mciGetDeviceIDADart = int Function(Pointer<Utf8>);
final mciGetDeviceIDA = DynamicLibrary.open('WINMM.dll')
    .lookupFunction<mciGetDeviceIDANative, mciGetDeviceIDADart>('mciGetDeviceIDA');
// pszDevice : LPCSTR -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function mciGetDeviceIDA(
  pszDevice: PAnsiChar   // LPCSTR
): DWORD; stdcall;
  external 'WINMM.dll' name 'mciGetDeviceIDA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "mciGetDeviceIDA"
  c_mciGetDeviceIDA :: CString -> IO Word32
-- pszDevice : LPCSTR -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let mcigetdeviceida =
  foreign "mciGetDeviceIDA"
    (string @-> returning uint32_t)
(* pszDevice : LPCSTR -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library winmm (t "WINMM.dll"))
(cffi:use-foreign-library winmm)

(cffi:defcfun ("mciGetDeviceIDA" mci-get-device-ida :convention :stdcall) :uint32
  (psz-device :string))   ; LPCSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $mciGetDeviceIDA = Win32::API::More->new('WINMM',
    'DWORD mciGetDeviceIDA(LPCSTR pszDevice)');
# my $ret = $mciGetDeviceIDA->Call($pszDevice);
# pszDevice : LPCSTR -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い