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

SLGetWindowsInformationDWORD

関数
Windowsライセンスに関する情報の値をDWORD型で取得する。
DLLSLC.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT SLGetWindowsInformationDWORD(
    LPCWSTR pwszValueName,
    DWORD* pdwValue
);

パラメーター

名前方向説明
pwszValueNameLPCWSTRin取得するDWORD型Windowsライセンス情報値の名前を指すUnicode文字列。
pdwValueDWORD*out取得した値(DWORD)を受け取るポインタ。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SLGetWindowsInformationDWORD(
    LPCWSTR pwszValueName,
    DWORD* pdwValue
);
[DllImport("SLC.dll", ExactSpelling = true)]
static extern int SLGetWindowsInformationDWORD(
    [MarshalAs(UnmanagedType.LPWStr)] string pwszValueName,   // LPCWSTR
    out uint pdwValue   // DWORD* out
);
<DllImport("SLC.dll", ExactSpelling:=True)>
Public Shared Function SLGetWindowsInformationDWORD(
    <MarshalAs(UnmanagedType.LPWStr)> pwszValueName As String,   ' LPCWSTR
    <Out> ByRef pdwValue As UInteger   ' DWORD* out
) As Integer
End Function
' pwszValueName : LPCWSTR
' pdwValue : DWORD* out
Declare PtrSafe Function SLGetWindowsInformationDWORD Lib "slc" ( _
    ByVal pwszValueName As LongPtr, _
    ByRef pdwValue As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SLGetWindowsInformationDWORD = ctypes.windll.slc.SLGetWindowsInformationDWORD
SLGetWindowsInformationDWORD.restype = ctypes.c_int
SLGetWindowsInformationDWORD.argtypes = [
    wintypes.LPCWSTR,  # pwszValueName : LPCWSTR
    ctypes.POINTER(wintypes.DWORD),  # pdwValue : DWORD* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	slc = windows.NewLazySystemDLL("SLC.dll")
	procSLGetWindowsInformationDWORD = slc.NewProc("SLGetWindowsInformationDWORD")
)

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

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

typedef SLGetWindowsInformationDWORDNative = Int32 Function(Pointer<Utf16>, Pointer<Uint32>);
typedef SLGetWindowsInformationDWORDDart = int Function(Pointer<Utf16>, Pointer<Uint32>);
final SLGetWindowsInformationDWORD = DynamicLibrary.open('SLC.dll')
    .lookupFunction<SLGetWindowsInformationDWORDNative, SLGetWindowsInformationDWORDDart>('SLGetWindowsInformationDWORD');
// pwszValueName : LPCWSTR -> Pointer<Utf16>
// pdwValue : DWORD* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SLGetWindowsInformationDWORD(
  pwszValueName: PWideChar;   // LPCWSTR
  pdwValue: Pointer   // DWORD* out
): Integer; stdcall;
  external 'SLC.dll' name 'SLGetWindowsInformationDWORD';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SLGetWindowsInformationDWORD"
  c_SLGetWindowsInformationDWORD :: CWString -> Ptr Word32 -> IO Int32
-- pwszValueName : LPCWSTR -> CWString
-- pdwValue : DWORD* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let slgetwindowsinformationdword =
  foreign "SLGetWindowsInformationDWORD"
    ((ptr uint16_t) @-> (ptr uint32_t) @-> returning int32_t)
(* pwszValueName : LPCWSTR -> (ptr uint16_t) *)
(* pdwValue : DWORD* out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library slc (t "SLC.dll"))
(cffi:use-foreign-library slc)

(cffi:defcfun ("SLGetWindowsInformationDWORD" slget-windows-information-dword :convention :stdcall) :int32
  (pwsz-value-name (:string :encoding :utf-16le))   ; LPCWSTR
  (pdw-value :pointer))   ; DWORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SLGetWindowsInformationDWORD = Win32::API::More->new('SLC',
    'int SLGetWindowsInformationDWORD(LPCWSTR pwszValueName, LPVOID pdwValue)');
# my $ret = $SLGetWindowsInformationDWORD->Call($pwszValueName, $pdwValue);
# pwszValueName : LPCWSTR -> LPCWSTR
# pdwValue : DWORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。