ホーム › Devices.Communication › GetCommProperties
GetCommProperties
関数通信デバイスのプロパティ情報をCOMMPROP構造体に取得する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL GetCommProperties(
HANDLE hFile,
COMMPROP* lpCommProp
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hFile | HANDLE | in |
| lpCommProp | COMMPROP* | inout |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL GetCommProperties(
HANDLE hFile,
COMMPROP* lpCommProp
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool GetCommProperties(
IntPtr hFile, // HANDLE
IntPtr lpCommProp // COMMPROP* in/out
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetCommProperties(
hFile As IntPtr, ' HANDLE
lpCommProp As IntPtr ' COMMPROP* in/out
) As Boolean
End Function' hFile : HANDLE
' lpCommProp : COMMPROP* in/out
Declare PtrSafe Function GetCommProperties Lib "kernel32" ( _
ByVal hFile As LongPtr, _
ByVal lpCommProp As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetCommProperties = ctypes.windll.kernel32.GetCommProperties
GetCommProperties.restype = wintypes.BOOL
GetCommProperties.argtypes = [
wintypes.HANDLE, # hFile : HANDLE
ctypes.c_void_p, # lpCommProp : COMMPROP* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
GetCommProperties = Fiddle::Function.new(
lib['GetCommProperties'],
[
Fiddle::TYPE_VOIDP, # hFile : HANDLE
Fiddle::TYPE_VOIDP, # lpCommProp : COMMPROP* in/out
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn GetCommProperties(
hFile: *mut core::ffi::c_void, // HANDLE
lpCommProp: *mut COMMPROP // COMMPROP* in/out
) -> 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 GetCommProperties(IntPtr hFile, IntPtr lpCommProp);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetCommProperties' -Namespace Win32 -PassThru
# $api::GetCommProperties(hFile, lpCommProp)#uselib "KERNEL32.dll"
#func global GetCommProperties "GetCommProperties" sptr, sptr
; GetCommProperties hFile, varptr(lpCommProp) ; 戻り値は stat
; hFile : HANDLE -> "sptr"
; lpCommProp : COMMPROP* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global GetCommProperties "GetCommProperties" sptr, var ; res = GetCommProperties(hFile, lpCommProp) ; hFile : HANDLE -> "sptr" ; lpCommProp : COMMPROP* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global GetCommProperties "GetCommProperties" sptr, sptr ; res = GetCommProperties(hFile, varptr(lpCommProp)) ; hFile : HANDLE -> "sptr" ; lpCommProp : COMMPROP* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetCommProperties(HANDLE hFile, COMMPROP* lpCommProp) #uselib "KERNEL32.dll" #cfunc global GetCommProperties "GetCommProperties" intptr, var ; res = GetCommProperties(hFile, lpCommProp) ; hFile : HANDLE -> "intptr" ; lpCommProp : COMMPROP* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetCommProperties(HANDLE hFile, COMMPROP* lpCommProp) #uselib "KERNEL32.dll" #cfunc global GetCommProperties "GetCommProperties" intptr, intptr ; res = GetCommProperties(hFile, varptr(lpCommProp)) ; hFile : HANDLE -> "intptr" ; lpCommProp : COMMPROP* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGetCommProperties = kernel32.NewProc("GetCommProperties")
)
// hFile (HANDLE), lpCommProp (COMMPROP* in/out)
r1, _, err := procGetCommProperties.Call(
uintptr(hFile),
uintptr(lpCommProp),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetCommProperties(
hFile: THandle; // HANDLE
lpCommProp: Pointer // COMMPROP* in/out
): BOOL; stdcall;
external 'KERNEL32.dll' name 'GetCommProperties';result := DllCall("KERNEL32\GetCommProperties"
, "Ptr", hFile ; HANDLE
, "Ptr", lpCommProp ; COMMPROP* in/out
, "Int") ; return: BOOL●GetCommProperties(hFile, lpCommProp) = DLL("KERNEL32.dll", "bool GetCommProperties(void*, void*)")
# 呼び出し: GetCommProperties(hFile, lpCommProp)
# hFile : HANDLE -> "void*"
# lpCommProp : COMMPROP* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。