ホーム › Security.LicenseProtection › ValidateLicenseKeyProtection
ValidateLicenseKeyProtection
関数ライセンスキーの保護状態と有効期間を検証する。
シグネチャ
// licenseprotection.dll
#include <windows.h>
HRESULT ValidateLicenseKeyProtection(
LPCWSTR licenseKey,
FILETIME* notValidBefore,
FILETIME* notValidAfter,
LicenseProtectionStatus* status
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| licenseKey | LPCWSTR | in | 検証するライセンスキー文字列(Unicode)。 |
| notValidBefore | FILETIME* | out | ライセンスの有効開始日時を受け取るFILETIME構造体へのポインタ。 |
| notValidAfter | FILETIME* | out | ライセンスの有効終了日時を受け取るFILETIME構造体へのポインタ。 |
| status | LicenseProtectionStatus* | out | ライセンス検証の結果ステータスを受け取るLicenseProtectionStatusへのポインタ。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// licenseprotection.dll
#include <windows.h>
HRESULT ValidateLicenseKeyProtection(
LPCWSTR licenseKey,
FILETIME* notValidBefore,
FILETIME* notValidAfter,
LicenseProtectionStatus* status
);[DllImport("licenseprotection.dll", ExactSpelling = true)]
static extern int ValidateLicenseKeyProtection(
[MarshalAs(UnmanagedType.LPWStr)] string licenseKey, // LPCWSTR
IntPtr notValidBefore, // FILETIME* out
IntPtr notValidAfter, // FILETIME* out
out int status // LicenseProtectionStatus* out
);<DllImport("licenseprotection.dll", ExactSpelling:=True)>
Public Shared Function ValidateLicenseKeyProtection(
<MarshalAs(UnmanagedType.LPWStr)> licenseKey As String, ' LPCWSTR
notValidBefore As IntPtr, ' FILETIME* out
notValidAfter As IntPtr, ' FILETIME* out
<Out> ByRef status As Integer ' LicenseProtectionStatus* out
) As Integer
End Function' licenseKey : LPCWSTR
' notValidBefore : FILETIME* out
' notValidAfter : FILETIME* out
' status : LicenseProtectionStatus* out
Declare PtrSafe Function ValidateLicenseKeyProtection Lib "licenseprotection" ( _
ByVal licenseKey As LongPtr, _
ByVal notValidBefore As LongPtr, _
ByVal notValidAfter As LongPtr, _
ByRef status As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ValidateLicenseKeyProtection = ctypes.windll.licenseprotection.ValidateLicenseKeyProtection
ValidateLicenseKeyProtection.restype = ctypes.c_int
ValidateLicenseKeyProtection.argtypes = [
wintypes.LPCWSTR, # licenseKey : LPCWSTR
ctypes.c_void_p, # notValidBefore : FILETIME* out
ctypes.c_void_p, # notValidAfter : FILETIME* out
ctypes.c_void_p, # status : LicenseProtectionStatus* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('licenseprotection.dll')
ValidateLicenseKeyProtection = Fiddle::Function.new(
lib['ValidateLicenseKeyProtection'],
[
Fiddle::TYPE_VOIDP, # licenseKey : LPCWSTR
Fiddle::TYPE_VOIDP, # notValidBefore : FILETIME* out
Fiddle::TYPE_VOIDP, # notValidAfter : FILETIME* out
Fiddle::TYPE_VOIDP, # status : LicenseProtectionStatus* out
],
Fiddle::TYPE_INT)#[link(name = "licenseprotection")]
extern "system" {
fn ValidateLicenseKeyProtection(
licenseKey: *const u16, // LPCWSTR
notValidBefore: *mut FILETIME, // FILETIME* out
notValidAfter: *mut FILETIME, // FILETIME* out
status: *mut i32 // LicenseProtectionStatus* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("licenseprotection.dll")]
public static extern int ValidateLicenseKeyProtection([MarshalAs(UnmanagedType.LPWStr)] string licenseKey, IntPtr notValidBefore, IntPtr notValidAfter, out int status);
"@
$api = Add-Type -MemberDefinition $sig -Name 'licenseprotection_ValidateLicenseKeyProtection' -Namespace Win32 -PassThru
# $api::ValidateLicenseKeyProtection(licenseKey, notValidBefore, notValidAfter, status)#uselib "licenseprotection.dll"
#func global ValidateLicenseKeyProtection "ValidateLicenseKeyProtection" sptr, sptr, sptr, sptr
; ValidateLicenseKeyProtection licenseKey, varptr(notValidBefore), varptr(notValidAfter), status ; 戻り値は stat
; licenseKey : LPCWSTR -> "sptr"
; notValidBefore : FILETIME* out -> "sptr"
; notValidAfter : FILETIME* out -> "sptr"
; status : LicenseProtectionStatus* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "licenseprotection.dll" #cfunc global ValidateLicenseKeyProtection "ValidateLicenseKeyProtection" wstr, var, var, int ; res = ValidateLicenseKeyProtection(licenseKey, notValidBefore, notValidAfter, status) ; licenseKey : LPCWSTR -> "wstr" ; notValidBefore : FILETIME* out -> "var" ; notValidAfter : FILETIME* out -> "var" ; status : LicenseProtectionStatus* out -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "licenseprotection.dll" #cfunc global ValidateLicenseKeyProtection "ValidateLicenseKeyProtection" wstr, sptr, sptr, int ; res = ValidateLicenseKeyProtection(licenseKey, varptr(notValidBefore), varptr(notValidAfter), status) ; licenseKey : LPCWSTR -> "wstr" ; notValidBefore : FILETIME* out -> "sptr" ; notValidAfter : FILETIME* out -> "sptr" ; status : LicenseProtectionStatus* out -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT ValidateLicenseKeyProtection(LPCWSTR licenseKey, FILETIME* notValidBefore, FILETIME* notValidAfter, LicenseProtectionStatus* status) #uselib "licenseprotection.dll" #cfunc global ValidateLicenseKeyProtection "ValidateLicenseKeyProtection" wstr, var, var, int ; res = ValidateLicenseKeyProtection(licenseKey, notValidBefore, notValidAfter, status) ; licenseKey : LPCWSTR -> "wstr" ; notValidBefore : FILETIME* out -> "var" ; notValidAfter : FILETIME* out -> "var" ; status : LicenseProtectionStatus* out -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT ValidateLicenseKeyProtection(LPCWSTR licenseKey, FILETIME* notValidBefore, FILETIME* notValidAfter, LicenseProtectionStatus* status) #uselib "licenseprotection.dll" #cfunc global ValidateLicenseKeyProtection "ValidateLicenseKeyProtection" wstr, intptr, intptr, int ; res = ValidateLicenseKeyProtection(licenseKey, varptr(notValidBefore), varptr(notValidAfter), status) ; licenseKey : LPCWSTR -> "wstr" ; notValidBefore : FILETIME* out -> "intptr" ; notValidAfter : FILETIME* out -> "intptr" ; status : LicenseProtectionStatus* out -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
licenseprotection = windows.NewLazySystemDLL("licenseprotection.dll")
procValidateLicenseKeyProtection = licenseprotection.NewProc("ValidateLicenseKeyProtection")
)
// licenseKey (LPCWSTR), notValidBefore (FILETIME* out), notValidAfter (FILETIME* out), status (LicenseProtectionStatus* out)
r1, _, err := procValidateLicenseKeyProtection.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(licenseKey))),
uintptr(notValidBefore),
uintptr(notValidAfter),
uintptr(status),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction ValidateLicenseKeyProtection(
licenseKey: PWideChar; // LPCWSTR
notValidBefore: Pointer; // FILETIME* out
notValidAfter: Pointer; // FILETIME* out
status: Pointer // LicenseProtectionStatus* out
): Integer; stdcall;
external 'licenseprotection.dll' name 'ValidateLicenseKeyProtection';result := DllCall("licenseprotection\ValidateLicenseKeyProtection"
, "WStr", licenseKey ; LPCWSTR
, "Ptr", notValidBefore ; FILETIME* out
, "Ptr", notValidAfter ; FILETIME* out
, "Ptr", status ; LicenseProtectionStatus* out
, "Int") ; return: HRESULT●ValidateLicenseKeyProtection(licenseKey, notValidBefore, notValidAfter, status) = DLL("licenseprotection.dll", "int ValidateLicenseKeyProtection(char*, void*, void*, void*)")
# 呼び出し: ValidateLicenseKeyProtection(licenseKey, notValidBefore, notValidAfter, status)
# licenseKey : LPCWSTR -> "char*"
# notValidBefore : FILETIME* out -> "void*"
# notValidAfter : FILETIME* out -> "void*"
# status : LicenseProtectionStatus* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。