Win32 API 日本語リファレンス
ホームStorage.FileSystem › CreateTransactionManager

CreateTransactionManager

関数
KTMトランザクションマネージャーを新規作成する。
DLLktmw32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

HANDLE CreateTransactionManager(
    SECURITY_ATTRIBUTES* lpTransactionAttributes,
    LPWSTR LogFileName,
    DWORD CreateOptions,
    DWORD CommitStrength
);

パラメーター

名前方向説明
lpTransactionAttributesSECURITY_ATTRIBUTES*inoutTM オブジェクトに対するトランザクションの SECURITY_ATTRIBUTES (ACL) です。
LogFileNameLPWSTRinログ ファイルのストリーム名です。ストリームがログ内に存在しない場合は作成されます。揮発性 TM を作成するには、このパラメーターを NULL にし、CreateOptionsTRANSACTION_MANAGER_VOLATILE を指定する必要があります。この場合、トランザクション マネージャーは揮発性とみなされます。
CreateOptionsDWORDin

新しい TM の任意の属性です。

意味
TRANSACTION_MANAGER_VOLATILE
TM が揮発性であり、回復を実行しないことを示します。
CommitStrengthDWORDin予約済みです。ゼロを指定してください。

戻り値の型: HANDLE

公式ドキュメント

新しいトランザクション マネージャー (TM) オブジェクトを作成し、指定されたアクセス権を持つハンドルを返します。

戻り値

関数が成功した場合、戻り値はトランザクション マネージャーへのハンドルです。

関数が失敗した場合、戻り値は INVALID_HANDLE_VALUE です。拡張エラー情報を取得するには、GetLastError 関数を呼び出します。

次の一覧は、発生し得るエラー コードを示しています。

解説(Remarks)

この関数を呼び出した直後に、RecoverTransactionManager を呼び出す必要があります。

トランザクション マネージャーが揮発性の場合、すべてのリソース マネージャーも揮発性でなければなりません。

TM が正しく機能するためには、TM の作成後に RecoverTransactionManager を呼び出す必要があります。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

