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

WindowsCreateStringReference

関数
コピーせず既存バッファを参照する高速HSTRING参照を生成する。
DLLapi-ms-win-core-winrt-string-l1-1-0.dll呼出規約winapi対応OSwindows8.0

シグネチャ

// api-ms-win-core-winrt-string-l1-1-0.dll
#include <windows.h>

HRESULT WindowsCreateStringReference(
    LPCWSTR sourceString,   // optional
    DWORD length,
    HSTRING_HEADER* hstringHeader,
    HSTRING* string
);

パラメーター

名前方向
sourceStringLPCWSTRinoptional
lengthDWORDin
hstringHeaderHSTRING_HEADER*out
stringHSTRING*out

戻り値の型: HRESULT

各言語での呼び出し定義

// api-ms-win-core-winrt-string-l1-1-0.dll
#include <windows.h>

HRESULT WindowsCreateStringReference(
    LPCWSTR sourceString,   // optional
    DWORD length,
    HSTRING_HEADER* hstringHeader,
    HSTRING* string
);
[DllImport("api-ms-win-core-winrt-string-l1-1-0.dll", ExactSpelling = true)]
static extern int WindowsCreateStringReference(
    [MarshalAs(UnmanagedType.LPWStr)] string sourceString,   // LPCWSTR optional
    uint length,   // DWORD
    IntPtr hstringHeader,   // HSTRING_HEADER* out
    IntPtr string   // HSTRING* out
);
<DllImport("api-ms-win-core-winrt-string-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function WindowsCreateStringReference(
    <MarshalAs(UnmanagedType.LPWStr)> sourceString As String,   ' LPCWSTR optional
    length As UInteger,   ' DWORD
    hstringHeader As IntPtr,   ' HSTRING_HEADER* out
    [string] As IntPtr   ' HSTRING* out
) As Integer
End Function
' sourceString : LPCWSTR optional
' length : DWORD
' hstringHeader : HSTRING_HEADER* out
' string : HSTRING* out
Declare PtrSafe Function WindowsCreateStringReference Lib "api-ms-win-core-winrt-string-l1-1-0" ( _
    ByVal sourceString As LongPtr, _
    ByVal length As Long, _
    ByVal hstringHeader As LongPtr, _
    ByVal string As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WindowsCreateStringReference = ctypes.windll.LoadLibrary("api-ms-win-core-winrt-string-l1-1-0.dll").WindowsCreateStringReference
WindowsCreateStringReference.restype = ctypes.c_int
WindowsCreateStringReference.argtypes = [
    wintypes.LPCWSTR,  # sourceString : LPCWSTR optional
    wintypes.DWORD,  # length : DWORD
    ctypes.c_void_p,  # hstringHeader : HSTRING_HEADER* out
    ctypes.c_void_p,  # string : HSTRING* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	api_ms_win_core_winrt_string_l1_1_0 = windows.NewLazySystemDLL("api-ms-win-core-winrt-string-l1-1-0.dll")
	procWindowsCreateStringReference = api_ms_win_core_winrt_string_l1_1_0.NewProc("WindowsCreateStringReference")
)

// sourceString (LPCWSTR optional), length (DWORD), hstringHeader (HSTRING_HEADER* out), string (HSTRING* out)
r1, _, err := procWindowsCreateStringReference.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(sourceString))),
	uintptr(length),
	uintptr(hstringHeader),
	uintptr(string),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function WindowsCreateStringReference(
  sourceString: PWideChar;   // LPCWSTR optional
  length: DWORD;   // DWORD
  hstringHeader: Pointer;   // HSTRING_HEADER* out
  string: Pointer   // HSTRING* out
): Integer; stdcall;
  external 'api-ms-win-core-winrt-string-l1-1-0.dll' name 'WindowsCreateStringReference';
result := DllCall("api-ms-win-core-winrt-string-l1-1-0\WindowsCreateStringReference"
    , "WStr", sourceString   ; LPCWSTR optional
    , "UInt", length   ; DWORD
    , "Ptr", hstringHeader   ; HSTRING_HEADER* out
    , "Ptr", string   ; HSTRING* out
    , "Int")   ; return: HRESULT
●WindowsCreateStringReference(sourceString, length, hstringHeader, string) = DLL("api-ms-win-core-winrt-string-l1-1-0.dll", "int WindowsCreateStringReference(char*, dword, void*, void*)")
# 呼び出し: WindowsCreateStringReference(sourceString, length, hstringHeader, string)
# sourceString : LPCWSTR optional -> "char*"
# length : DWORD -> "dword"
# hstringHeader : HSTRING_HEADER* out -> "void*"
# string : HSTRING* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。