ホーム › Devices.Communication › EscapeCommFunction
EscapeCommFunction
関数通信デバイスに拡張機能の指示を発行する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL EscapeCommFunction(
HANDLE hFile,
ESCAPE_COMM_FUNCTION dwFunc
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hFile | HANDLE | in |
| dwFunc | ESCAPE_COMM_FUNCTION | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL EscapeCommFunction(
HANDLE hFile,
ESCAPE_COMM_FUNCTION dwFunc
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool EscapeCommFunction(
IntPtr hFile, // HANDLE
uint dwFunc // ESCAPE_COMM_FUNCTION
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function EscapeCommFunction(
hFile As IntPtr, ' HANDLE
dwFunc As UInteger ' ESCAPE_COMM_FUNCTION
) As Boolean
End Function' hFile : HANDLE
' dwFunc : ESCAPE_COMM_FUNCTION
Declare PtrSafe Function EscapeCommFunction Lib "kernel32" ( _
ByVal hFile As LongPtr, _
ByVal dwFunc As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
EscapeCommFunction = ctypes.windll.kernel32.EscapeCommFunction
EscapeCommFunction.restype = wintypes.BOOL
EscapeCommFunction.argtypes = [
wintypes.HANDLE, # hFile : HANDLE
wintypes.DWORD, # dwFunc : ESCAPE_COMM_FUNCTION
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
EscapeCommFunction = Fiddle::Function.new(
lib['EscapeCommFunction'],
[
Fiddle::TYPE_VOIDP, # hFile : HANDLE
-Fiddle::TYPE_INT, # dwFunc : ESCAPE_COMM_FUNCTION
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn EscapeCommFunction(
hFile: *mut core::ffi::c_void, // HANDLE
dwFunc: u32 // ESCAPE_COMM_FUNCTION
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern bool EscapeCommFunction(IntPtr hFile, uint dwFunc);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_EscapeCommFunction' -Namespace Win32 -PassThru
# $api::EscapeCommFunction(hFile, dwFunc)#uselib "KERNEL32.dll"
#func global EscapeCommFunction "EscapeCommFunction" sptr, sptr
; EscapeCommFunction hFile, dwFunc ; 戻り値は stat
; hFile : HANDLE -> "sptr"
; dwFunc : ESCAPE_COMM_FUNCTION -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global EscapeCommFunction "EscapeCommFunction" sptr, int
; res = EscapeCommFunction(hFile, dwFunc)
; hFile : HANDLE -> "sptr"
; dwFunc : ESCAPE_COMM_FUNCTION -> "int"; BOOL EscapeCommFunction(HANDLE hFile, ESCAPE_COMM_FUNCTION dwFunc)
#uselib "KERNEL32.dll"
#cfunc global EscapeCommFunction "EscapeCommFunction" intptr, int
; res = EscapeCommFunction(hFile, dwFunc)
; hFile : HANDLE -> "intptr"
; dwFunc : ESCAPE_COMM_FUNCTION -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procEscapeCommFunction = kernel32.NewProc("EscapeCommFunction")
)
// hFile (HANDLE), dwFunc (ESCAPE_COMM_FUNCTION)
r1, _, err := procEscapeCommFunction.Call(
uintptr(hFile),
uintptr(dwFunc),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction EscapeCommFunction(
hFile: THandle; // HANDLE
dwFunc: DWORD // ESCAPE_COMM_FUNCTION
): BOOL; stdcall;
external 'KERNEL32.dll' name 'EscapeCommFunction';result := DllCall("KERNEL32\EscapeCommFunction"
, "Ptr", hFile ; HANDLE
, "UInt", dwFunc ; ESCAPE_COMM_FUNCTION
, "Int") ; return: BOOL●EscapeCommFunction(hFile, dwFunc) = DLL("KERNEL32.dll", "bool EscapeCommFunction(void*, dword)")
# 呼び出し: EscapeCommFunction(hFile, dwFunc)
# hFile : HANDLE -> "void*"
# dwFunc : ESCAPE_COMM_FUNCTION -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。