Win32 API 日本語リファレンス
ホームSystem.WindowsProgramming › _lopen

_lopen

関数
既存ファイルを開きファイルハンドルを返す旧式関数。
DLLKERNEL32.dll呼出規約winapi

シグネチャ

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

INT _lopen(
    LPCSTR lpPathName,
    INT iReadWrite
);

パラメーター

名前方向
lpPathNameLPCSTRin
iReadWriteINTin

戻り値の型: INT

各言語での呼び出し定義

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

INT _lopen(
    LPCSTR lpPathName,
    INT iReadWrite
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern int _lopen(
    [MarshalAs(UnmanagedType.LPStr)] string lpPathName,   // LPCSTR
    int iReadWrite   // INT
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function _lopen(
    <MarshalAs(UnmanagedType.LPStr)> lpPathName As String,   ' LPCSTR
    iReadWrite As Integer   ' INT
) As Integer
End Function
' lpPathName : LPCSTR
' iReadWrite : INT
Declare PtrSafe Function _lopen Lib "kernel32" ( _
    ByVal lpPathName As String, _
    ByVal iReadWrite As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

_lopen = ctypes.windll.kernel32._lopen
_lopen.restype = ctypes.c_int
_lopen.argtypes = [
    wintypes.LPCSTR,  # lpPathName : LPCSTR
    ctypes.c_int,  # iReadWrite : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
_lopen = Fiddle::Function.new(
  lib['_lopen'],
  [
    Fiddle::TYPE_VOIDP,  # lpPathName : LPCSTR
    Fiddle::TYPE_INT,  # iReadWrite : INT
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn _lopen(
        lpPathName: *const u8,  // LPCSTR
        iReadWrite: i32  // INT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll")]
public static extern int _lopen([MarshalAs(UnmanagedType.LPStr)] string lpPathName, int iReadWrite);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32__lopen' -Namespace Win32 -PassThru
# $api::_lopen(lpPathName, iReadWrite)
#uselib "KERNEL32.dll"
#func global _lopen "_lopen" sptr, sptr
; _lopen lpPathName, iReadWrite   ; 戻り値は stat
; lpPathName : LPCSTR -> "sptr"
; iReadWrite : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global _lopen "_lopen" str, int
; res = _lopen(lpPathName, iReadWrite)
; lpPathName : LPCSTR -> "str"
; iReadWrite : INT -> "int"
; INT _lopen(LPCSTR lpPathName, INT iReadWrite)
#uselib "KERNEL32.dll"
#cfunc global _lopen "_lopen" str, int
; res = _lopen(lpPathName, iReadWrite)
; lpPathName : LPCSTR -> "str"
; iReadWrite : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	proc_lopen = kernel32.NewProc("_lopen")
)

// lpPathName (LPCSTR), iReadWrite (INT)
r1, _, err := proc_lopen.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpPathName))),
	uintptr(iReadWrite),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function _lopen(
  lpPathName: PAnsiChar;   // LPCSTR
  iReadWrite: Integer   // INT
): Integer; stdcall;
  external 'KERNEL32.dll' name '_lopen';
result := DllCall("KERNEL32\_lopen"
    , "AStr", lpPathName   ; LPCSTR
    , "Int", iReadWrite   ; INT
    , "Int")   ; return: INT
●_lopen(lpPathName, iReadWrite) = DLL("KERNEL32.dll", "int _lopen(char*, int)")
# 呼び出し: _lopen(lpPathName, iReadWrite)
# lpPathName : LPCSTR -> "char*"
# iReadWrite : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。