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

SetCommBreak

関数
通信デバイスの送信回線を中断状態(ブレーク)にする。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetCommBreak(
    HANDLE hFile
);

パラメーター

名前方向
hFileHANDLEin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetCommBreak(
    HANDLE hFile
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetCommBreak(
    IntPtr hFile   // HANDLE
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetCommBreak(
    hFile As IntPtr   ' HANDLE
) As Boolean
End Function
' hFile : HANDLE
Declare PtrSafe Function SetCommBreak Lib "kernel32" ( _
    ByVal hFile As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetCommBreak = ctypes.windll.kernel32.SetCommBreak
SetCommBreak.restype = wintypes.BOOL
SetCommBreak.argtypes = [
    wintypes.HANDLE,  # hFile : HANDLE
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
SetCommBreak = Fiddle::Function.new(
  lib['SetCommBreak'],
  [
    Fiddle::TYPE_VOIDP,  # hFile : HANDLE
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn SetCommBreak(
        hFile: *mut core::ffi::c_void  // HANDLE
    ) -> 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 SetCommBreak(IntPtr hFile);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetCommBreak' -Namespace Win32 -PassThru
# $api::SetCommBreak(hFile)
#uselib "KERNEL32.dll"
#func global SetCommBreak "SetCommBreak" sptr
; SetCommBreak hFile   ; 戻り値は stat
; hFile : HANDLE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global SetCommBreak "SetCommBreak" sptr
; res = SetCommBreak(hFile)
; hFile : HANDLE -> "sptr"
; BOOL SetCommBreak(HANDLE hFile)
#uselib "KERNEL32.dll"
#cfunc global SetCommBreak "SetCommBreak" intptr
; res = SetCommBreak(hFile)
; hFile : HANDLE -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetCommBreak = kernel32.NewProc("SetCommBreak")
)

// hFile (HANDLE)
r1, _, err := procSetCommBreak.Call(
	uintptr(hFile),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetCommBreak(
  hFile: THandle   // HANDLE
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'SetCommBreak';
result := DllCall("KERNEL32\SetCommBreak"
    , "Ptr", hFile   ; HANDLE
    , "Int")   ; return: BOOL
●SetCommBreak(hFile) = DLL("KERNEL32.dll", "bool SetCommBreak(void*)")
# 呼び出し: SetCommBreak(hFile)
# hFile : HANDLE -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。