Win32 API 日本語リファレンス
ホームDevices.Tapi › phoneGetGain

phoneGetGain

関数
電話のマイク入力のゲイン設定を取得する。
DLLTAPI32.dll呼出規約winapi

シグネチャ

// TAPI32.dll
#include <windows.h>

INT phoneGetGain(
    DWORD hPhone,
    DWORD dwHookSwitchDev,
    DWORD* lpdwGain
);

パラメーター

名前方向説明
hPhoneDWORDinマイク入力ゲインを取得する対象の電話デバイスのハンドル。
dwHookSwitchDevDWORDin対象のフックスイッチデバイスを示すフラグ(送話器/ヘッドセット/スピーカー)。
lpdwGainDWORD*inout現在のゲイン値(0x00000000~0x0000FFFF)を受け取る出力先ポインタ。

戻り値の型: INT

各言語での呼び出し定義

// TAPI32.dll
#include <windows.h>

INT phoneGetGain(
    DWORD hPhone,
    DWORD dwHookSwitchDev,
    DWORD* lpdwGain
);
[DllImport("TAPI32.dll", ExactSpelling = true)]
static extern int phoneGetGain(
    uint hPhone,   // DWORD
    uint dwHookSwitchDev,   // DWORD
    ref uint lpdwGain   // DWORD* in/out
);
<DllImport("TAPI32.dll", ExactSpelling:=True)>
Public Shared Function phoneGetGain(
    hPhone As UInteger,   ' DWORD
    dwHookSwitchDev As UInteger,   ' DWORD
    ByRef lpdwGain As UInteger   ' DWORD* in/out
) As Integer
End Function
' hPhone : DWORD
' dwHookSwitchDev : DWORD
' lpdwGain : DWORD* in/out
Declare PtrSafe Function phoneGetGain Lib "tapi32" ( _
    ByVal hPhone As Long, _
    ByVal dwHookSwitchDev As Long, _
    ByRef lpdwGain As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

phoneGetGain = ctypes.windll.tapi32.phoneGetGain
phoneGetGain.restype = ctypes.c_int
phoneGetGain.argtypes = [
    wintypes.DWORD,  # hPhone : DWORD
    wintypes.DWORD,  # dwHookSwitchDev : DWORD
    ctypes.POINTER(wintypes.DWORD),  # lpdwGain : DWORD* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('TAPI32.dll')
phoneGetGain = Fiddle::Function.new(
  lib['phoneGetGain'],
  [
    -Fiddle::TYPE_INT,  # hPhone : DWORD
    -Fiddle::TYPE_INT,  # dwHookSwitchDev : DWORD
    Fiddle::TYPE_VOIDP,  # lpdwGain : DWORD* in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "tapi32")]
extern "system" {
    fn phoneGetGain(
        hPhone: u32,  // DWORD
        dwHookSwitchDev: u32,  // DWORD
        lpdwGain: *mut u32  // DWORD* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("TAPI32.dll")]
public static extern int phoneGetGain(uint hPhone, uint dwHookSwitchDev, ref uint lpdwGain);
"@
$api = Add-Type -MemberDefinition $sig -Name 'TAPI32_phoneGetGain' -Namespace Win32 -PassThru
# $api::phoneGetGain(hPhone, dwHookSwitchDev, lpdwGain)
#uselib "TAPI32.dll"
#func global phoneGetGain "phoneGetGain" sptr, sptr, sptr
; phoneGetGain hPhone, dwHookSwitchDev, varptr(lpdwGain)   ; 戻り値は stat
; hPhone : DWORD -> "sptr"
; dwHookSwitchDev : DWORD -> "sptr"
; lpdwGain : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "TAPI32.dll"
#cfunc global phoneGetGain "phoneGetGain" int, int, var
; res = phoneGetGain(hPhone, dwHookSwitchDev, lpdwGain)
; hPhone : DWORD -> "int"
; dwHookSwitchDev : DWORD -> "int"
; lpdwGain : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT phoneGetGain(DWORD hPhone, DWORD dwHookSwitchDev, DWORD* lpdwGain)
#uselib "TAPI32.dll"
#cfunc global phoneGetGain "phoneGetGain" int, int, var
; res = phoneGetGain(hPhone, dwHookSwitchDev, lpdwGain)
; hPhone : DWORD -> "int"
; dwHookSwitchDev : DWORD -> "int"
; lpdwGain : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	tapi32 = windows.NewLazySystemDLL("TAPI32.dll")
	procphoneGetGain = tapi32.NewProc("phoneGetGain")
)

// hPhone (DWORD), dwHookSwitchDev (DWORD), lpdwGain (DWORD* in/out)
r1, _, err := procphoneGetGain.Call(
	uintptr(hPhone),
	uintptr(dwHookSwitchDev),
	uintptr(lpdwGain),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function phoneGetGain(
  hPhone: DWORD;   // DWORD
  dwHookSwitchDev: DWORD;   // DWORD
  lpdwGain: Pointer   // DWORD* in/out
): Integer; stdcall;
  external 'TAPI32.dll' name 'phoneGetGain';
result := DllCall("TAPI32\phoneGetGain"
    , "UInt", hPhone   ; DWORD
    , "UInt", dwHookSwitchDev   ; DWORD
    , "Ptr", lpdwGain   ; DWORD* in/out
    , "Int")   ; return: INT
●phoneGetGain(hPhone, dwHookSwitchDev, lpdwGain) = DLL("TAPI32.dll", "int phoneGetGain(dword, dword, void*)")
# 呼び出し: phoneGetGain(hPhone, dwHookSwitchDev, lpdwGain)
# hPhone : DWORD -> "dword"
# dwHookSwitchDev : DWORD -> "dword"
# lpdwGain : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "tapi32" fn phoneGetGain(
    hPhone: u32, // DWORD
    dwHookSwitchDev: u32, // DWORD
    lpdwGain: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;
proc phoneGetGain(
    hPhone: uint32,  # DWORD
    dwHookSwitchDev: uint32,  # DWORD
    lpdwGain: ptr uint32  # DWORD* in/out
): int32 {.importc: "phoneGetGain", stdcall, dynlib: "TAPI32.dll".}
pragma(lib, "tapi32");
extern(Windows)
int phoneGetGain(
    uint hPhone,   // DWORD
    uint dwHookSwitchDev,   // DWORD
    uint* lpdwGain   // DWORD* in/out
);
ccall((:phoneGetGain, "TAPI32.dll"), stdcall, Int32,
      (UInt32, UInt32, Ptr{UInt32}),
      hPhone, dwHookSwitchDev, lpdwGain)
# hPhone : DWORD -> UInt32
# dwHookSwitchDev : DWORD -> UInt32
# lpdwGain : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t phoneGetGain(
    uint32_t hPhone,
    uint32_t dwHookSwitchDev,
    uint32_t* lpdwGain);
]]
local tapi32 = ffi.load("tapi32")
-- tapi32.phoneGetGain(hPhone, dwHookSwitchDev, lpdwGain)
-- hPhone : DWORD
-- dwHookSwitchDev : DWORD
-- lpdwGain : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('TAPI32.dll');
const phoneGetGain = lib.func('__stdcall', 'phoneGetGain', 'int32_t', ['uint32_t', 'uint32_t', 'uint32_t *']);
// phoneGetGain(hPhone, dwHookSwitchDev, lpdwGain)
// hPhone : DWORD -> 'uint32_t'
// dwHookSwitchDev : DWORD -> 'uint32_t'
// lpdwGain : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("TAPI32.dll", {
  phoneGetGain: { parameters: ["u32", "u32", "pointer"], result: "i32" },
});
// lib.symbols.phoneGetGain(hPhone, dwHookSwitchDev, lpdwGain)
// hPhone : DWORD -> "u32"
// dwHookSwitchDev : DWORD -> "u32"
// lpdwGain : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t phoneGetGain(
    uint32_t hPhone,
    uint32_t dwHookSwitchDev,
    uint32_t* lpdwGain);
