ホーム › 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), varptr(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, var ; res = ValidateLicenseKeyProtection(licenseKey, notValidBefore, notValidAfter, status) ; licenseKey : LPCWSTR -> "wstr" ; notValidBefore : FILETIME* out -> "var" ; notValidAfter : FILETIME* out -> "var" ; status : LicenseProtectionStatus* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "licenseprotection.dll" #cfunc global ValidateLicenseKeyProtection "ValidateLicenseKeyProtection" wstr, sptr, sptr, sptr ; res = ValidateLicenseKeyProtection(licenseKey, varptr(notValidBefore), varptr(notValidAfter), varptr(status)) ; licenseKey : LPCWSTR -> "wstr" ; notValidBefore : FILETIME* out -> "sptr" ; notValidAfter : FILETIME* out -> "sptr" ; status : LicenseProtectionStatus* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT ValidateLicenseKeyProtection(LPCWSTR licenseKey, FILETIME* notValidBefore, FILETIME* notValidAfter, LicenseProtectionStatus* status) #uselib "licenseprotection.dll" #cfunc global ValidateLicenseKeyProtection "ValidateLicenseKeyProtection" wstr, var, var, var ; res = ValidateLicenseKeyProtection(licenseKey, notValidBefore, notValidAfter, status) ; licenseKey : LPCWSTR -> "wstr" ; notValidBefore : FILETIME* out -> "var" ; notValidAfter : FILETIME* out -> "var" ; status : LicenseProtectionStatus* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT ValidateLicenseKeyProtection(LPCWSTR licenseKey, FILETIME* notValidBefore, FILETIME* notValidAfter, LicenseProtectionStatus* status) #uselib "licenseprotection.dll" #cfunc global ValidateLicenseKeyProtection "ValidateLicenseKeyProtection" wstr, intptr, intptr, intptr ; res = ValidateLicenseKeyProtection(licenseKey, varptr(notValidBefore), varptr(notValidAfter), varptr(status)) ; licenseKey : LPCWSTR -> "wstr" ; notValidBefore : FILETIME* out -> "intptr" ; notValidAfter : FILETIME* out -> "intptr" ; status : LicenseProtectionStatus* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(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)。const std = @import("std");
extern "licenseprotection" fn ValidateLicenseKeyProtection(
licenseKey: [*c]const u16, // LPCWSTR
notValidBefore: [*c]FILETIME, // FILETIME* out
notValidAfter: [*c]FILETIME, // FILETIME* out
status: [*c]i32 // LicenseProtectionStatus* out
) callconv(std.os.windows.WINAPI) i32;proc ValidateLicenseKeyProtection(
licenseKey: WideCString, # LPCWSTR
notValidBefore: ptr FILETIME, # FILETIME* out
notValidAfter: ptr FILETIME, # FILETIME* out
status: ptr int32 # LicenseProtectionStatus* out
): int32 {.importc: "ValidateLicenseKeyProtection", stdcall, dynlib: "licenseprotection.dll".}pragma(lib, "licenseprotection");
extern(Windows)
int ValidateLicenseKeyProtection(
const(wchar)* licenseKey, // LPCWSTR
FILETIME* notValidBefore, // FILETIME* out
FILETIME* notValidAfter, // FILETIME* out
int* status // LicenseProtectionStatus* out
);ccall((:ValidateLicenseKeyProtection, "licenseprotection.dll"), stdcall, Int32,
(Cwstring, Ptr{FILETIME}, Ptr{FILETIME}, Ptr{Int32}),
licenseKey, notValidBefore, notValidAfter, status)
# licenseKey : LPCWSTR -> Cwstring
# notValidBefore : FILETIME* out -> Ptr{FILETIME}
# notValidAfter : FILETIME* out -> Ptr{FILETIME}
# status : LicenseProtectionStatus* out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t ValidateLicenseKeyProtection(
const uint16_t* licenseKey,
void* notValidBefore,
void* notValidAfter,
int32_t* status);
]]
local licenseprotection = ffi.load("licenseprotection")
-- licenseprotection.ValidateLicenseKeyProtection(licenseKey, notValidBefore, notValidAfter, status)
-- licenseKey : LPCWSTR
-- notValidBefore : FILETIME* out
-- notValidAfter : FILETIME* out
-- status : LicenseProtectionStatus* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('licenseprotection.dll');
const ValidateLicenseKeyProtection = lib.func('__stdcall', 'ValidateLicenseKeyProtection', 'int32_t', ['str16', 'void *', 'void *', 'int32_t *']);
// ValidateLicenseKeyProtection(licenseKey, notValidBefore, notValidAfter, status)
// licenseKey : LPCWSTR -> 'str16'
// notValidBefore : FILETIME* out -> 'void *'
// notValidAfter : FILETIME* out -> 'void *'
// status : LicenseProtectionStatus* out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("licenseprotection.dll", {
ValidateLicenseKeyProtection: { parameters: ["buffer", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.ValidateLicenseKeyProtection(licenseKey, notValidBefore, notValidAfter, status)
// licenseKey : LPCWSTR -> "buffer"
// notValidBefore : FILETIME* out -> "pointer"
// notValidAfter : FILETIME* out -> "pointer"
// status : LicenseProtectionStatus* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ValidateLicenseKeyProtection(
const uint16_t* licenseKey,
void* notValidBefore,
void* notValidAfter,
int32_t* status);
C, "licenseprotection.dll");
// $ffi->ValidateLicenseKeyProtection(licenseKey, notValidBefore, notValidAfter, status);
// licenseKey : LPCWSTR
// notValidBefore : FILETIME* out
// notValidAfter : FILETIME* out
// status : LicenseProtectionStatus* 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 Licenseprotection extends StdCallLibrary {
Licenseprotection INSTANCE = Native.load("licenseprotection", Licenseprotection.class);
int ValidateLicenseKeyProtection(
WString licenseKey, // LPCWSTR
Pointer notValidBefore, // FILETIME* out
Pointer notValidAfter, // FILETIME* out
IntByReference status // LicenseProtectionStatus* out
);
}@[Link("licenseprotection")]
lib Liblicenseprotection
fun ValidateLicenseKeyProtection = ValidateLicenseKeyProtection(
licenseKey : UInt16*, # LPCWSTR
notValidBefore : FILETIME*, # FILETIME* out
notValidAfter : FILETIME*, # FILETIME* out
status : Int32* # LicenseProtectionStatus* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ValidateLicenseKeyProtectionNative = Int32 Function(Pointer<Utf16>, Pointer<Void>, Pointer<Void>, Pointer<Int32>);
typedef ValidateLicenseKeyProtectionDart = int Function(Pointer<Utf16>, Pointer<Void>, Pointer<Void>, Pointer<Int32>);
final ValidateLicenseKeyProtection = DynamicLibrary.open('licenseprotection.dll')
.lookupFunction<ValidateLicenseKeyProtectionNative, ValidateLicenseKeyProtectionDart>('ValidateLicenseKeyProtection');
// licenseKey : LPCWSTR -> Pointer<Utf16>
// notValidBefore : FILETIME* out -> Pointer<Void>
// notValidAfter : FILETIME* out -> Pointer<Void>
// status : LicenseProtectionStatus* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ValidateLicenseKeyProtection(
licenseKey: PWideChar; // LPCWSTR
notValidBefore: Pointer; // FILETIME* out
notValidAfter: Pointer; // FILETIME* out
status: Pointer // LicenseProtectionStatus* out
): Integer; stdcall;
external 'licenseprotection.dll' name 'ValidateLicenseKeyProtection';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ValidateLicenseKeyProtection"
c_ValidateLicenseKeyProtection :: CWString -> Ptr () -> Ptr () -> Ptr Int32 -> IO Int32
-- licenseKey : LPCWSTR -> CWString
-- notValidBefore : FILETIME* out -> Ptr ()
-- notValidAfter : FILETIME* out -> Ptr ()
-- status : LicenseProtectionStatus* out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let validatelicensekeyprotection =
foreign "ValidateLicenseKeyProtection"
((ptr uint16_t) @-> (ptr void) @-> (ptr void) @-> (ptr int32_t) @-> returning int32_t)
(* licenseKey : LPCWSTR -> (ptr uint16_t) *)
(* notValidBefore : FILETIME* out -> (ptr void) *)
(* notValidAfter : FILETIME* out -> (ptr void) *)
(* status : LicenseProtectionStatus* out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library licenseprotection (t "licenseprotection.dll"))
(cffi:use-foreign-library licenseprotection)
(cffi:defcfun ("ValidateLicenseKeyProtection" validate-license-key-protection :convention :stdcall) :int32
(license-key (:string :encoding :utf-16le)) ; LPCWSTR
(not-valid-before :pointer) ; FILETIME* out
(not-valid-after :pointer) ; FILETIME* out
(status :pointer)) ; LicenseProtectionStatus* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ValidateLicenseKeyProtection = Win32::API::More->new('licenseprotection',
'int ValidateLicenseKeyProtection(LPCWSTR licenseKey, LPVOID notValidBefore, LPVOID notValidAfter, LPVOID status)');
# my $ret = $ValidateLicenseKeyProtection->Call($licenseKey, $notValidBefore, $notValidAfter, $status);
# licenseKey : LPCWSTR -> LPCWSTR
# notValidBefore : FILETIME* out -> LPVOID
# notValidAfter : FILETIME* out -> LPVOID
# status : LicenseProtectionStatus* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。