Win32 API 日本語リファレンス
ホームNetworking.Clustering › RegisterAppInstance

RegisterAppInstance

関数
プロセスにアプリインスタンスIDを登録する。
DLLNTLANMAN.dll呼出規約winapi対応OSwindowsserver2012

シグネチャ

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

DWORD RegisterAppInstance(
    HANDLE ProcessHandle,
    GUID* AppInstanceId,
    BOOL ChildrenInheritAppInstance
);

パラメーター

名前方向説明
ProcessHandleHANDLEinアプリインスタンスIDを登録する対象プロセスのハンドル。
AppInstanceIdGUID*in登録するアプリケーションインスタンス識別子(GUID)へのポインター。
ChildrenInheritAppInstanceBOOLinTRUEなら子プロセスもこのインスタンスIDを継承する。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD RegisterAppInstance(
    HANDLE ProcessHandle,
    GUID* AppInstanceId,
    BOOL ChildrenInheritAppInstance
);
[DllImport("NTLANMAN.dll", ExactSpelling = true)]
static extern uint RegisterAppInstance(
    IntPtr ProcessHandle,   // HANDLE
    ref Guid AppInstanceId,   // GUID*
    bool ChildrenInheritAppInstance   // BOOL
);
<DllImport("NTLANMAN.dll", ExactSpelling:=True)>
Public Shared Function RegisterAppInstance(
    ProcessHandle As IntPtr,   ' HANDLE
    ByRef AppInstanceId As Guid,   ' GUID*
    ChildrenInheritAppInstance As Boolean   ' BOOL
) As UInteger
End Function
' ProcessHandle : HANDLE
' AppInstanceId : GUID*
' ChildrenInheritAppInstance : BOOL
Declare PtrSafe Function RegisterAppInstance Lib "ntlanman" ( _
    ByVal ProcessHandle As LongPtr, _
    ByVal AppInstanceId As LongPtr, _
    ByVal ChildrenInheritAppInstance As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RegisterAppInstance = ctypes.windll.ntlanman.RegisterAppInstance
RegisterAppInstance.restype = wintypes.DWORD
RegisterAppInstance.argtypes = [
    wintypes.HANDLE,  # ProcessHandle : HANDLE
    ctypes.c_void_p,  # AppInstanceId : GUID*
    wintypes.BOOL,  # ChildrenInheritAppInstance : BOOL
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('NTLANMAN.dll')
RegisterAppInstance = Fiddle::Function.new(
  lib['RegisterAppInstance'],
  [
    Fiddle::TYPE_VOIDP,  # ProcessHandle : HANDLE
    Fiddle::TYPE_VOIDP,  # AppInstanceId : GUID*
    Fiddle::TYPE_INT,  # ChildrenInheritAppInstance : BOOL
  ],
  -Fiddle::TYPE_INT)
#[link(name = "ntlanman")]
extern "system" {
    fn RegisterAppInstance(
        ProcessHandle: *mut core::ffi::c_void,  // HANDLE
        AppInstanceId: *mut GUID,  // GUID*
        ChildrenInheritAppInstance: i32  // BOOL
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("NTLANMAN.dll")]
public static extern uint RegisterAppInstance(IntPtr ProcessHandle, ref Guid AppInstanceId, bool ChildrenInheritAppInstance);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NTLANMAN_RegisterAppInstance' -Namespace Win32 -PassThru
# $api::RegisterAppInstance(ProcessHandle, AppInstanceId, ChildrenInheritAppInstance)
#uselib "NTLANMAN.dll"
#func global RegisterAppInstance "RegisterAppInstance" sptr, sptr, sptr
; RegisterAppInstance ProcessHandle, varptr(AppInstanceId), ChildrenInheritAppInstance   ; 戻り値は stat
; ProcessHandle : HANDLE -> "sptr"
; AppInstanceId : GUID* -> "sptr"
; ChildrenInheritAppInstance : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "NTLANMAN.dll"
#cfunc global RegisterAppInstance "RegisterAppInstance" sptr, var, int
; res = RegisterAppInstance(ProcessHandle, AppInstanceId, ChildrenInheritAppInstance)
; ProcessHandle : HANDLE -> "sptr"
; AppInstanceId : GUID* -> "var"
; ChildrenInheritAppInstance : BOOL -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD RegisterAppInstance(HANDLE ProcessHandle, GUID* AppInstanceId, BOOL ChildrenInheritAppInstance)
#uselib "NTLANMAN.dll"
#cfunc global RegisterAppInstance "RegisterAppInstance" intptr, var, int
; res = RegisterAppInstance(ProcessHandle, AppInstanceId, ChildrenInheritAppInstance)
; ProcessHandle : HANDLE -> "intptr"
; AppInstanceId : GUID* -> "var"
; ChildrenInheritAppInstance : BOOL -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ntlanman = windows.NewLazySystemDLL("NTLANMAN.dll")
	procRegisterAppInstance = ntlanman.NewProc("RegisterAppInstance")
)

// ProcessHandle (HANDLE), AppInstanceId (GUID*), ChildrenInheritAppInstance (BOOL)
r1, _, err := procRegisterAppInstance.Call(
	uintptr(ProcessHandle),
	uintptr(AppInstanceId),
	uintptr(ChildrenInheritAppInstance),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function RegisterAppInstance(
  ProcessHandle: THandle;   // HANDLE
  AppInstanceId: PGUID;   // GUID*
  ChildrenInheritAppInstance: BOOL   // BOOL
): DWORD; stdcall;
  external 'NTLANMAN.dll' name 'RegisterAppInstance';
result := DllCall("NTLANMAN\RegisterAppInstance"
    , "Ptr", ProcessHandle   ; HANDLE
    , "Ptr", AppInstanceId   ; GUID*
    , "Int", ChildrenInheritAppInstance   ; BOOL
    , "UInt")   ; return: DWORD
●RegisterAppInstance(ProcessHandle, AppInstanceId, ChildrenInheritAppInstance) = DLL("NTLANMAN.dll", "dword RegisterAppInstance(void*, void*, bool)")
# 呼び出し: RegisterAppInstance(ProcessHandle, AppInstanceId, ChildrenInheritAppInstance)
# ProcessHandle : HANDLE -> "void*"
# AppInstanceId : GUID* -> "void*"
# ChildrenInheritAppInstance : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef RegisterAppInstanceNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Int32);
typedef RegisterAppInstanceDart = int Function(Pointer<Void>, Pointer<Void>, int);
final RegisterAppInstance = DynamicLibrary.open('NTLANMAN.dll')
    .lookupFunction<RegisterAppInstanceNative, RegisterAppInstanceDart>('RegisterAppInstance');
// ProcessHandle : HANDLE -> Pointer<Void>
// AppInstanceId : GUID* -> Pointer<Void>
// ChildrenInheritAppInstance : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RegisterAppInstance(
  ProcessHandle: THandle;   // HANDLE
  AppInstanceId: PGUID;   // GUID*
  ChildrenInheritAppInstance: BOOL   // BOOL
): DWORD; stdcall;
  external 'NTLANMAN.dll' name 'RegisterAppInstance';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RegisterAppInstance"
  c_RegisterAppInstance :: Ptr () -> Ptr () -> CInt -> IO Word32
-- ProcessHandle : HANDLE -> Ptr ()
-- AppInstanceId : GUID* -> Ptr ()
-- ChildrenInheritAppInstance : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let registerappinstance =
  foreign "RegisterAppInstance"
    ((ptr void) @-> (ptr void) @-> int32_t @-> returning uint32_t)
(* ProcessHandle : HANDLE -> (ptr void) *)
(* AppInstanceId : GUID* -> (ptr void) *)
(* ChildrenInheritAppInstance : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library ntlanman (t "NTLANMAN.dll"))
(cffi:use-foreign-library ntlanman)

(cffi:defcfun ("RegisterAppInstance" register-app-instance :convention :stdcall) :uint32
  (process-handle :pointer)   ; HANDLE
  (app-instance-id :pointer)   ; GUID*
  (children-inherit-app-instance :int32))   ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RegisterAppInstance = Win32::API::More->new('NTLANMAN',
    'DWORD RegisterAppInstance(HANDLE ProcessHandle, LPVOID AppInstanceId, BOOL ChildrenInheritAppInstance)');
# my $ret = $RegisterAppInstance->Call($ProcessHandle, $AppInstanceId, $ChildrenInheritAppInstance);
# ProcessHandle : HANDLE -> HANDLE
# AppInstanceId : GUID* -> LPVOID
# ChildrenInheritAppInstance : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。