Win32 API 日本語リファレンス
ホームMedia.Audio.DirectSound › DirectSoundCreate

DirectSoundCreate

関数
DirectSoundデバイスオブジェクトを生成して初期化する。
DLLDSOUND.dll呼出規約winapi

シグネチャ

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

HRESULT DirectSoundCreate(
    const GUID* pcGuidDevice,   // optional
    IDirectSound** ppDS,
    IUnknown* pUnkOuter   // optional
);

パラメーター

名前方向
pcGuidDeviceGUID*inoptional
ppDSIDirectSound**out
pUnkOuterIUnknown*inoptional

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT DirectSoundCreate(
    const GUID* pcGuidDevice,   // optional
    IDirectSound** ppDS,
    IUnknown* pUnkOuter   // optional
);
[DllImport("DSOUND.dll", ExactSpelling = true)]
static extern int DirectSoundCreate(
    IntPtr pcGuidDevice,   // GUID* optional
    IntPtr ppDS,   // IDirectSound** out
    IntPtr pUnkOuter   // IUnknown* optional
);
<DllImport("DSOUND.dll", ExactSpelling:=True)>
Public Shared Function DirectSoundCreate(
    pcGuidDevice As IntPtr,   ' GUID* optional
    ppDS As IntPtr,   ' IDirectSound** out
    pUnkOuter As IntPtr   ' IUnknown* optional
) As Integer
End Function
' pcGuidDevice : GUID* optional
' ppDS : IDirectSound** out
' pUnkOuter : IUnknown* optional
Declare PtrSafe Function DirectSoundCreate Lib "dsound" ( _
    ByVal pcGuidDevice As LongPtr, _
    ByVal ppDS As LongPtr, _
    ByVal pUnkOuter As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DirectSoundCreate = ctypes.windll.dsound.DirectSoundCreate
DirectSoundCreate.restype = ctypes.c_int
DirectSoundCreate.argtypes = [
    ctypes.c_void_p,  # pcGuidDevice : GUID* optional
    ctypes.c_void_p,  # ppDS : IDirectSound** out
    ctypes.c_void_p,  # pUnkOuter : IUnknown* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('DSOUND.dll')
DirectSoundCreate = Fiddle::Function.new(
  lib['DirectSoundCreate'],
  [
    Fiddle::TYPE_VOIDP,  # pcGuidDevice : GUID* optional
    Fiddle::TYPE_VOIDP,  # ppDS : IDirectSound** out
    Fiddle::TYPE_VOIDP,  # pUnkOuter : IUnknown* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "dsound")]
extern "system" {
    fn DirectSoundCreate(
        pcGuidDevice: *const GUID,  // GUID* optional
        ppDS: *mut *mut core::ffi::c_void,  // IDirectSound** out
        pUnkOuter: *mut core::ffi::c_void  // IUnknown* optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("DSOUND.dll")]
public static extern int DirectSoundCreate(IntPtr pcGuidDevice, IntPtr ppDS, IntPtr pUnkOuter);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DSOUND_DirectSoundCreate' -Namespace Win32 -PassThru
# $api::DirectSoundCreate(pcGuidDevice, ppDS, pUnkOuter)
#uselib "DSOUND.dll"
#func global DirectSoundCreate "DirectSoundCreate" sptr, sptr, sptr
; DirectSoundCreate varptr(pcGuidDevice), ppDS, pUnkOuter   ; 戻り値は stat
; pcGuidDevice : GUID* optional -> "sptr"
; ppDS : IDirectSound** out -> "sptr"
; pUnkOuter : IUnknown* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "DSOUND.dll"
#cfunc global DirectSoundCreate "DirectSoundCreate" var, sptr, sptr
; res = DirectSoundCreate(pcGuidDevice, ppDS, pUnkOuter)
; pcGuidDevice : GUID* optional -> "var"
; ppDS : IDirectSound** out -> "sptr"
; pUnkOuter : IUnknown* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT DirectSoundCreate(GUID* pcGuidDevice, IDirectSound** ppDS, IUnknown* pUnkOuter)
#uselib "DSOUND.dll"
#cfunc global DirectSoundCreate "DirectSoundCreate" var, intptr, intptr
; res = DirectSoundCreate(pcGuidDevice, ppDS, pUnkOuter)
; pcGuidDevice : GUID* optional -> "var"
; ppDS : IDirectSound** out -> "intptr"
; pUnkOuter : IUnknown* optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dsound = windows.NewLazySystemDLL("DSOUND.dll")
	procDirectSoundCreate = dsound.NewProc("DirectSoundCreate")
)

// pcGuidDevice (GUID* optional), ppDS (IDirectSound** out), pUnkOuter (IUnknown* optional)
r1, _, err := procDirectSoundCreate.Call(
	uintptr(pcGuidDevice),
	uintptr(ppDS),
	uintptr(pUnkOuter),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function DirectSoundCreate(
  pcGuidDevice: PGUID;   // GUID* optional
  ppDS: Pointer;   // IDirectSound** out
  pUnkOuter: Pointer   // IUnknown* optional
): Integer; stdcall;
  external 'DSOUND.dll' name 'DirectSoundCreate';
result := DllCall("DSOUND\DirectSoundCreate"
    , "Ptr", pcGuidDevice   ; GUID* optional
    , "Ptr", ppDS   ; IDirectSound** out
    , "Ptr", pUnkOuter   ; IUnknown* optional
    , "Int")   ; return: HRESULT
●DirectSoundCreate(pcGuidDevice, ppDS, pUnkOuter) = DLL("DSOUND.dll", "int DirectSoundCreate(void*, void*, void*)")
# 呼び出し: DirectSoundCreate(pcGuidDevice, ppDS, pUnkOuter)
# pcGuidDevice : GUID* optional -> "void*"
# ppDS : IDirectSound** out -> "void*"
# pUnkOuter : IUnknown* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。