Win32 API 日本語リファレンス
ホームSecurity.Authentication.Identity › SLSetCurrentProductKey

SLSetCurrentProductKey

関数
製品SKUに対する現在のプロダクトキーを設定する。
DLLSLC.dll呼出規約winapi対応OSwindows8.0

シグネチャ

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

HRESULT SLSetCurrentProductKey(
    void* hSLC,
    const GUID* pProductSkuId,
    const GUID* pProductKeyId
);

パラメーター

名前方向説明
hSLCvoid*inSLOpenで取得したSLCハンドル。
pProductSkuIdGUID*in対象製品SKUを識別するGUIDへのポインタ。
pProductKeyIdGUID*in現在使用するプロダクトキーとして設定するGUIDへのポインタ。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SLSetCurrentProductKey(
    void* hSLC,
    const GUID* pProductSkuId,
    const GUID* pProductKeyId
);
[DllImport("SLC.dll", ExactSpelling = true)]
static extern int SLSetCurrentProductKey(
    IntPtr hSLC,   // void*
    ref Guid pProductSkuId,   // GUID*
    ref Guid pProductKeyId   // GUID*
);
<DllImport("SLC.dll", ExactSpelling:=True)>
Public Shared Function SLSetCurrentProductKey(
    hSLC As IntPtr,   ' void*
    ByRef pProductSkuId As Guid,   ' GUID*
    ByRef pProductKeyId As Guid   ' GUID*
) As Integer
End Function
' hSLC : void*
' pProductSkuId : GUID*
' pProductKeyId : GUID*
Declare PtrSafe Function SLSetCurrentProductKey Lib "slc" ( _
    ByVal hSLC As LongPtr, _
    ByVal pProductSkuId As LongPtr, _
    ByVal pProductKeyId As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SLSetCurrentProductKey = ctypes.windll.slc.SLSetCurrentProductKey
SLSetCurrentProductKey.restype = ctypes.c_int
SLSetCurrentProductKey.argtypes = [
    ctypes.POINTER(None),  # hSLC : void*
    ctypes.c_void_p,  # pProductSkuId : GUID*
    ctypes.c_void_p,  # pProductKeyId : GUID*
]
require 'fiddle'
require 'fiddle/import'

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

var (
	slc = windows.NewLazySystemDLL("SLC.dll")
	procSLSetCurrentProductKey = slc.NewProc("SLSetCurrentProductKey")
)

// hSLC (void*), pProductSkuId (GUID*), pProductKeyId (GUID*)
r1, _, err := procSLSetCurrentProductKey.Call(
	uintptr(hSLC),
	uintptr(pProductSkuId),
	uintptr(pProductKeyId),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SLSetCurrentProductKey(
  hSLC: Pointer;   // void*
  pProductSkuId: PGUID;   // GUID*
  pProductKeyId: PGUID   // GUID*
): Integer; stdcall;
  external 'SLC.dll' name 'SLSetCurrentProductKey';
result := DllCall("SLC\SLSetCurrentProductKey"
    , "Ptr", hSLC   ; void*
    , "Ptr", pProductSkuId   ; GUID*
    , "Ptr", pProductKeyId   ; GUID*
    , "Int")   ; return: HRESULT
●SLSetCurrentProductKey(hSLC, pProductSkuId, pProductKeyId) = DLL("SLC.dll", "int SLSetCurrentProductKey(void*, void*, void*)")
# 呼び出し: SLSetCurrentProductKey(hSLC, pProductSkuId, pProductKeyId)
# hSLC : void* -> "void*"
# pProductSkuId : GUID* -> "void*"
# pProductKeyId : GUID* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "slc" fn SLSetCurrentProductKey(
    hSLC: ?*anyopaque, // void*
    pProductSkuId: [*c]GUID, // GUID*
    pProductKeyId: [*c]GUID // GUID*
) callconv(std.os.windows.WINAPI) i32;
proc SLSetCurrentProductKey(
    hSLC: pointer,  # void*
    pProductSkuId: ptr GUID,  # GUID*
    pProductKeyId: ptr GUID  # GUID*
): int32 {.importc: "SLSetCurrentProductKey", stdcall, dynlib: "SLC.dll".}
pragma(lib, "slc");
extern(Windows)
int SLSetCurrentProductKey(
    void* hSLC,   // void*
    GUID* pProductSkuId,   // GUID*
    GUID* pProductKeyId   // GUID*
);
ccall((:SLSetCurrentProductKey, "SLC.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{GUID}, Ptr{GUID}),
      hSLC, pProductSkuId, pProductKeyId)
# hSLC : void* -> Ptr{Cvoid}
# pProductSkuId : GUID* -> Ptr{GUID}
# pProductKeyId : GUID* -> Ptr{GUID}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SLSetCurrentProductKey(
    void* hSLC,
    void* pProductSkuId,
    void* pProductKeyId);
]]
local slc = ffi.load("slc")
-- slc.SLSetCurrentProductKey(hSLC, pProductSkuId, pProductKeyId)
-- hSLC : void*
-- pProductSkuId : GUID*
-- pProductKeyId : GUID*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SLC.dll');
const SLSetCurrentProductKey = lib.func('__stdcall', 'SLSetCurrentProductKey', 'int32_t', ['void *', 'void *', 'void *']);
// SLSetCurrentProductKey(hSLC, pProductSkuId, pProductKeyId)
// hSLC : void* -> 'void *'
// pProductSkuId : GUID* -> 'void *'
// pProductKeyId : GUID* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SLC.dll", {
  SLSetCurrentProductKey: { parameters: ["pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SLSetCurrentProductKey(hSLC, pProductSkuId, pProductKeyId)
// hSLC : void* -> "pointer"
// pProductSkuId : GUID* -> "pointer"
// pProductKeyId : GUID* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SLSetCurrentProductKey(
    void* hSLC,
    void* pProductSkuId,
    void* pProductKeyId);
C, "SLC.dll");
// $ffi->SLSetCurrentProductKey(hSLC, pProductSkuId, pProductKeyId);
// hSLC : void*
// pProductSkuId : GUID*
// pProductKeyId : GUID*
// 構造体/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 Slc extends StdCallLibrary {
    Slc INSTANCE = Native.load("slc", Slc.class);
    int SLSetCurrentProductKey(
        Pointer hSLC,   // void*
        Pointer pProductSkuId,   // GUID*
        Pointer pProductKeyId   // GUID*
    );
}
@[Link("slc")]
lib LibSLC
  fun SLSetCurrentProductKey = SLSetCurrentProductKey(
    hSLC : Void*,   # void*
    pProductSkuId : GUID*,   # GUID*
    pProductKeyId : GUID*   # GUID*
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SLSetCurrentProductKeyNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef SLSetCurrentProductKeyDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
final SLSetCurrentProductKey = DynamicLibrary.open('SLC.dll')
    .lookupFunction<SLSetCurrentProductKeyNative, SLSetCurrentProductKeyDart>('SLSetCurrentProductKey');
// hSLC : void* -> Pointer<Void>
// pProductSkuId : GUID* -> Pointer<Void>
// pProductKeyId : GUID* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SLSetCurrentProductKey(
  hSLC: Pointer;   // void*
  pProductSkuId: PGUID;   // GUID*
  pProductKeyId: PGUID   // GUID*
): Integer; stdcall;
  external 'SLC.dll' name 'SLSetCurrentProductKey';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SLSetCurrentProductKey"
  c_SLSetCurrentProductKey :: Ptr () -> Ptr () -> Ptr () -> IO Int32
-- hSLC : void* -> Ptr ()
-- pProductSkuId : GUID* -> Ptr ()
-- pProductKeyId : GUID* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let slsetcurrentproductkey =
  foreign "SLSetCurrentProductKey"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* hSLC : void* -> (ptr void) *)
(* pProductSkuId : GUID* -> (ptr void) *)
(* pProductKeyId : GUID* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library slc (t "SLC.dll"))
(cffi:use-foreign-library slc)

(cffi:defcfun ("SLSetCurrentProductKey" slset-current-product-key :convention :stdcall) :int32
  (h-slc :pointer)   ; void*
  (p-product-sku-id :pointer)   ; GUID*
  (p-product-key-id :pointer))   ; GUID*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SLSetCurrentProductKey = Win32::API::More->new('SLC',
    'int SLSetCurrentProductKey(LPVOID hSLC, LPVOID pProductSkuId, LPVOID pProductKeyId)');
# my $ret = $SLSetCurrentProductKey->Call($hSLC, $pProductSkuId, $pProductKeyId);
# hSLC : void* -> LPVOID
# pProductSkuId : GUID* -> LPVOID
# pProductKeyId : GUID* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。