Win32 API 日本語リファレンス
ホームSystem.WindowsProgramming › RtlInitUnicodeString

RtlInitUnicodeString

関数
Unicode文字列構造体を初期化する。
DLLntdll.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

void RtlInitUnicodeString(
    UNICODE_STRING* DestinationString,
    LPCWSTR SourceString
);

パラメーター

名前方向説明
DestinationStringUNICODE_STRING*inout初期化対象のUNICODE_STRING構造体へのポインタ。
SourceStringLPCWSTRin格納するNUL終端ワイド文字列。NULL指定で空文字列に初期化される。

戻り値の型: void

各言語での呼び出し定義

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

void RtlInitUnicodeString(
    UNICODE_STRING* DestinationString,
    LPCWSTR SourceString
);
[DllImport("ntdll.dll", ExactSpelling = true)]
static extern void RtlInitUnicodeString(
    IntPtr DestinationString,   // UNICODE_STRING* in/out
    [MarshalAs(UnmanagedType.LPWStr)] string SourceString   // LPCWSTR
);
<DllImport("ntdll.dll", ExactSpelling:=True)>
Public Shared Sub RtlInitUnicodeString(
    DestinationString As IntPtr,   ' UNICODE_STRING* in/out
    <MarshalAs(UnmanagedType.LPWStr)> SourceString As String   ' LPCWSTR
)
End Sub
' DestinationString : UNICODE_STRING* in/out
' SourceString : LPCWSTR
Declare PtrSafe Sub RtlInitUnicodeString Lib "ntdll" ( _
    ByVal DestinationString As LongPtr, _
    ByVal SourceString As LongPtr)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RtlInitUnicodeString = ctypes.windll.ntdll.RtlInitUnicodeString
RtlInitUnicodeString.restype = None
RtlInitUnicodeString.argtypes = [
    ctypes.c_void_p,  # DestinationString : UNICODE_STRING* in/out
    wintypes.LPCWSTR,  # SourceString : LPCWSTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ntdll.dll')
RtlInitUnicodeString = Fiddle::Function.new(
  lib['RtlInitUnicodeString'],
  [
    Fiddle::TYPE_VOIDP,  # DestinationString : UNICODE_STRING* in/out
    Fiddle::TYPE_VOIDP,  # SourceString : LPCWSTR
  ],
  Fiddle::TYPE_VOID)
#[link(name = "ntdll")]
extern "system" {
    fn RtlInitUnicodeString(
        DestinationString: *mut UNICODE_STRING,  // UNICODE_STRING* in/out
        SourceString: *const u16  // LPCWSTR
    );
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ntdll.dll")]
public static extern void RtlInitUnicodeString(IntPtr DestinationString, [MarshalAs(UnmanagedType.LPWStr)] string SourceString);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ntdll_RtlInitUnicodeString' -Namespace Win32 -PassThru
# $api::RtlInitUnicodeString(DestinationString, SourceString)
#uselib "ntdll.dll"
#func global RtlInitUnicodeString "RtlInitUnicodeString" sptr, sptr
; RtlInitUnicodeString varptr(DestinationString), SourceString
; DestinationString : UNICODE_STRING* in/out -> "sptr"
; SourceString : LPCWSTR -> "sptr"
出力引数:
#uselib "ntdll.dll"
#func global RtlInitUnicodeString "RtlInitUnicodeString" var, wstr
; RtlInitUnicodeString DestinationString, SourceString
; DestinationString : UNICODE_STRING* in/out -> "var"
; SourceString : LPCWSTR -> "wstr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void RtlInitUnicodeString(UNICODE_STRING* DestinationString, LPCWSTR SourceString)
#uselib "ntdll.dll"
#func global RtlInitUnicodeString "RtlInitUnicodeString" var, wstr
; RtlInitUnicodeString DestinationString, SourceString
; DestinationString : UNICODE_STRING* in/out -> "var"
; SourceString : LPCWSTR -> "wstr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ntdll = windows.NewLazySystemDLL("ntdll.dll")
	procRtlInitUnicodeString = ntdll.NewProc("RtlInitUnicodeString")
)

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

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

typedef RtlInitUnicodeStringNative = Void Function(Pointer<Void>, Pointer<Utf16>);
typedef RtlInitUnicodeStringDart = void Function(Pointer<Void>, Pointer<Utf16>);
final RtlInitUnicodeString = DynamicLibrary.open('ntdll.dll')
    .lookupFunction<RtlInitUnicodeStringNative, RtlInitUnicodeStringDart>('RtlInitUnicodeString');
// DestinationString : UNICODE_STRING* in/out -> Pointer<Void>
// SourceString : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
procedure RtlInitUnicodeString(
  DestinationString: Pointer;   // UNICODE_STRING* in/out
  SourceString: PWideChar   // LPCWSTR
); stdcall;
  external 'ntdll.dll' name 'RtlInitUnicodeString';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RtlInitUnicodeString"
  c_RtlInitUnicodeString :: Ptr () -> CWString -> IO ()
-- DestinationString : UNICODE_STRING* in/out -> Ptr ()
-- SourceString : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let rtlinitunicodestring =
  foreign "RtlInitUnicodeString"
    ((ptr void) @-> (ptr uint16_t) @-> returning void)
(* DestinationString : UNICODE_STRING* in/out -> (ptr void) *)
(* SourceString : LPCWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library ntdll (t "ntdll.dll"))
(cffi:use-foreign-library ntdll)

(cffi:defcfun ("RtlInitUnicodeString" rtl-init-unicode-string :convention :stdcall) :void
  (destination-string :pointer)   ; UNICODE_STRING* in/out
  (source-string (:string :encoding :utf-16le)))   ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RtlInitUnicodeString = Win32::API::More->new('ntdll',
    'void RtlInitUnicodeString(LPVOID DestinationString, LPCWSTR SourceString)');
# my $ret = $RtlInitUnicodeString->Call($DestinationString, $SourceString);
# DestinationString : UNICODE_STRING* in/out -> LPVOID
# SourceString : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型