Win32 API 日本語リファレンス
ホームStorage.Packaging.Appx › GetApplicationUserModelId

GetApplicationUserModelId

関数
指定プロセスのアプリケーションユーザーモデルIDを取得する。
DLLKERNEL32.dll呼出規約winapi

シグネチャ

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

WIN32_ERROR GetApplicationUserModelId(
    HANDLE hProcess,
    DWORD* applicationUserModelIdLength,
    LPWSTR applicationUserModelId   // optional
);

パラメーター

名前方向説明
hProcessHANDLEin対象プロセスのハンドル。PROCESS_QUERY_*権限が必要。
applicationUserModelIdLengthDWORD*inout入力で文字数、出力で必要文字数を受け取る入出力ポインタ(終端含む)。
applicationUserModelIdLPWSTRoutoptional対象プロセスのAUMID文字列を受け取る出力バッファ。NULLでサイズ照会可。

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR GetApplicationUserModelId(
    HANDLE hProcess,
    DWORD* applicationUserModelIdLength,
    LPWSTR applicationUserModelId   // optional
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern uint GetApplicationUserModelId(
    IntPtr hProcess,   // HANDLE
    ref uint applicationUserModelIdLength,   // DWORD* in/out
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder applicationUserModelId   // LPWSTR optional, out
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function GetApplicationUserModelId(
    hProcess As IntPtr,   ' HANDLE
    ByRef applicationUserModelIdLength As UInteger,   ' DWORD* in/out
    <MarshalAs(UnmanagedType.LPWStr)> applicationUserModelId As System.Text.StringBuilder   ' LPWSTR optional, out
) As UInteger
End Function
' hProcess : HANDLE
' applicationUserModelIdLength : DWORD* in/out
' applicationUserModelId : LPWSTR optional, out
Declare PtrSafe Function GetApplicationUserModelId Lib "kernel32" ( _
    ByVal hProcess As LongPtr, _
    ByRef applicationUserModelIdLength As Long, _
    ByVal applicationUserModelId As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetApplicationUserModelId = ctypes.windll.kernel32.GetApplicationUserModelId
GetApplicationUserModelId.restype = wintypes.DWORD
GetApplicationUserModelId.argtypes = [
    wintypes.HANDLE,  # hProcess : HANDLE
    ctypes.POINTER(wintypes.DWORD),  # applicationUserModelIdLength : DWORD* in/out
    wintypes.LPWSTR,  # applicationUserModelId : LPWSTR optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetApplicationUserModelId = kernel32.NewProc("GetApplicationUserModelId")
)

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

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

typedef GetApplicationUserModelIdNative = Uint32 Function(Pointer<Void>, Pointer<Uint32>, Pointer<Utf16>);
typedef GetApplicationUserModelIdDart = int Function(Pointer<Void>, Pointer<Uint32>, Pointer<Utf16>);
final GetApplicationUserModelId = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<GetApplicationUserModelIdNative, GetApplicationUserModelIdDart>('GetApplicationUserModelId');
// hProcess : HANDLE -> Pointer<Void>
// applicationUserModelIdLength : DWORD* in/out -> Pointer<Uint32>
// applicationUserModelId : LPWSTR optional, out -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetApplicationUserModelId(
  hProcess: THandle;   // HANDLE
  applicationUserModelIdLength: Pointer;   // DWORD* in/out
  applicationUserModelId: PWideChar   // LPWSTR optional, out
): DWORD; stdcall;
  external 'KERNEL32.dll' name 'GetApplicationUserModelId';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetApplicationUserModelId"
  c_GetApplicationUserModelId :: Ptr () -> Ptr Word32 -> CWString -> IO Word32
-- hProcess : HANDLE -> Ptr ()
-- applicationUserModelIdLength : DWORD* in/out -> Ptr Word32
-- applicationUserModelId : LPWSTR optional, out -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getapplicationusermodelid =
  foreign "GetApplicationUserModelId"
    ((ptr void) @-> (ptr uint32_t) @-> (ptr uint16_t) @-> returning uint32_t)
(* hProcess : HANDLE -> (ptr void) *)
(* applicationUserModelIdLength : DWORD* in/out -> (ptr uint32_t) *)
(* applicationUserModelId : LPWSTR optional, out -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("GetApplicationUserModelId" get-application-user-model-id :convention :stdcall) :uint32
  (h-process :pointer)   ; HANDLE
  (application-user-model-id-length :pointer)   ; DWORD* in/out
  (application-user-model-id :pointer))   ; LPWSTR optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetApplicationUserModelId = Win32::API::More->new('KERNEL32',
    'DWORD GetApplicationUserModelId(HANDLE hProcess, LPVOID applicationUserModelIdLength, LPWSTR applicationUserModelId)');
# my $ret = $GetApplicationUserModelId->Call($hProcess, $applicationUserModelIdLength, $applicationUserModelId);
# hProcess : HANDLE -> HANDLE
# applicationUserModelIdLength : DWORD* in/out -> LPVOID
# applicationUserModelId : LPWSTR optional, out -> LPWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型