Win32 API 日本語リファレンス
ホームNetworking.Clustering › ResUtilGetSzValue

ResUtilGetSzValue

関数
クラスタキーから文字列値を取得する。
DLLRESUTILS.dll呼出規約winapiSetLastErrorあり対応OSwindowsserver2008

シグネチャ

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

LPWSTR ResUtilGetSzValue(
    HKEY hkeyClusterKey,
    LPCWSTR pszValueName
);

パラメーター

名前方向説明
hkeyClusterKeyHKEYin文字列値を読み取る対象のクラスターレジストリキー。
pszValueNameLPCWSTRin読み取る値の名前を示すワイド文字列。

戻り値の型: LPWSTR

各言語での呼び出し定義

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

LPWSTR ResUtilGetSzValue(
    HKEY hkeyClusterKey,
    LPCWSTR pszValueName
);
[DllImport("RESUTILS.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr ResUtilGetSzValue(
    IntPtr hkeyClusterKey,   // HKEY
    [MarshalAs(UnmanagedType.LPWStr)] string pszValueName   // LPCWSTR
);
<DllImport("RESUTILS.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function ResUtilGetSzValue(
    hkeyClusterKey As IntPtr,   ' HKEY
    <MarshalAs(UnmanagedType.LPWStr)> pszValueName As String   ' LPCWSTR
) As IntPtr
End Function
' hkeyClusterKey : HKEY
' pszValueName : LPCWSTR
Declare PtrSafe Function ResUtilGetSzValue Lib "resutils" ( _
    ByVal hkeyClusterKey As LongPtr, _
    ByVal pszValueName As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ResUtilGetSzValue = ctypes.windll.resutils.ResUtilGetSzValue
ResUtilGetSzValue.restype = wintypes.LPWSTR
ResUtilGetSzValue.argtypes = [
    wintypes.HANDLE,  # hkeyClusterKey : HKEY
    wintypes.LPCWSTR,  # pszValueName : LPCWSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('RESUTILS.dll')
ResUtilGetSzValue = Fiddle::Function.new(
  lib['ResUtilGetSzValue'],
  [
    Fiddle::TYPE_VOIDP,  # hkeyClusterKey : HKEY
    Fiddle::TYPE_VOIDP,  # pszValueName : LPCWSTR
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "resutils")]
extern "system" {
    fn ResUtilGetSzValue(
        hkeyClusterKey: *mut core::ffi::c_void,  // HKEY
        pszValueName: *const u16  // LPCWSTR
    ) -> *mut u16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("RESUTILS.dll", SetLastError = true)]
public static extern IntPtr ResUtilGetSzValue(IntPtr hkeyClusterKey, [MarshalAs(UnmanagedType.LPWStr)] string pszValueName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'RESUTILS_ResUtilGetSzValue' -Namespace Win32 -PassThru
# $api::ResUtilGetSzValue(hkeyClusterKey, pszValueName)
#uselib "RESUTILS.dll"
#func global ResUtilGetSzValue "ResUtilGetSzValue" sptr, sptr
; ResUtilGetSzValue hkeyClusterKey, pszValueName   ; 戻り値は stat
; hkeyClusterKey : HKEY -> "sptr"
; pszValueName : LPCWSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "RESUTILS.dll"
#cfunc global ResUtilGetSzValue "ResUtilGetSzValue" sptr, wstr
; res = ResUtilGetSzValue(hkeyClusterKey, pszValueName)
; hkeyClusterKey : HKEY -> "sptr"
; pszValueName : LPCWSTR -> "wstr"
; LPWSTR ResUtilGetSzValue(HKEY hkeyClusterKey, LPCWSTR pszValueName)
#uselib "RESUTILS.dll"
#cfunc global ResUtilGetSzValue "ResUtilGetSzValue" intptr, wstr
; res = ResUtilGetSzValue(hkeyClusterKey, pszValueName)
; hkeyClusterKey : HKEY -> "intptr"
; pszValueName : LPCWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	resutils = windows.NewLazySystemDLL("RESUTILS.dll")
	procResUtilGetSzValue = resutils.NewProc("ResUtilGetSzValue")
)

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

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

typedef ResUtilGetSzValueNative = Pointer<Utf16> Function(Pointer<Void>, Pointer<Utf16>);
typedef ResUtilGetSzValueDart = Pointer<Utf16> Function(Pointer<Void>, Pointer<Utf16>);
final ResUtilGetSzValue = DynamicLibrary.open('RESUTILS.dll')
    .lookupFunction<ResUtilGetSzValueNative, ResUtilGetSzValueDart>('ResUtilGetSzValue');
// hkeyClusterKey : HKEY -> Pointer<Void>
// pszValueName : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ResUtilGetSzValue(
  hkeyClusterKey: THandle;   // HKEY
  pszValueName: PWideChar   // LPCWSTR
): PWideChar; stdcall;
  external 'RESUTILS.dll' name 'ResUtilGetSzValue';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ResUtilGetSzValue"
  c_ResUtilGetSzValue :: Ptr () -> CWString -> IO CWString
-- hkeyClusterKey : HKEY -> Ptr ()
-- pszValueName : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let resutilgetszvalue =
  foreign "ResUtilGetSzValue"
    ((ptr void) @-> (ptr uint16_t) @-> returning (ptr uint16_t))
(* hkeyClusterKey : HKEY -> (ptr void) *)
(* pszValueName : LPCWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library resutils (t "RESUTILS.dll"))
(cffi:use-foreign-library resutils)

(cffi:defcfun ("ResUtilGetSzValue" res-util-get-sz-value :convention :stdcall) (:string :encoding :utf-16le)
  (hkey-cluster-key :pointer)   ; HKEY
  (psz-value-name (:string :encoding :utf-16le)))   ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ResUtilGetSzValue = Win32::API::More->new('RESUTILS',
    'LPWSTR ResUtilGetSzValue(HANDLE hkeyClusterKey, LPCWSTR pszValueName)');
# my $ret = $ResUtilGetSzValue->Call($hkeyClusterKey, $pszValueName);
# hkeyClusterKey : HKEY -> HANDLE
# pszValueName : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。