Win32 API 日本語リファレンス
ホームFoundation › UNICODE_STRING

UNICODE_STRING

構造体
サイズx64: 16 バイト / x86: 8 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
LengthWORD2+0+0

Buffer メンバーが指す文字列の長さをバイト単位で指定します。終端の NULL 文字がある場合、その分は含みません。

Windows 7、Windows Server 2008、Windows Vista、Windows Server 2003 および Windows XP: Length 構造体メンバーが 0 で、MaximumLength 構造体メンバーが 1 の場合、Buffer 構造体メンバーは空の文字列であるか、null 文字のみを含むことがあります。この動作は Windows Server 2008 R2 および Windows 7 with SP1 以降で変更されました。

MaximumLengthWORD2+2+2

Buffer 用に割り当てられたメモリの合計サイズをバイト単位で指定します。メモリを破壊することなく、最大 MaximumLength バイトまでバッファーに書き込むことができます。

Windows 7、Windows Server 2008、Windows Vista、Windows Server 2003 および Windows XP: Length 構造体メンバーが 0 で、MaximumLength 構造体メンバーが 1 の場合、Buffer 構造体メンバーは空の文字列であるか、null 文字のみを含むことがあります。この動作は Windows Server 2008 R2 および Windows 7 with SP1 以降で変更されました。

BufferLPWSTR8/4+8+4

ワイド文字列へのポインターです。各種 LSA 関数が返す文字列は null 終端でない場合がある点に注意してください。

Windows 7、Windows Server 2008、Windows Vista、Windows Server 2003 および Windows XP: Length 構造体メンバーが 0 で、MaximumLength 構造体メンバーが 1 の場合、Buffer 構造体メンバーは空の文字列であるか、null 文字のみを含むことがあります。この動作は Windows Server 2008 R2 および Windows 7 with SP1 以降で変更されました。

公式ドキュメント

UNICODE_STRING 構造体は、Unicode 文字列を指定するために、さまざまな ローカル セキュリティ機関 (LSA) 関数で使用されます。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での定義

#include <windows.h>

// UNICODE_STRING  (x64 16 / x86 8 バイト)
typedef struct UNICODE_STRING {
    WORD Length;
    WORD MaximumLength;
    LPWSTR Buffer;
} UNICODE_STRING;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct UNICODE_STRING
{
    public ushort Length;
    public ushort MaximumLength;
    public IntPtr Buffer;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure UNICODE_STRING
    Public Length As UShort
    Public MaximumLength As UShort
    Public Buffer As IntPtr
End Structure
import ctypes
from ctypes import wintypes

class UNICODE_STRING(ctypes.Structure):
    _fields_ = [
        ("Length", ctypes.c_ushort),
        ("MaximumLength", ctypes.c_ushort),
        ("Buffer", ctypes.c_void_p),
    ]
#[repr(C)]
pub struct UNICODE_STRING {
    pub Length: u16,
    pub MaximumLength: u16,
    pub Buffer: *mut core::ffi::c_void,
}
import "golang.org/x/sys/windows"

type UNICODE_STRING struct {
	Length uint16
	MaximumLength uint16
	Buffer uintptr
}
type
  UNICODE_STRING = record
    Length: Word;
    MaximumLength: Word;
    Buffer: Pointer;
  end;
const UNICODE_STRING = extern struct {
    Length: u16,
    MaximumLength: u16,
    Buffer: ?*anyopaque,
};
type
  UNICODE_STRING {.bycopy.} = object
    Length: uint16
    MaximumLength: uint16
    Buffer: pointer
struct UNICODE_STRING
{
    ushort Length;
    ushort MaximumLength;
    void* Buffer;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; UNICODE_STRING サイズ: 8 バイト(x86)
dim st, 2    ; 4byte整数×2(構造体サイズ 8 / 4 切り上げ)
; Length : WORD (+0, 2byte)  wpoke st,0,値  /  値 = wpeek(st,0)
; MaximumLength : WORD (+2, 2byte)  wpoke st,2,値  /  値 = wpeek(st,2)
; Buffer : LPWSTR (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; UNICODE_STRING サイズ: 16 バイト(x64)
dim st, 4    ; 4byte整数×4(構造体サイズ 16 / 4 切り上げ)
; Length : WORD (+0, 2byte)  wpoke st,0,値  /  値 = wpeek(st,0)
; MaximumLength : WORD (+2, 2byte)  wpoke st,2,値  /  値 = wpeek(st,2)
; Buffer : LPWSTR (+8, 8byte)  qpoke st,8,値 / qpeek(st,8)  ※IronHSPのみ。3.7/3.8は lpoke st,8,下位 : lpoke st,12,上位
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global UNICODE_STRING
    #field short Length
    #field short MaximumLength
    #field intptr Buffer
#endstruct

stdim st, UNICODE_STRING        ; NSTRUCT 変数を確保
st->Length = 100
mes "Length=" + st->Length