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

AddUsersToEncryptedFile

関数
暗号化ファイルに証明書でユーザーのアクセス権を追加する。
DLLADVAPI32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

DWORD AddUsersToEncryptedFile(
    LPCWSTR lpFileName,
    ENCRYPTION_CERTIFICATE_LIST* pEncryptionCertificates
);

パラメーター

名前方向
lpFileNameLPCWSTRin
pEncryptionCertificatesENCRYPTION_CERTIFICATE_LIST*in

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD AddUsersToEncryptedFile(
    LPCWSTR lpFileName,
    ENCRYPTION_CERTIFICATE_LIST* pEncryptionCertificates
);
[DllImport("ADVAPI32.dll", ExactSpelling = true)]
static extern uint AddUsersToEncryptedFile(
    [MarshalAs(UnmanagedType.LPWStr)] string lpFileName,   // LPCWSTR
    IntPtr pEncryptionCertificates   // ENCRYPTION_CERTIFICATE_LIST*
);
<DllImport("ADVAPI32.dll", ExactSpelling:=True)>
Public Shared Function AddUsersToEncryptedFile(
    <MarshalAs(UnmanagedType.LPWStr)> lpFileName As String,   ' LPCWSTR
    pEncryptionCertificates As IntPtr   ' ENCRYPTION_CERTIFICATE_LIST*
) As UInteger
End Function
' lpFileName : LPCWSTR
' pEncryptionCertificates : ENCRYPTION_CERTIFICATE_LIST*
Declare PtrSafe Function AddUsersToEncryptedFile Lib "advapi32" ( _
    ByVal lpFileName As LongPtr, _
    ByVal pEncryptionCertificates As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

AddUsersToEncryptedFile = ctypes.windll.advapi32.AddUsersToEncryptedFile
AddUsersToEncryptedFile.restype = wintypes.DWORD
AddUsersToEncryptedFile.argtypes = [
    wintypes.LPCWSTR,  # lpFileName : LPCWSTR
    ctypes.c_void_p,  # pEncryptionCertificates : ENCRYPTION_CERTIFICATE_LIST*
]
require 'fiddle'
require 'fiddle/import'

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

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procAddUsersToEncryptedFile = advapi32.NewProc("AddUsersToEncryptedFile")
)

// lpFileName (LPCWSTR), pEncryptionCertificates (ENCRYPTION_CERTIFICATE_LIST*)
r1, _, err := procAddUsersToEncryptedFile.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpFileName))),
	uintptr(pEncryptionCertificates),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function AddUsersToEncryptedFile(
  lpFileName: PWideChar;   // LPCWSTR
  pEncryptionCertificates: Pointer   // ENCRYPTION_CERTIFICATE_LIST*
): DWORD; stdcall;
  external 'ADVAPI32.dll' name 'AddUsersToEncryptedFile';
result := DllCall("ADVAPI32\AddUsersToEncryptedFile"
    , "WStr", lpFileName   ; LPCWSTR
    , "Ptr", pEncryptionCertificates   ; ENCRYPTION_CERTIFICATE_LIST*
    , "UInt")   ; return: DWORD
●AddUsersToEncryptedFile(lpFileName, pEncryptionCertificates) = DLL("ADVAPI32.dll", "dword AddUsersToEncryptedFile(char*, void*)")
# 呼び出し: AddUsersToEncryptedFile(lpFileName, pEncryptionCertificates)
# lpFileName : LPCWSTR -> "char*"
# pEncryptionCertificates : ENCRYPTION_CERTIFICATE_LIST* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。