timeSetEvent
関数指定間隔でコールバックを呼び出すマルチメディアタイマーを開始する。
シグネチャ
// WINMM.dll
#include <windows.h>
DWORD timeSetEvent(
DWORD uDelay,
DWORD uResolution,
LPTIMECALLBACK fptc,
UINT_PTR dwUser,
DWORD fuEvent
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| uDelay | DWORD | in | イベント発生までの遅延または周期(ミリ秒単位)。 |
| uResolution | DWORD | in | タイマーイベントの許容分解能(ミリ秒単位)。0で可能な限り高精度にする。 |
| fptc | LPTIMECALLBACK | in | 時間到来時に呼ばれるコールバック関数LPTIMECALLBACK。TIME_CALLBACK_EVENT指定時はイベントハンドル。 |
| dwUser | UINT_PTR | in | コールバックへ渡されるアプリ定義のユーザーデータ。任意の値を指定可能。 |
| fuEvent | DWORD | in | イベント種別フラグ。TIME_ONESHOT/TIME_PERIODICやコールバック方式を指定する。 |
戻り値の型: DWORD
各言語での呼び出し定義
// WINMM.dll
#include <windows.h>
DWORD timeSetEvent(
DWORD uDelay,
DWORD uResolution,
LPTIMECALLBACK fptc,
UINT_PTR dwUser,
DWORD fuEvent
);[DllImport("WINMM.dll", ExactSpelling = true)]
static extern uint timeSetEvent(
uint uDelay, // DWORD
uint uResolution, // DWORD
IntPtr fptc, // LPTIMECALLBACK
UIntPtr dwUser, // UINT_PTR
uint fuEvent // DWORD
);<DllImport("WINMM.dll", ExactSpelling:=True)>
Public Shared Function timeSetEvent(
uDelay As UInteger, ' DWORD
uResolution As UInteger, ' DWORD
fptc As IntPtr, ' LPTIMECALLBACK
dwUser As UIntPtr, ' UINT_PTR
fuEvent As UInteger ' DWORD
) As UInteger
End Function' uDelay : DWORD
' uResolution : DWORD
' fptc : LPTIMECALLBACK
' dwUser : UINT_PTR
' fuEvent : DWORD
Declare PtrSafe Function timeSetEvent Lib "winmm" ( _
ByVal uDelay As Long, _
ByVal uResolution As Long, _
ByVal fptc As LongPtr, _
ByVal dwUser As LongPtr, _
ByVal fuEvent As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
timeSetEvent = ctypes.windll.winmm.timeSetEvent
timeSetEvent.restype = wintypes.DWORD
timeSetEvent.argtypes = [
wintypes.DWORD, # uDelay : DWORD
wintypes.DWORD, # uResolution : DWORD
ctypes.c_void_p, # fptc : LPTIMECALLBACK
ctypes.c_size_t, # dwUser : UINT_PTR
wintypes.DWORD, # fuEvent : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WINMM.dll')
timeSetEvent = Fiddle::Function.new(
lib['timeSetEvent'],
[
-Fiddle::TYPE_INT, # uDelay : DWORD
-Fiddle::TYPE_INT, # uResolution : DWORD
Fiddle::TYPE_VOIDP, # fptc : LPTIMECALLBACK
Fiddle::TYPE_UINTPTR_T, # dwUser : UINT_PTR
-Fiddle::TYPE_INT, # fuEvent : DWORD
],
-Fiddle::TYPE_INT)#[link(name = "winmm")]
extern "system" {
fn timeSetEvent(
uDelay: u32, // DWORD
uResolution: u32, // DWORD
fptc: *const core::ffi::c_void, // LPTIMECALLBACK
dwUser: usize, // UINT_PTR
fuEvent: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WINMM.dll")]
public static extern uint timeSetEvent(uint uDelay, uint uResolution, IntPtr fptc, UIntPtr dwUser, uint fuEvent);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINMM_timeSetEvent' -Namespace Win32 -PassThru
# $api::timeSetEvent(uDelay, uResolution, fptc, dwUser, fuEvent)#uselib "WINMM.dll"
#func global timeSetEvent "timeSetEvent" sptr, sptr, sptr, sptr, sptr
; timeSetEvent uDelay, uResolution, fptc, dwUser, fuEvent ; 戻り値は stat
; uDelay : DWORD -> "sptr"
; uResolution : DWORD -> "sptr"
; fptc : LPTIMECALLBACK -> "sptr"
; dwUser : UINT_PTR -> "sptr"
; fuEvent : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WINMM.dll"
#cfunc global timeSetEvent "timeSetEvent" int, int, sptr, sptr, int
; res = timeSetEvent(uDelay, uResolution, fptc, dwUser, fuEvent)
; uDelay : DWORD -> "int"
; uResolution : DWORD -> "int"
; fptc : LPTIMECALLBACK -> "sptr"
; dwUser : UINT_PTR -> "sptr"
; fuEvent : DWORD -> "int"; DWORD timeSetEvent(DWORD uDelay, DWORD uResolution, LPTIMECALLBACK fptc, UINT_PTR dwUser, DWORD fuEvent)
#uselib "WINMM.dll"
#cfunc global timeSetEvent "timeSetEvent" int, int, intptr, intptr, int
; res = timeSetEvent(uDelay, uResolution, fptc, dwUser, fuEvent)
; uDelay : DWORD -> "int"
; uResolution : DWORD -> "int"
; fptc : LPTIMECALLBACK -> "intptr"
; dwUser : UINT_PTR -> "intptr"
; fuEvent : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winmm = windows.NewLazySystemDLL("WINMM.dll")
proctimeSetEvent = winmm.NewProc("timeSetEvent")
)
// uDelay (DWORD), uResolution (DWORD), fptc (LPTIMECALLBACK), dwUser (UINT_PTR), fuEvent (DWORD)
r1, _, err := proctimeSetEvent.Call(
uintptr(uDelay),
uintptr(uResolution),
uintptr(fptc),
uintptr(dwUser),
uintptr(fuEvent),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction timeSetEvent(
uDelay: DWORD; // DWORD
uResolution: DWORD; // DWORD
fptc: Pointer; // LPTIMECALLBACK
dwUser: NativeUInt; // UINT_PTR
fuEvent: DWORD // DWORD
): DWORD; stdcall;
external 'WINMM.dll' name 'timeSetEvent';result := DllCall("WINMM\timeSetEvent"
, "UInt", uDelay ; DWORD
, "UInt", uResolution ; DWORD
, "Ptr", fptc ; LPTIMECALLBACK
, "UPtr", dwUser ; UINT_PTR
, "UInt", fuEvent ; DWORD
, "UInt") ; return: DWORD●timeSetEvent(uDelay, uResolution, fptc, dwUser, fuEvent) = DLL("WINMM.dll", "dword timeSetEvent(dword, dword, void*, int, dword)")
# 呼び出し: timeSetEvent(uDelay, uResolution, fptc, dwUser, fuEvent)
# uDelay : DWORD -> "dword"
# uResolution : DWORD -> "dword"
# fptc : LPTIMECALLBACK -> "void*"
# dwUser : UINT_PTR -> "int"
# fuEvent : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "winmm" fn timeSetEvent(
uDelay: u32, // DWORD
uResolution: u32, // DWORD
fptc: ?*anyopaque, // LPTIMECALLBACK
dwUser: usize, // UINT_PTR
fuEvent: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;proc timeSetEvent(
uDelay: uint32, # DWORD
uResolution: uint32, # DWORD
fptc: pointer, # LPTIMECALLBACK
dwUser: uint, # UINT_PTR
fuEvent: uint32 # DWORD
): uint32 {.importc: "timeSetEvent", stdcall, dynlib: "WINMM.dll".}pragma(lib, "winmm");
extern(Windows)
uint timeSetEvent(
uint uDelay, // DWORD
uint uResolution, // DWORD
void* fptc, // LPTIMECALLBACK
size_t dwUser, // UINT_PTR
uint fuEvent // DWORD
);ccall((:timeSetEvent, "WINMM.dll"), stdcall, UInt32,
(UInt32, UInt32, Ptr{Cvoid}, Csize_t, UInt32),
uDelay, uResolution, fptc, dwUser, fuEvent)
# uDelay : DWORD -> UInt32
# uResolution : DWORD -> UInt32
# fptc : LPTIMECALLBACK -> Ptr{Cvoid}
# dwUser : UINT_PTR -> Csize_t
# fuEvent : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t timeSetEvent(
uint32_t uDelay,
uint32_t uResolution,
void* fptc,
uintptr_t dwUser,
uint32_t fuEvent);
]]
local winmm = ffi.load("winmm")
-- winmm.timeSetEvent(uDelay, uResolution, fptc, dwUser, fuEvent)
-- uDelay : DWORD
-- uResolution : DWORD
-- fptc : LPTIMECALLBACK
-- dwUser : UINT_PTR
-- fuEvent : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WINMM.dll');
const timeSetEvent = lib.func('__stdcall', 'timeSetEvent', 'uint32_t', ['uint32_t', 'uint32_t', 'void *', 'uintptr_t', 'uint32_t']);
// timeSetEvent(uDelay, uResolution, fptc, dwUser, fuEvent)
// uDelay : DWORD -> 'uint32_t'
// uResolution : DWORD -> 'uint32_t'
// fptc : LPTIMECALLBACK -> 'void *'
// dwUser : UINT_PTR -> 'uintptr_t'
// fuEvent : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("WINMM.dll", {
timeSetEvent: { parameters: ["u32", "u32", "pointer", "usize", "u32"], result: "u32" },
});
// lib.symbols.timeSetEvent(uDelay, uResolution, fptc, dwUser, fuEvent)
// uDelay : DWORD -> "u32"
// uResolution : DWORD -> "u32"
// fptc : LPTIMECALLBACK -> "pointer"
// dwUser : UINT_PTR -> "usize"
// fuEvent : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t timeSetEvent(
uint32_t uDelay,
uint32_t uResolution,
void* fptc,
size_t dwUser,
uint32_t fuEvent);
C, "WINMM.dll");
// $ffi->timeSetEvent(uDelay, uResolution, fptc, dwUser, fuEvent);
// uDelay : DWORD
// uResolution : DWORD
// fptc : LPTIMECALLBACK
// dwUser : UINT_PTR
// fuEvent : DWORD
// 構造体/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);
int timeSetEvent(
int uDelay, // DWORD
int uResolution, // DWORD
Callback fptc, // LPTIMECALLBACK
long dwUser, // UINT_PTR
int fuEvent // DWORD
);
}@[Link("winmm")]
lib LibWINMM
fun timeSetEvent = timeSetEvent(
uDelay : UInt32, # DWORD
uResolution : UInt32, # DWORD
fptc : Void*, # LPTIMECALLBACK
dwUser : LibC::SizeT, # UINT_PTR
fuEvent : UInt32 # DWORD
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef timeSetEventNative = Uint32 Function(Uint32, Uint32, Pointer<Void>, UintPtr, Uint32);
typedef timeSetEventDart = int Function(int, int, Pointer<Void>, int, int);
final timeSetEvent = DynamicLibrary.open('WINMM.dll')
.lookupFunction<timeSetEventNative, timeSetEventDart>('timeSetEvent');
// uDelay : DWORD -> Uint32
// uResolution : DWORD -> Uint32
// fptc : LPTIMECALLBACK -> Pointer<Void>
// dwUser : UINT_PTR -> UintPtr
// fuEvent : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function timeSetEvent(
uDelay: DWORD; // DWORD
uResolution: DWORD; // DWORD
fptc: Pointer; // LPTIMECALLBACK
dwUser: NativeUInt; // UINT_PTR
fuEvent: DWORD // DWORD
): DWORD; stdcall;
external 'WINMM.dll' name 'timeSetEvent';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "timeSetEvent"
c_timeSetEvent :: Word32 -> Word32 -> Ptr () -> CUIntPtr -> Word32 -> IO Word32
-- uDelay : DWORD -> Word32
-- uResolution : DWORD -> Word32
-- fptc : LPTIMECALLBACK -> Ptr ()
-- dwUser : UINT_PTR -> CUIntPtr
-- fuEvent : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let timesetevent =
foreign "timeSetEvent"
(uint32_t @-> uint32_t @-> (ptr void) @-> size_t @-> uint32_t @-> returning uint32_t)
(* uDelay : DWORD -> uint32_t *)
(* uResolution : DWORD -> uint32_t *)
(* fptc : LPTIMECALLBACK -> (ptr void) *)
(* dwUser : UINT_PTR -> size_t *)
(* fuEvent : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library winmm (t "WINMM.dll"))
(cffi:use-foreign-library winmm)
(cffi:defcfun ("timeSetEvent" time-set-event :convention :stdcall) :uint32
(u-delay :uint32) ; DWORD
(u-resolution :uint32) ; DWORD
(fptc :pointer) ; LPTIMECALLBACK
(dw-user :uint64) ; UINT_PTR
(fu-event :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $timeSetEvent = Win32::API::More->new('WINMM',
'DWORD timeSetEvent(DWORD uDelay, DWORD uResolution, LPVOID fptc, WPARAM dwUser, DWORD fuEvent)');
# my $ret = $timeSetEvent->Call($uDelay, $uResolution, $fptc, $dwUser, $fuEvent);
# uDelay : DWORD -> DWORD
# uResolution : DWORD -> DWORD
# fptc : LPTIMECALLBACK -> LPVOID
# dwUser : UINT_PTR -> WPARAM
# fuEvent : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。関連項目
使用する型