Win32 API 日本語リファレンス
ホームUI.Shell › GetCurrentProcessExplicitAppUserModelID

GetCurrentProcessExplicitAppUserModelID

関数
現在のプロセスのアプリケーションユーザーモデルIDを取得する。
DLLSHELL32.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

HRESULT GetCurrentProcessExplicitAppUserModelID(
    LPWSTR* AppID
);

パラメーター

名前方向説明
AppIDLPWSTR*outプロセスに割り当てられた AppUserModelID のアドレスを受け取るポインターです。不要になった文字列は、呼び出し元が CoTaskMemFree を使用して解放する必要があります。

戻り値の型: HRESULT

公式ドキュメント

現在のプロセスに対して、アプリケーションが明示的に定義した Application User Model ID (AppUserModelID) を取得します。

戻り値

型: HRESULT

この関数が成功すると、S_OK を返します。それ以外の場合は、HRESULT エラー コードを返します。

解説(Remarks)

この関数で取得される AppUserModelID は、事前に SetCurrentProcessExplicitAppUserModelID を通じて設定されたものです。

アプリケーションが取得できるのは、明示的に設定された AppUserModelID のみです。システムによって割り当てられた既定の AppUserModelID は取得できません。アプリケーションが自身の AppUserModelID を把握する必要がある場合は、明示的に設定する必要があります。

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

各言語での呼び出し定義

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

HRESULT GetCurrentProcessExplicitAppUserModelID(
    LPWSTR* AppID
);
[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern int GetCurrentProcessExplicitAppUserModelID(
    IntPtr AppID   // LPWSTR* out
);
<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function GetCurrentProcessExplicitAppUserModelID(
    AppID As IntPtr   ' LPWSTR* out
) As Integer
End Function
' AppID : LPWSTR* out
Declare PtrSafe Function GetCurrentProcessExplicitAppUserModelID Lib "shell32" ( _
    ByVal AppID As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetCurrentProcessExplicitAppUserModelID = ctypes.windll.shell32.GetCurrentProcessExplicitAppUserModelID
GetCurrentProcessExplicitAppUserModelID.restype = ctypes.c_int
GetCurrentProcessExplicitAppUserModelID.argtypes = [
    ctypes.c_void_p,  # AppID : LPWSTR* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
GetCurrentProcessExplicitAppUserModelID = Fiddle::Function.new(
  lib['GetCurrentProcessExplicitAppUserModelID'],
  [
    Fiddle::TYPE_VOIDP,  # AppID : LPWSTR* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "shell32")]
extern "system" {
    fn GetCurrentProcessExplicitAppUserModelID(
        AppID: *mut *mut u16  // LPWSTR* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHELL32.dll")]
public static extern int GetCurrentProcessExplicitAppUserModelID(IntPtr AppID);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_GetCurrentProcessExplicitAppUserModelID' -Namespace Win32 -PassThru
# $api::GetCurrentProcessExplicitAppUserModelID(AppID)
#uselib "SHELL32.dll"
#func global GetCurrentProcessExplicitAppUserModelID "GetCurrentProcessExplicitAppUserModelID" sptr
; GetCurrentProcessExplicitAppUserModelID varptr(AppID)   ; 戻り値は stat
; AppID : LPWSTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHELL32.dll"
#cfunc global GetCurrentProcessExplicitAppUserModelID "GetCurrentProcessExplicitAppUserModelID" var
; res = GetCurrentProcessExplicitAppUserModelID(AppID)
; AppID : LPWSTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT GetCurrentProcessExplicitAppUserModelID(LPWSTR* AppID)
#uselib "SHELL32.dll"
#cfunc global GetCurrentProcessExplicitAppUserModelID "GetCurrentProcessExplicitAppUserModelID" var
; res = GetCurrentProcessExplicitAppUserModelID(AppID)
; AppID : LPWSTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procGetCurrentProcessExplicitAppUserModelID = shell32.NewProc("GetCurrentProcessExplicitAppUserModelID")
)

// AppID (LPWSTR* out)
r1, _, err := procGetCurrentProcessExplicitAppUserModelID.Call(
	uintptr(AppID),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function GetCurrentProcessExplicitAppUserModelID(
  AppID: PPWideChar   // LPWSTR* out
): Integer; stdcall;
  external 'SHELL32.dll' name 'GetCurrentProcessExplicitAppUserModelID';
result := DllCall("SHELL32\GetCurrentProcessExplicitAppUserModelID"
    , "Ptr", AppID   ; LPWSTR* out
    , "Int")   ; return: HRESULT
●GetCurrentProcessExplicitAppUserModelID(AppID) = DLL("SHELL32.dll", "int GetCurrentProcessExplicitAppUserModelID(void*)")
# 呼び出し: GetCurrentProcessExplicitAppUserModelID(AppID)
# AppID : LPWSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef GetCurrentProcessExplicitAppUserModelIDNative = Int32 Function(Pointer<Pointer<Utf16>>);
typedef GetCurrentProcessExplicitAppUserModelIDDart = int Function(Pointer<Pointer<Utf16>>);
final GetCurrentProcessExplicitAppUserModelID = DynamicLibrary.open('SHELL32.dll')
    .lookupFunction<GetCurrentProcessExplicitAppUserModelIDNative, GetCurrentProcessExplicitAppUserModelIDDart>('GetCurrentProcessExplicitAppUserModelID');
// AppID : LPWSTR* out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetCurrentProcessExplicitAppUserModelID(
  AppID: PPWideChar   // LPWSTR* out
): Integer; stdcall;
  external 'SHELL32.dll' name 'GetCurrentProcessExplicitAppUserModelID';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetCurrentProcessExplicitAppUserModelID"
  c_GetCurrentProcessExplicitAppUserModelID :: Ptr CWString -> IO Int32
-- AppID : LPWSTR* out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getcurrentprocessexplicitappusermodelid =
  foreign "GetCurrentProcessExplicitAppUserModelID"
    ((ptr (ptr uint16_t)) @-> returning int32_t)
(* AppID : LPWSTR* out -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)

(cffi:defcfun ("GetCurrentProcessExplicitAppUserModelID" get-current-process-explicit-app-user-model-id :convention :stdcall) :int32
  (app-id :pointer))   ; LPWSTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetCurrentProcessExplicitAppUserModelID = Win32::API::More->new('SHELL32',
    'int GetCurrentProcessExplicitAppUserModelID(LPVOID AppID)');
# my $ret = $GetCurrentProcessExplicitAppUserModelID->Call($AppID);
# AppID : LPWSTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。