HANDLE CreateTransactionManager(
    SECURITY_ATTRIBUTES* lpTransactionAttributes,
    LPWSTR LogFileName,
    DWORD CreateOptions,
    DWORD CommitStrength
);
[DllImport("ktmw32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr CreateTransactionManager(
    IntPtr lpTransactionAttributes,   // SECURITY_ATTRIBUTES* in/out
    [MarshalAs(UnmanagedType.LPWStr)] string LogFileName,   // LPWSTR
    uint CreateOptions,   // DWORD
    uint CommitStrength   // DWORD
);
<DllImport("ktmw32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreateTransactionManager(
    lpTransactionAttributes As IntPtr,   ' SECURITY_ATTRIBUTES* in/out
    <MarshalAs(UnmanagedType.LPWStr)> LogFileName As String,   ' LPWSTR
    CreateOptions As UInteger,   ' DWORD
    CommitStrength As UInteger   ' DWORD
) As IntPtr
End Function
' lpTransactionAttributes : SECURITY_ATTRIBUTES* in/out
' LogFileName : LPWSTR
' CreateOptions : DWORD
' CommitStrength : DWORD
Declare PtrSafe Function CreateTransactionManager Lib "ktmw32" ( _
    ByVal lpTransactionAttributes As LongPtr, _
    ByVal LogFileName As LongPtr, _
    ByVal CreateOptions As Long, _
    ByVal CommitStrength As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateTransactionManager = ctypes.windll.ktmw32.CreateTransactionManager
CreateTransactionManager.restype = ctypes.c_void_p
CreateTransactionManager.argtypes = [
    ctypes.c_void_p,  # lpTransactionAttributes : SECURITY_ATTRIBUTES* in/out
    wintypes.LPCWSTR,  # LogFileName : LPWSTR
    wintypes.DWORD,  # CreateOptions : DWORD
    wintypes.DWORD,  # CommitStrength : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ktmw32.dll')
CreateTransactionManager = Fiddle::Function.new(
  lib['CreateTransactionManager'],
  [
    Fiddle::TYPE_VOIDP,  # lpTransactionAttributes : SECURITY_ATTRIBUTES* in/out
    Fiddle::TYPE_VOIDP,  # LogFileName : LPWSTR
    -Fiddle::TYPE_INT,  # CreateOptions : DWORD
    -Fiddle::TYPE_INT,  # CommitStrength : DWORD
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "ktmw32")]
extern "system" {
    fn CreateTransactionManager(
        lpTransactionAttributes: *mut SECURITY_ATTRIBUTES,  // SECURITY_ATTRIBUTES* in/out
        LogFileName: *mut u16,  // LPWSTR
        CreateOptions: u32,  // DWORD
        CommitStrength: u32  // DWORD
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ktmw32.dll", SetLastError = true)]
public static extern IntPtr CreateTransactionManager(IntPtr lpTransactionAttributes, [MarshalAs(UnmanagedType.LPWStr)] string LogFileName, uint CreateOptions, uint CommitStrength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ktmw32_CreateTransactionManager' -Namespace Win32 -PassThru
# $api::CreateTransactionManager(lpTransactionAttributes, LogFileName, CreateOptions, CommitStrength)
#uselib "ktmw32.dll"
#func global CreateTransactionManager "CreateTransactionManager" sptr, sptr, sptr, sptr
; CreateTransactionManager varptr(lpTransactionAttributes), LogFileName, CreateOptions, CommitStrength   ; 戻り値は stat
; lpTransactionAttributes : SECURITY_ATTRIBUTES* in/out -> "sptr"
; LogFileName : LPWSTR -> "sptr"
; CreateOptions : DWORD -> "sptr"
; CommitStrength : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ktmw32.dll"
#cfunc global CreateTransactionManager "CreateTransactionManager" var, wstr, int, int
; res = CreateTransactionManager(lpTransactionAttributes, LogFileName, CreateOptions, CommitStrength)
; lpTransactionAttributes : SECURITY_ATTRIBUTES* in/out -> "var"
; LogFileName : LPWSTR -> "wstr"
; CreateOptions : DWORD -> "int"
; CommitStrength : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HANDLE CreateTransactionManager(SECURITY_ATTRIBUTES* lpTransactionAttributes, LPWSTR LogFileName, DWORD CreateOptions, DWORD CommitStrength)
#uselib "ktmw32.dll"
#cfunc global CreateTransactionManager "CreateTransactionManager" var, wstr, int, int
; res = CreateTransactionManager(lpTransactionAttributes, LogFileName, CreateOptions, CommitStrength)
; lpTransactionAttributes : SECURITY_ATTRIBUTES* in/out -> "var"
; LogFileName : LPWSTR -> "wstr"
; CreateOptions : DWORD -> "int"
; CommitStrength : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ktmw32 = windows.NewLazySystemDLL("ktmw32.dll")
	procCreateTransactionManager = ktmw32.NewProc("CreateTransactionManager")
)

// lpTransactionAttributes (SECURITY_ATTRIBUTES* in/out), LogFileName (LPWSTR), CreateOptions (DWORD), CommitStrength (DWORD)
r1, _, err := procCreateTransactionManager.Call(
	uintptr(lpTransactionAttributes),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(LogFileName))),
	uintptr(CreateOptions),
	uintptr(CommitStrength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HANDLE
function CreateTransactionManager(
  lpTransactionAttributes: Pointer;   // SECURITY_ATTRIBUTES* in/out
  LogFileName: PWideChar;   // LPWSTR
  CreateOptions: DWORD;   // DWORD
  CommitStrength: DWORD   // DWORD
): THandle; stdcall;
  external 'ktmw32.dll' name 'CreateTransactionManager';
result := DllCall("ktmw32\CreateTransactionManager"
    , "Ptr", lpTransactionAttributes   ; SECURITY_ATTRIBUTES* in/out
    , "WStr", LogFileName   ; LPWSTR
    , "UInt", CreateOptions   ; DWORD
    , "UInt", CommitStrength   ; DWORD
    , "Ptr")   ; return: HANDLE
●CreateTransactionManager(lpTransactionAttributes, LogFileName, CreateOptions, CommitStrength) = DLL("ktmw32.dll", "void* CreateTransactionManager(void*, char*, dword, dword)")
# 呼び出し: CreateTransactionManager(lpTransactionAttributes, LogFileName, CreateOptions, CommitStrength)
# lpTransactionAttributes : SECURITY_ATTRIBUTES* in/out -> "void*"
# LogFileName : LPWSTR -> "char*"
# CreateOptions : DWORD -> "dword"
# CommitStrength : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "ktmw32" fn CreateTransactionManager(
    lpTransactionAttributes: [*c]SECURITY_ATTRIBUTES, // SECURITY_ATTRIBUTES* in/out
    LogFileName: [*c]const u16, // LPWSTR
    CreateOptions: u32, // DWORD
    CommitStrength: u32 // DWORD
) callconv(std.os.windows.WINAPI) ?*anyopaque;
proc CreateTransactionManager(
    lpTransactionAttributes: ptr SECURITY_ATTRIBUTES,  # SECURITY_ATTRIBUTES* in/out
    LogFileName: WideCString,  # LPWSTR
    CreateOptions: uint32,  # DWORD
    CommitStrength: uint32  # DWORD
): pointer {.importc: "CreateTransactionManager", stdcall, dynlib: "ktmw32.dll".}
pragma(lib, "ktmw32");
extern(Windows)
void* CreateTransactionManager(
    SECURITY_ATTRIBUTES* lpTransactionAttributes,   // SECURITY_ATTRIBUTES* in/out
    const(wchar)* LogFileName,   // LPWSTR
    uint CreateOptions,   // DWORD
    uint CommitStrength   // DWORD
);
ccall((:CreateTransactionManager, "ktmw32.dll"), stdcall, Ptr{Cvoid},
      (Ptr{SECURITY_ATTRIBUTES}, Cwstring, UInt32, UInt32),
      lpTransactionAttributes, LogFileName, CreateOptions, CommitStrength)
# lpTransactionAttributes : SECURITY_ATTRIBUTES* in/out -> Ptr{SECURITY_ATTRIBUTES}
# LogFileName : LPWSTR -> Cwstring
# CreateOptions : DWORD -> UInt32
# CommitStrength : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
void* CreateTransactionManager(
    void* lpTransactionAttributes,
    const uint16_t* LogFileName,
    uint32_t CreateOptions,
    uint32_t CommitStrength);
]]
local ktmw32 = ffi.load("ktmw32")
-- ktmw32.CreateTransactionManager(lpTransactionAttributes, LogFileName, CreateOptions, CommitStrength)
-- lpTransactionAttributes : SECURITY_ATTRIBUTES* in/out
-- LogFileName : LPWSTR
-- CreateOptions : DWORD
-- CommitStrength : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ktmw32.dll');
const CreateTransactionManager = lib.func('__stdcall', 'CreateTransactionManager', 'void *', ['void *', 'str16', 'uint32_t', 'uint32_t']);
// CreateTransactionManager(lpTransactionAttributes, LogFileName, CreateOptions, CommitStrength)
// lpTransactionAttributes : SECURITY_ATTRIBUTES* in/out -> 'void *'
// LogFileName : LPWSTR -> 'str16'
// CreateOptions : DWORD -> 'uint32_t'
// CommitStrength : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ktmw32.dll", {
  CreateTransactionManager: { parameters: ["pointer", "buffer", "u32", "u32"], result: "pointer" },
});
// lib.symbols.CreateTransactionManager(lpTransactionAttributes, LogFileName, CreateOptions, CommitStrength)
// lpTransactionAttributes : SECURITY_ATTRIBUTES* in/out -> "pointer"
// LogFileName : LPWSTR -> "buffer"
// CreateOptions : DWORD -> "u32"
// CommitStrength : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void* CreateTransactionManager(
    void* lpTransactionAttributes,
    const uint16_t* LogFileName,
    uint32_t CreateOptions,
    uint32_t CommitStrength);
