ホーム › Security.Isolation › GetAppContainerFolderPath
GetAppContainerFolderPath
関数AppContainer SIDに対応するフォルダーパスを取得する。
シグネチャ
// USERENV.dll
#include <windows.h>
HRESULT GetAppContainerFolderPath(
LPCWSTR pszAppContainerSid,
LPWSTR* ppszPath
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszAppContainerSid | LPCWSTR | in | 対象AppContainerのSIDを表す文字列。 |
| ppszPath | LPWSTR* | out | AppContainerのフォルダーパスを受け取るポインタ。CoTaskMemFreeで解放する。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// USERENV.dll
#include <windows.h>
HRESULT GetAppContainerFolderPath(
LPCWSTR pszAppContainerSid,
LPWSTR* ppszPath
);[DllImport("USERENV.dll", ExactSpelling = true)]
static extern int GetAppContainerFolderPath(
[MarshalAs(UnmanagedType.LPWStr)] string pszAppContainerSid, // LPCWSTR
IntPtr ppszPath // LPWSTR* out
);<DllImport("USERENV.dll", ExactSpelling:=True)>
Public Shared Function GetAppContainerFolderPath(
<MarshalAs(UnmanagedType.LPWStr)> pszAppContainerSid As String, ' LPCWSTR
ppszPath As IntPtr ' LPWSTR* out
) As Integer
End Function' pszAppContainerSid : LPCWSTR
' ppszPath : LPWSTR* out
Declare PtrSafe Function GetAppContainerFolderPath Lib "userenv" ( _
ByVal pszAppContainerSid As LongPtr, _
ByVal ppszPath As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetAppContainerFolderPath = ctypes.windll.userenv.GetAppContainerFolderPath
GetAppContainerFolderPath.restype = ctypes.c_int
GetAppContainerFolderPath.argtypes = [
wintypes.LPCWSTR, # pszAppContainerSid : LPCWSTR
ctypes.c_void_p, # ppszPath : LPWSTR* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USERENV.dll')
GetAppContainerFolderPath = Fiddle::Function.new(
lib['GetAppContainerFolderPath'],
[
Fiddle::TYPE_VOIDP, # pszAppContainerSid : LPCWSTR
Fiddle::TYPE_VOIDP, # ppszPath : LPWSTR* out
],
Fiddle::TYPE_INT)#[link(name = "userenv")]
extern "system" {
fn GetAppContainerFolderPath(
pszAppContainerSid: *const u16, // LPCWSTR
ppszPath: *mut *mut u16 // LPWSTR* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USERENV.dll")]
public static extern int GetAppContainerFolderPath([MarshalAs(UnmanagedType.LPWStr)] string pszAppContainerSid, IntPtr ppszPath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USERENV_GetAppContainerFolderPath' -Namespace Win32 -PassThru
# $api::GetAppContainerFolderPath(pszAppContainerSid, ppszPath)#uselib "USERENV.dll"
#func global GetAppContainerFolderPath "GetAppContainerFolderPath" sptr, sptr
; GetAppContainerFolderPath pszAppContainerSid, varptr(ppszPath) ; 戻り値は stat
; pszAppContainerSid : LPCWSTR -> "sptr"
; ppszPath : LPWSTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "USERENV.dll" #cfunc global GetAppContainerFolderPath "GetAppContainerFolderPath" wstr, var ; res = GetAppContainerFolderPath(pszAppContainerSid, ppszPath) ; pszAppContainerSid : LPCWSTR -> "wstr" ; ppszPath : LPWSTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USERENV.dll" #cfunc global GetAppContainerFolderPath "GetAppContainerFolderPath" wstr, sptr ; res = GetAppContainerFolderPath(pszAppContainerSid, varptr(ppszPath)) ; pszAppContainerSid : LPCWSTR -> "wstr" ; ppszPath : LPWSTR* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT GetAppContainerFolderPath(LPCWSTR pszAppContainerSid, LPWSTR* ppszPath) #uselib "USERENV.dll" #cfunc global GetAppContainerFolderPath "GetAppContainerFolderPath" wstr, var ; res = GetAppContainerFolderPath(pszAppContainerSid, ppszPath) ; pszAppContainerSid : LPCWSTR -> "wstr" ; ppszPath : LPWSTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT GetAppContainerFolderPath(LPCWSTR pszAppContainerSid, LPWSTR* ppszPath) #uselib "USERENV.dll" #cfunc global GetAppContainerFolderPath "GetAppContainerFolderPath" wstr, intptr ; res = GetAppContainerFolderPath(pszAppContainerSid, varptr(ppszPath)) ; pszAppContainerSid : LPCWSTR -> "wstr" ; ppszPath : LPWSTR* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
userenv = windows.NewLazySystemDLL("USERENV.dll")
procGetAppContainerFolderPath = userenv.NewProc("GetAppContainerFolderPath")
)
// pszAppContainerSid (LPCWSTR), ppszPath (LPWSTR* out)
r1, _, err := procGetAppContainerFolderPath.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszAppContainerSid))),
uintptr(ppszPath),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction GetAppContainerFolderPath(
pszAppContainerSid: PWideChar; // LPCWSTR
ppszPath: PPWideChar // LPWSTR* out
): Integer; stdcall;
external 'USERENV.dll' name 'GetAppContainerFolderPath';result := DllCall("USERENV\GetAppContainerFolderPath"
, "WStr", pszAppContainerSid ; LPCWSTR
, "Ptr", ppszPath ; LPWSTR* out
, "Int") ; return: HRESULT●GetAppContainerFolderPath(pszAppContainerSid, ppszPath) = DLL("USERENV.dll", "int GetAppContainerFolderPath(char*, void*)")
# 呼び出し: GetAppContainerFolderPath(pszAppContainerSid, ppszPath)
# pszAppContainerSid : LPCWSTR -> "char*"
# ppszPath : LPWSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "userenv" fn GetAppContainerFolderPath(
pszAppContainerSid: [*c]const u16, // LPCWSTR
ppszPath: [*c][*c]u16 // LPWSTR* out
) callconv(std.os.windows.WINAPI) i32;proc GetAppContainerFolderPath(
pszAppContainerSid: WideCString, # LPCWSTR
ppszPath: ptr WideCString # LPWSTR* out
): int32 {.importc: "GetAppContainerFolderPath", stdcall, dynlib: "USERENV.dll".}pragma(lib, "userenv");
extern(Windows)
int GetAppContainerFolderPath(
const(wchar)* pszAppContainerSid, // LPCWSTR
wchar** ppszPath // LPWSTR* out
);ccall((:GetAppContainerFolderPath, "USERENV.dll"), stdcall, Int32,
(Cwstring, Ptr{Ptr{UInt16}}),
pszAppContainerSid, ppszPath)
# pszAppContainerSid : LPCWSTR -> Cwstring
# ppszPath : LPWSTR* out -> Ptr{Ptr{UInt16}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetAppContainerFolderPath(
const uint16_t* pszAppContainerSid,
uint16_t** ppszPath);
]]
local userenv = ffi.load("userenv")
-- userenv.GetAppContainerFolderPath(pszAppContainerSid, ppszPath)
-- pszAppContainerSid : LPCWSTR
-- ppszPath : LPWSTR* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USERENV.dll');
const GetAppContainerFolderPath = lib.func('__stdcall', 'GetAppContainerFolderPath', 'int32_t', ['str16', 'void *']);
// GetAppContainerFolderPath(pszAppContainerSid, ppszPath)
// pszAppContainerSid : LPCWSTR -> 'str16'
// ppszPath : LPWSTR* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USERENV.dll", {
GetAppContainerFolderPath: { parameters: ["buffer", "pointer"], result: "i32" },
});
// lib.symbols.GetAppContainerFolderPath(pszAppContainerSid, ppszPath)
// pszAppContainerSid : LPCWSTR -> "buffer"
// ppszPath : LPWSTR* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetAppContainerFolderPath(
const uint16_t* pszAppContainerSid,
uint16_t** ppszPath);
C, "USERENV.dll");
// $ffi->GetAppContainerFolderPath(pszAppContainerSid, ppszPath);
// pszAppContainerSid : LPCWSTR
// ppszPath : 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 Userenv extends StdCallLibrary {
Userenv INSTANCE = Native.load("userenv", Userenv.class);
int GetAppContainerFolderPath(
WString pszAppContainerSid, // LPCWSTR
PointerByReference ppszPath // LPWSTR* out
);
}@[Link("userenv")]
lib LibUSERENV
fun GetAppContainerFolderPath = GetAppContainerFolderPath(
pszAppContainerSid : UInt16*, # LPCWSTR
ppszPath : 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 GetAppContainerFolderPathNative = Int32 Function(Pointer<Utf16>, Pointer<Pointer<Utf16>>);
typedef GetAppContainerFolderPathDart = int Function(Pointer<Utf16>, Pointer<Pointer<Utf16>>);
final GetAppContainerFolderPath = DynamicLibrary.open('USERENV.dll')
.lookupFunction<GetAppContainerFolderPathNative, GetAppContainerFolderPathDart>('GetAppContainerFolderPath');
// pszAppContainerSid : LPCWSTR -> Pointer<Utf16>
// ppszPath : LPWSTR* out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetAppContainerFolderPath(
pszAppContainerSid: PWideChar; // LPCWSTR
ppszPath: PPWideChar // LPWSTR* out
): Integer; stdcall;
external 'USERENV.dll' name 'GetAppContainerFolderPath';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetAppContainerFolderPath"
c_GetAppContainerFolderPath :: CWString -> Ptr CWString -> IO Int32
-- pszAppContainerSid : LPCWSTR -> CWString
-- ppszPath : LPWSTR* out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getappcontainerfolderpath =
foreign "GetAppContainerFolderPath"
((ptr uint16_t) @-> (ptr (ptr uint16_t)) @-> returning int32_t)
(* pszAppContainerSid : LPCWSTR -> (ptr uint16_t) *)
(* ppszPath : LPWSTR* out -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library userenv (t "USERENV.dll"))
(cffi:use-foreign-library userenv)
(cffi:defcfun ("GetAppContainerFolderPath" get-app-container-folder-path :convention :stdcall) :int32
(psz-app-container-sid (:string :encoding :utf-16le)) ; LPCWSTR
(ppsz-path :pointer)) ; LPWSTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetAppContainerFolderPath = Win32::API::More->new('USERENV',
'int GetAppContainerFolderPath(LPCWSTR pszAppContainerSid, LPVOID ppszPath)');
# my $ret = $GetAppContainerFolderPath->Call($pszAppContainerSid, $ppszPath);
# pszAppContainerSid : LPCWSTR -> LPCWSTR
# ppszPath : LPWSTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。