Win32 API 日本語リファレンス
ホームSecurity.EnterpriseData › UnprotectFile

UnprotectFile

関数
企業IDで保護されたファイルの保護を解除する。
DLLefswrt.dll呼出規約winapi

シグネチャ

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

HRESULT UnprotectFile(
    LPCWSTR fileOrFolderPath,
    const FILE_UNPROTECT_OPTIONS* options   // optional
);

パラメーター

名前方向
fileOrFolderPathLPCWSTRin
optionsFILE_UNPROTECT_OPTIONS*inoptional

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT UnprotectFile(
    LPCWSTR fileOrFolderPath,
    const FILE_UNPROTECT_OPTIONS* options   // optional
);
[DllImport("efswrt.dll", ExactSpelling = true)]
static extern int UnprotectFile(
    [MarshalAs(UnmanagedType.LPWStr)] string fileOrFolderPath,   // LPCWSTR
    IntPtr options   // FILE_UNPROTECT_OPTIONS* optional
);
<DllImport("efswrt.dll", ExactSpelling:=True)>
Public Shared Function UnprotectFile(
    <MarshalAs(UnmanagedType.LPWStr)> fileOrFolderPath As String,   ' LPCWSTR
    options As IntPtr   ' FILE_UNPROTECT_OPTIONS* optional
) As Integer
End Function
' fileOrFolderPath : LPCWSTR
' options : FILE_UNPROTECT_OPTIONS* optional
Declare PtrSafe Function UnprotectFile Lib "efswrt" ( _
    ByVal fileOrFolderPath As LongPtr, _
    ByVal options As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

UnprotectFile = ctypes.windll.efswrt.UnprotectFile
UnprotectFile.restype = ctypes.c_int
UnprotectFile.argtypes = [
    wintypes.LPCWSTR,  # fileOrFolderPath : LPCWSTR
    ctypes.c_void_p,  # options : FILE_UNPROTECT_OPTIONS* optional
]
require 'fiddle'
require 'fiddle/import'

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

var (
	efswrt = windows.NewLazySystemDLL("efswrt.dll")
	procUnprotectFile = efswrt.NewProc("UnprotectFile")
)

// fileOrFolderPath (LPCWSTR), options (FILE_UNPROTECT_OPTIONS* optional)
r1, _, err := procUnprotectFile.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(fileOrFolderPath))),
	uintptr(options),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function UnprotectFile(
  fileOrFolderPath: PWideChar;   // LPCWSTR
  options: Pointer   // FILE_UNPROTECT_OPTIONS* optional
): Integer; stdcall;
  external 'efswrt.dll' name 'UnprotectFile';
result := DllCall("efswrt\UnprotectFile"
    , "WStr", fileOrFolderPath   ; LPCWSTR
    , "Ptr", options   ; FILE_UNPROTECT_OPTIONS* optional
    , "Int")   ; return: HRESULT
●UnprotectFile(fileOrFolderPath, options) = DLL("efswrt.dll", "int UnprotectFile(char*, void*)")
# 呼び出し: UnprotectFile(fileOrFolderPath, options)
# fileOrFolderPath : LPCWSTR -> "char*"
# options : FILE_UNPROTECT_OPTIONS* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。