C, "TAPI32.dll");
// $ffi->phoneGetGain(hPhone, dwHookSwitchDev, lpdwGain);
// hPhone : DWORD
// dwHookSwitchDev : DWORD
// lpdwGain : DWORD* in/out
// 構造体/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 Tapi32 extends StdCallLibrary {
    Tapi32 INSTANCE = Native.load("tapi32", Tapi32.class);
    int phoneGetGain(
        int hPhone,   // DWORD
        int dwHookSwitchDev,   // DWORD
        IntByReference lpdwGain   // DWORD* in/out
    );
}
@[Link("tapi32")]
lib LibTAPI32
  fun phoneGetGain = phoneGetGain(
    hPhone : UInt32,   # DWORD
    dwHookSwitchDev : UInt32,   # DWORD
    lpdwGain : UInt32*   # DWORD* in/out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef phoneGetGainNative = Int32 Function(Uint32, Uint32, Pointer<Uint32>);
typedef phoneGetGainDart = int Function(int, int, Pointer<Uint32>);
final phoneGetGain = DynamicLibrary.open('TAPI32.dll')
    .lookupFunction<phoneGetGainNative, phoneGetGainDart>('phoneGetGain');
// hPhone : DWORD -> Uint32
// dwHookSwitchDev : DWORD -> Uint32
// lpdwGain : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function phoneGetGain(
  hPhone: DWORD;   // DWORD
  dwHookSwitchDev: DWORD;   // DWORD
  lpdwGain: Pointer   // DWORD* in/out
): Integer; stdcall;
  external 'TAPI32.dll' name 'phoneGetGain';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "phoneGetGain"
  c_phoneGetGain :: Word32 -> Word32 -> Ptr Word32 -> IO Int32
-- hPhone : DWORD -> Word32
-- dwHookSwitchDev : DWORD -> Word32
-- lpdwGain : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let phonegetgain =
  foreign "phoneGetGain"
    (uint32_t @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* hPhone : DWORD -> uint32_t *)
(* dwHookSwitchDev : DWORD -> uint32_t *)
(* lpdwGain : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library tapi32 (t "TAPI32.dll"))
(cffi:use-foreign-library tapi32)

(cffi:defcfun ("phoneGetGain" phone-get-gain :convention :stdcall) :int32
  (h-phone :uint32)   ; DWORD
  (dw-hook-switch-dev :uint32)   ; DWORD
  (lpdw-gain :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $phoneGetGain = Win32::API::More->new('TAPI32',
    'int phoneGetGain(DWORD hPhone, DWORD dwHookSwitchDev, LPVOID lpdwGain)');
# my $ret = $phoneGetGain->Call($hPhone, $dwHookSwitchDev, $lpdwGain);
# hPhone : DWORD -> DWORD
# dwHookSwitchDev : DWORD -> DWORD
# lpdwGain : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。