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

CreateResourceManager

関数
KTMリソースマネージャーを新規作成する。
DLLktmw32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

HANDLE CreateResourceManager(
    SECURITY_ATTRIBUTES* lpResourceManagerAttributes,
    GUID* ResourceManagerId,
    DWORD CreateOptions,
    HANDLE TmHandle,
    LPWSTR Description   // optional
);

パラメーター

名前方向説明
lpResourceManagerAttributesSECURITY_ATTRIBUTES*inoutリソース マネージャーのセキュリティ属性を含む SECURITY_ATTRIBUTES 構造体へのポインターです。既定の属性を取得するには NULL を指定します。
ResourceManagerIdGUID*inoutリソース マネージャーの GUID へのポインターです。このパラメーターは必須であり、NULL にすることはできません。
CreateOptionsDWORDin

新しい RM の省略可能な属性です。

意味
RESOURCE_MANAGER_VOLATILE
RM が揮発性 (volatile) であり、回復を実行しないことを示します。
TmHandleHANDLEinこの RM のトランザクションを管理する TM へのハンドルです。
DescriptionLPWSTRinoptionalこの RM の説明です。

戻り値の型: HANDLE

公式ドキュメント

新しいリソース マネージャー (RM) オブジェクトを作成し、その RM をトランザクション マネージャー (TM) に関連付けます。

戻り値

関数が成功した場合、戻り値は RM へのハンドルです。

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

以下のリストは、発生する可能性のあるエラー コードを示します。

解説(Remarks)

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

RM は、その RM がエンリストしたトランザクションに関する TM 通知のエンドポイントです。

RM は通常は永続的 (persistent) であり、システム障害の後、特定の操作を実行するには再度開く必要があります。揮発性 (volatile) または一時的 (transient) な RM は、CreateResourceManager 関数を呼び出して RESOURCE_MANAGER_VOLATILE を指定することで作成できます。揮発性 RM は回復操作を実行しませんが、トランザクションに関する通知は必要とします。

持続性 (durable) のある TM 上に揮発性 RM を作成することはできますが、揮発性 TM 上に持続性のある RM を作成することはできません。

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

各言語での呼び出し定義

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

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

