ホーム › Security.Credentials › CredIsProtectedA
CredIsProtectedA
関数資格情報文字列が保護されているか判定する。
シグネチャ
// ADVAPI32.dll (ANSI / -A)
#include <windows.h>
BOOL CredIsProtectedA(
LPSTR pszProtectedCredentials,
CRED_PROTECTION_TYPE* pProtectionType
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszProtectedCredentials | LPSTR | in | テストする資格情報を指定する、null 終端文字列へのポインターです。 |
| pProtectionType | CRED_PROTECTION_TYPE* | out | pszProtectedCredentials パラメーターで指定された資格情報が保護されているかどうかを示す、CRED_PROTECTION_TYPE 列挙体の値へのポインターです。 |
戻り値の型: BOOL
公式ドキュメント
指定された資格情報が、以前の CredProtect 関数の呼び出しによって暗号化されているかどうかを示します。(ANSI)
戻り値
関数が成功した場合は TRUE、それ以外の場合は FALSE を返します。
拡張エラー情報を取得するには、 GetLastError 関数を呼び出します。
解説(Remarks)
メモ
wincred.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして CredIsProtected を定義します。エンコード非依存のエイリアスの使用を、エンコード非依存ではないコードと混在させると、不一致が生じ、コンパイルエラーまたは実行時エラーを引き起こす可能性があります。詳細については、「Conventions for Function Prototypes」を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// ADVAPI32.dll (ANSI / -A)
#include <windows.h>
BOOL CredIsProtectedA(
LPSTR pszProtectedCredentials,
CRED_PROTECTION_TYPE* pProtectionType
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool CredIsProtectedA(
[MarshalAs(UnmanagedType.LPStr)] string pszProtectedCredentials, // LPSTR
out int pProtectionType // CRED_PROTECTION_TYPE* out
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CredIsProtectedA(
<MarshalAs(UnmanagedType.LPStr)> pszProtectedCredentials As String, ' LPSTR
<Out> ByRef pProtectionType As Integer ' CRED_PROTECTION_TYPE* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' pszProtectedCredentials : LPSTR
' pProtectionType : CRED_PROTECTION_TYPE* out
Declare PtrSafe Function CredIsProtectedA Lib "advapi32" ( _
ByVal pszProtectedCredentials As String, _
ByRef pProtectionType As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CredIsProtectedA = ctypes.windll.advapi32.CredIsProtectedA
CredIsProtectedA.restype = wintypes.BOOL
CredIsProtectedA.argtypes = [
wintypes.LPCSTR, # pszProtectedCredentials : LPSTR
ctypes.c_void_p, # pProtectionType : CRED_PROTECTION_TYPE* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
CredIsProtectedA = Fiddle::Function.new(
lib['CredIsProtectedA'],
[
Fiddle::TYPE_VOIDP, # pszProtectedCredentials : LPSTR
Fiddle::TYPE_VOIDP, # pProtectionType : CRED_PROTECTION_TYPE* out
],
Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn CredIsProtectedA(
pszProtectedCredentials: *mut u8, // LPSTR
pProtectionType: *mut i32 // CRED_PROTECTION_TYPE* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool CredIsProtectedA([MarshalAs(UnmanagedType.LPStr)] string pszProtectedCredentials, out int pProtectionType);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_CredIsProtectedA' -Namespace Win32 -PassThru
# $api::CredIsProtectedA(pszProtectedCredentials, pProtectionType)#uselib "ADVAPI32.dll"
#func global CredIsProtectedA "CredIsProtectedA" sptr, sptr
; CredIsProtectedA pszProtectedCredentials, varptr(pProtectionType) ; 戻り値は stat
; pszProtectedCredentials : LPSTR -> "sptr"
; pProtectionType : CRED_PROTECTION_TYPE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ADVAPI32.dll" #cfunc global CredIsProtectedA "CredIsProtectedA" str, var ; res = CredIsProtectedA(pszProtectedCredentials, pProtectionType) ; pszProtectedCredentials : LPSTR -> "str" ; pProtectionType : CRED_PROTECTION_TYPE* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global CredIsProtectedA "CredIsProtectedA" str, sptr ; res = CredIsProtectedA(pszProtectedCredentials, varptr(pProtectionType)) ; pszProtectedCredentials : LPSTR -> "str" ; pProtectionType : CRED_PROTECTION_TYPE* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL CredIsProtectedA(LPSTR pszProtectedCredentials, CRED_PROTECTION_TYPE* pProtectionType) #uselib "ADVAPI32.dll" #cfunc global CredIsProtectedA "CredIsProtectedA" str, var ; res = CredIsProtectedA(pszProtectedCredentials, pProtectionType) ; pszProtectedCredentials : LPSTR -> "str" ; pProtectionType : CRED_PROTECTION_TYPE* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CredIsProtectedA(LPSTR pszProtectedCredentials, CRED_PROTECTION_TYPE* pProtectionType) #uselib "ADVAPI32.dll" #cfunc global CredIsProtectedA "CredIsProtectedA" str, intptr ; res = CredIsProtectedA(pszProtectedCredentials, varptr(pProtectionType)) ; pszProtectedCredentials : LPSTR -> "str" ; pProtectionType : CRED_PROTECTION_TYPE* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procCredIsProtectedA = advapi32.NewProc("CredIsProtectedA")
)
// pszProtectedCredentials (LPSTR), pProtectionType (CRED_PROTECTION_TYPE* out)
r1, _, err := procCredIsProtectedA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(pszProtectedCredentials))),
uintptr(pProtectionType),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CredIsProtectedA(
pszProtectedCredentials: PAnsiChar; // LPSTR
pProtectionType: Pointer // CRED_PROTECTION_TYPE* out
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'CredIsProtectedA';result := DllCall("ADVAPI32\CredIsProtectedA"
, "AStr", pszProtectedCredentials ; LPSTR
, "Ptr", pProtectionType ; CRED_PROTECTION_TYPE* out
, "Int") ; return: BOOL●CredIsProtectedA(pszProtectedCredentials, pProtectionType) = DLL("ADVAPI32.dll", "bool CredIsProtectedA(char*, void*)")
# 呼び出し: CredIsProtectedA(pszProtectedCredentials, pProtectionType)
# pszProtectedCredentials : LPSTR -> "char*"
# pProtectionType : CRED_PROTECTION_TYPE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "advapi32" fn CredIsProtectedA(
pszProtectedCredentials: [*c]const u8, // LPSTR
pProtectionType: [*c]i32 // CRED_PROTECTION_TYPE* out
) callconv(std.os.windows.WINAPI) i32;proc CredIsProtectedA(
pszProtectedCredentials: cstring, # LPSTR
pProtectionType: ptr int32 # CRED_PROTECTION_TYPE* out
): int32 {.importc: "CredIsProtectedA", stdcall, dynlib: "ADVAPI32.dll".}pragma(lib, "advapi32");
extern(Windows)
int CredIsProtectedA(
const(char)* pszProtectedCredentials, // LPSTR
int* pProtectionType // CRED_PROTECTION_TYPE* out
);ccall((:CredIsProtectedA, "ADVAPI32.dll"), stdcall, Int32,
(Cstring, Ptr{Int32}),
pszProtectedCredentials, pProtectionType)
# pszProtectedCredentials : LPSTR -> Cstring
# pProtectionType : CRED_PROTECTION_TYPE* out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CredIsProtectedA(
const char* pszProtectedCredentials,
int32_t* pProtectionType);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.CredIsProtectedA(pszProtectedCredentials, pProtectionType)
-- pszProtectedCredentials : LPSTR
-- pProtectionType : CRED_PROTECTION_TYPE* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const CredIsProtectedA = lib.func('__stdcall', 'CredIsProtectedA', 'int32_t', ['str', 'int32_t *']);
// CredIsProtectedA(pszProtectedCredentials, pProtectionType)
// pszProtectedCredentials : LPSTR -> 'str'
// pProtectionType : CRED_PROTECTION_TYPE* out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
CredIsProtectedA: { parameters: ["buffer", "pointer"], result: "i32" },
});
// lib.symbols.CredIsProtectedA(pszProtectedCredentials, pProtectionType)
// pszProtectedCredentials : LPSTR -> "buffer"
// pProtectionType : CRED_PROTECTION_TYPE* out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CredIsProtectedA(
const char* pszProtectedCredentials,
int32_t* pProtectionType);
C, "ADVAPI32.dll");
// $ffi->CredIsProtectedA(pszProtectedCredentials, pProtectionType);
// pszProtectedCredentials : LPSTR
// pProtectionType : CRED_PROTECTION_TYPE* 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 Advapi32 extends StdCallLibrary {
Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class, W32APIOptions.ASCII_OPTIONS);
boolean CredIsProtectedA(
String pszProtectedCredentials, // LPSTR
IntByReference pProtectionType // CRED_PROTECTION_TYPE* out
);
}@[Link("advapi32")]
lib LibADVAPI32
fun CredIsProtectedA = CredIsProtectedA(
pszProtectedCredentials : UInt8*, # LPSTR
pProtectionType : Int32* # CRED_PROTECTION_TYPE* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CredIsProtectedANative = Int32 Function(Pointer<Utf8>, Pointer<Int32>);
typedef CredIsProtectedADart = int Function(Pointer<Utf8>, Pointer<Int32>);
final CredIsProtectedA = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<CredIsProtectedANative, CredIsProtectedADart>('CredIsProtectedA');
// pszProtectedCredentials : LPSTR -> Pointer<Utf8>
// pProtectionType : CRED_PROTECTION_TYPE* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CredIsProtectedA(
pszProtectedCredentials: PAnsiChar; // LPSTR
pProtectionType: Pointer // CRED_PROTECTION_TYPE* out
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'CredIsProtectedA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CredIsProtectedA"
c_CredIsProtectedA :: CString -> Ptr Int32 -> IO CInt
-- pszProtectedCredentials : LPSTR -> CString
-- pProtectionType : CRED_PROTECTION_TYPE* out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let credisprotecteda =
foreign "CredIsProtectedA"
(string @-> (ptr int32_t) @-> returning int32_t)
(* pszProtectedCredentials : LPSTR -> string *)
(* pProtectionType : CRED_PROTECTION_TYPE* out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)
(cffi:defcfun ("CredIsProtectedA" cred-is-protected-a :convention :stdcall) :int32
(psz-protected-credentials :string) ; LPSTR
(p-protection-type :pointer)) ; CRED_PROTECTION_TYPE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CredIsProtectedA = Win32::API::More->new('ADVAPI32',
'BOOL CredIsProtectedA(LPCSTR pszProtectedCredentials, LPVOID pProtectionType)');
# my $ret = $CredIsProtectedA->Call($pszProtectedCredentials, $pProtectionType);
# pszProtectedCredentials : LPSTR -> LPCSTR
# pProtectionType : CRED_PROTECTION_TYPE* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f CredIsProtectedW (Unicode版) — 資格情報文字列が保護されているか判定する。