C, "ktmw32.dll");
// $ffi->CreateTransactionManager(lpTransactionAttributes, LogFileName, CreateOptions, CommitStrength);
// lpTransactionAttributes : SECURITY_ATTRIBUTES* in/out
// LogFileName : LPWSTR
// CreateOptions : DWORD
// CommitStrength : 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 Ktmw32 extends StdCallLibrary {
    Ktmw32 INSTANCE = Native.load("ktmw32", Ktmw32.class);
    Pointer CreateTransactionManager(
        Pointer lpTransactionAttributes,   // SECURITY_ATTRIBUTES* in/out
        WString LogFileName,   // LPWSTR
        int CreateOptions,   // DWORD
        int CommitStrength   // DWORD
    );
}
@[Link("ktmw32")]
lib Libktmw32
  fun CreateTransactionManager = CreateTransactionManager(
    lpTransactionAttributes : SECURITY_ATTRIBUTES*,   # SECURITY_ATTRIBUTES* in/out
    LogFileName : UInt16*,   # LPWSTR
    CreateOptions : UInt32,   # DWORD
    CommitStrength : UInt32   # DWORD
  ) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef CreateTransactionManagerNative = Pointer<Void> Function(Pointer<Void>, Pointer<Utf16>, Uint32, Uint32);