CreateResourceManager = ctypes.windll.ktmw32.CreateResourceManager
CreateResourceManager.restype = ctypes.c_void_p
CreateResourceManager.argtypes = [
    ctypes.c_void_p,  # lpResourceManagerAttributes : SECURITY_ATTRIBUTES* in/out
    ctypes.c_void_p,  # ResourceManagerId : GUID* in/out
    wintypes.DWORD,  # CreateOptions : DWORD
    wintypes.HANDLE,  # TmHandle : HANDLE
    wintypes.LPCWSTR,  # Description : LPWSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ktmw32.dll')
CreateResourceManager = Fiddle::Function.new(
  lib['CreateResourceManager'],
  [
    Fiddle::TYPE_VOIDP,  # lpResourceManagerAttributes : SECURITY_ATTRIBUTES* in/out
    Fiddle::TYPE_VOIDP,  # ResourceManagerId : GUID* in/out
    -Fiddle::TYPE_INT,  # CreateOptions : DWORD
    Fiddle::TYPE_VOIDP,  # TmHandle : HANDLE
    Fiddle::TYPE_VOIDP,  # Description : LPWSTR optional
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "ktmw32")]
extern "system" {
    fn CreateResourceManager(
        lpResourceManagerAttributes: *mut SECURITY_ATTRIBUTES,  // SECURITY_ATTRIBUTES* in/out
        ResourceManagerId: *mut GUID,  // GUID* in/out
        CreateOptions: u32,  // DWORD
        TmHandle: *mut core::ffi::c_void,  // HANDLE
        Description: *mut u16  // LPWSTR optional
    ) -> *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 CreateResourceManager(IntPtr lpResourceManagerAttributes, ref Guid ResourceManagerId, uint CreateOptions, IntPtr TmHandle, [MarshalAs(UnmanagedType.LPWStr)] string Description);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ktmw32_CreateResourceManager' -Namespace Win32 -PassThru
# $api::CreateResourceManager(lpResourceManagerAttributes, ResourceManagerId, CreateOptions, TmHandle, Description)
#uselib "ktmw32.dll"
#func global CreateResourceManager "CreateResourceManager" sptr, sptr, sptr, sptr, sptr
; CreateResourceManager varptr(lpResourceManagerAttributes), varptr(ResourceManagerId), CreateOptions, TmHandle, Description   ; 戻り値は stat
; lpResourceManagerAttributes : SECURITY_ATTRIBUTES* in/out -> "sptr"
; ResourceManagerId : GUID* in/out -> "sptr"
; CreateOptions : DWORD -> "sptr"
; TmHandle : HANDLE -> "sptr"
; Description : LPWSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ktmw32.dll"
#cfunc global CreateResourceManager "CreateResourceManager" var, var, int, sptr, wstr
; res = CreateResourceManager(lpResourceManagerAttributes, ResourceManagerId, CreateOptions, TmHandle, Description)
; lpResourceManagerAttributes : SECURITY_ATTRIBUTES* in/out -> "var"
; ResourceManagerId : GUID* in/out -> "var"
; CreateOptions : DWORD -> "int"
; TmHandle : HANDLE -> "sptr"
; Description : LPWSTR optional -> "wstr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HANDLE CreateResourceManager(SECURITY_ATTRIBUTES* lpResourceManagerAttributes, GUID* ResourceManagerId, DWORD CreateOptions, HANDLE TmHandle, LPWSTR Description)
#uselib "ktmw32.dll"
#cfunc global CreateResourceManager "CreateResourceManager" var, var, int, intptr, wstr
; res = CreateResourceManager(lpResourceManagerAttributes, ResourceManagerId, CreateOptions, TmHandle, Description)
; lpResourceManagerAttributes : SECURITY_ATTRIBUTES* in/out -> "var"
; ResourceManagerId : GUID* in/out -> "var"
; CreateOptions : DWORD -> "int"
; TmHandle : HANDLE -> "intptr"
; Description : LPWSTR optional -> "wstr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ktmw32 = windows.NewLazySystemDLL("ktmw32.dll")
	procCreateResourceManager = ktmw32.NewProc("CreateResourceManager")
)

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

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

typedef CreateResourceManagerNative = Pointer<Void> Function(Pointer<Void>, Pointer<Void>, Uint32, Pointer<Void>, Pointer<Utf16>);
typedef CreateResourceManagerDart = Pointer<Void> Function(Pointer<Void>, Pointer<Void>, int, Pointer<Void>, Pointer<Utf16>);
final CreateResourceManager = DynamicLibrary.open('ktmw32.dll')
    .lookupFunction<CreateResourceManagerNative, CreateResourceManagerDart>('CreateResourceManager');
// lpResourceManagerAttributes : SECURITY_ATTRIBUTES* in/out -> Pointer<Void>
// ResourceManagerId : GUID* in/out -> Pointer<Void>
// CreateOptions : DWORD -> Uint32
// TmHandle : HANDLE -> Pointer<Void>
// Description : LPWSTR optional -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CreateResourceManager(
  lpResourceManagerAttributes: Pointer;   // SECURITY_ATTRIBUTES* in/out
  ResourceManagerId: PGUID;   // GUID* in/out
  CreateOptions: DWORD;   // DWORD
  TmHandle: THandle;   // HANDLE
  Description: PWideChar   // LPWSTR optional
): THandle; stdcall;
  external 'ktmw32.dll' name 'CreateResourceManager';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CreateResourceManager"
  c_CreateResourceManager :: Ptr () -> Ptr () -> Word32 -> Ptr () -> CWString -> IO (Ptr ())
-- lpResourceManagerAttributes : SECURITY_ATTRIBUTES* in/out -> Ptr ()
-- ResourceManagerId : GUID* in/out -> Ptr ()
-- CreateOptions : DWORD -> Word32
-- TmHandle : HANDLE -> Ptr ()
-- Description : LPWSTR optional -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let createresourcemanager =
  foreign "CreateResourceManager"
    ((ptr void) @-> (ptr void) @-> uint32_t @-> (ptr void) @-> (ptr uint16_t) @-> returning (ptr void))
(* lpResourceManagerAttributes : SECURITY_ATTRIBUTES* in/out -> (ptr void) *)
(* ResourceManagerId : GUID* in/out -> (ptr void) *)
(* CreateOptions : DWORD -> uint32_t *)
(* TmHandle : HANDLE -> (ptr void) *)
(* Description : LPWSTR optional -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library ktmw32 (t "ktmw32.dll"))
(cffi:use-foreign-library ktmw32)

(cffi:defcfun ("CreateResourceManager" create-resource-manager :convention :stdcall) :pointer
  (lp-resource-manager-attributes :pointer)   ; SECURITY_ATTRIBUTES* in/out
  (resource-manager-id :pointer)   ; GUID* in/out
  (create-options :uint32)   ; DWORD
  (tm-handle :pointer)   ; HANDLE
  (description (:string :encoding :utf-16le)))   ; LPWSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CreateResourceManager = Win32::API::More->new('ktmw32',
    'HANDLE CreateResourceManager(LPVOID lpResourceManagerAttributes, LPVOID ResourceManagerId, DWORD CreateOptions, HANDLE TmHandle, LPCWSTR Description)');
# my $ret = $CreateResourceManager->Call($lpResourceManagerAttributes, $ResourceManagerId, $CreateOptions, $TmHandle, $Description);
# lpResourceManagerAttributes : SECURITY_ATTRIBUTES* in/out -> LPVOID
# ResourceManagerId : GUID* in/out -> LPVOID
# CreateOptions : DWORD -> DWORD
# TmHandle : HANDLE -> HANDLE
# Description : LPWSTR optional -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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