typedef CreateTransactionManagerDart = Pointer<Void> Function(Pointer<Void>, Pointer<Utf16>, int, int);
final CreateTransactionManager = DynamicLibrary.open('ktmw32.dll')
    .lookupFunction<CreateTransactionManagerNative, CreateTransactionManagerDart>('CreateTransactionManager');
// lpTransactionAttributes : SECURITY_ATTRIBUTES* in/out -> Pointer<Void>
// LogFileName : LPWSTR -> Pointer<Utf16>
// CreateOptions : DWORD -> Uint32
// CommitStrength : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CreateTransactionManager(
  lpTransactionAttributes: Pointer;   // SECURITY_ATTRIBUTES* in/out
  LogFileName: PWideChar;   // LPWSTR
  CreateOptions: DWORD;   // DWORD
  CommitStrength: DWORD   // DWORD
): THandle; stdcall;
  external 'ktmw32.dll' name 'CreateTransactionManager';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CreateTransactionManager"
  c_CreateTransactionManager :: Ptr () -> CWString -> Word32 -> Word32 -> IO (Ptr ())
-- lpTransactionAttributes : SECURITY_ATTRIBUTES* in/out -> Ptr ()
-- LogFileName : LPWSTR -> CWString
-- CreateOptions : DWORD -> Word32
-- CommitStrength : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let createtransactionmanager =
  foreign "CreateTransactionManager"
    ((ptr void) @-> (ptr uint16_t) @-> uint32_t @-> uint32_t @-> returning (ptr void))
(* lpTransactionAttributes : SECURITY_ATTRIBUTES* in/out -> (ptr void) *)
(* LogFileName : LPWSTR -> (ptr uint16_t) *)
(* CreateOptions : DWORD -> uint32_t *)
(* CommitStrength : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library ktmw32 (t "ktmw32.dll"))
(cffi:use-foreign-library ktmw32)

(cffi:defcfun ("CreateTransactionManager" create-transaction-manager :convention :stdcall) :pointer
  (lp-transaction-attributes :pointer)   ; SECURITY_ATTRIBUTES* in/out
  (log-file-name (:string :encoding :utf-16le))   ; LPWSTR
  (create-options :uint32)   ; DWORD
  (commit-strength :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CreateTransactionManager = Win32::API::More->new('ktmw32',
    'HANDLE CreateTransactionManager(LPVOID lpTransactionAttributes, LPCWSTR LogFileName, DWORD CreateOptions, DWORD CommitStrength)');
# my $ret = $CreateTransactionManager->Call($lpTransactionAttributes, $LogFileName, $CreateOptions, $CommitStrength);
# lpTransactionAttributes : SECURITY_ATTRIBUTES* in/out -> LPVOID
# LogFileName : LPWSTR -> LPCWSTR
# CreateOptions : DWORD -> DWORD
# CommitStrength : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型