ホーム › System.WinRT › WindowsCreateString
WindowsCreateString
関数UTF-16文字列から新しいHSTRING(WinRT文字列)を生成する。
シグネチャ
// api-ms-win-core-winrt-string-l1-1-0.dll
#include <windows.h>
HRESULT WindowsCreateString(
LPCWSTR sourceString, // optional
DWORD length,
HSTRING* string
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| sourceString | LPCWSTR | inoptional | コピー元となるUTF-16文字列。NULLで空文字列を生成。 |
| length | DWORD | in | ソース文字列の文字数(NUL終端を含まない)。 |
| string | HSTRING* | out | 出力として生成されたHSTRINGを受け取るポインタ。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// api-ms-win-core-winrt-string-l1-1-0.dll
#include <windows.h>
HRESULT WindowsCreateString(
LPCWSTR sourceString, // optional
DWORD length,
HSTRING* string
);[DllImport("api-ms-win-core-winrt-string-l1-1-0.dll", ExactSpelling = true)]
static extern int WindowsCreateString(
[MarshalAs(UnmanagedType.LPWStr)] string sourceString, // LPCWSTR optional
uint length, // DWORD
IntPtr string // HSTRING* out
);<DllImport("api-ms-win-core-winrt-string-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function WindowsCreateString(
<MarshalAs(UnmanagedType.LPWStr)> sourceString As String, ' LPCWSTR optional
length As UInteger, ' DWORD
[string] As IntPtr ' HSTRING* out
) As Integer
End Function' sourceString : LPCWSTR optional
' length : DWORD
' string : HSTRING* out
Declare PtrSafe Function WindowsCreateString Lib "api-ms-win-core-winrt-string-l1-1-0" ( _
ByVal sourceString As LongPtr, _
ByVal length As Long, _
ByVal string As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WindowsCreateString = ctypes.windll.LoadLibrary("api-ms-win-core-winrt-string-l1-1-0.dll").WindowsCreateString
WindowsCreateString.restype = ctypes.c_int
WindowsCreateString.argtypes = [
wintypes.LPCWSTR, # sourceString : LPCWSTR optional
wintypes.DWORD, # length : DWORD
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')
WindowsCreateString = Fiddle::Function.new(
lib['WindowsCreateString'],
[
Fiddle::TYPE_VOIDP, # sourceString : LPCWSTR optional
-Fiddle::TYPE_INT, # length : DWORD
Fiddle::TYPE_VOIDP, # string : HSTRING* out
],
Fiddle::TYPE_INT)#[link(name = "api-ms-win-core-winrt-string-l1-1-0")]
extern "system" {
fn WindowsCreateString(
sourceString: *const u16, // LPCWSTR optional
length: u32, // DWORD
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 WindowsCreateString([MarshalAs(UnmanagedType.LPWStr)] string sourceString, uint length, IntPtr string);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-winrt-string-l1-1-0_WindowsCreateString' -Namespace Win32 -PassThru
# $api::WindowsCreateString(sourceString, length, string)#uselib "api-ms-win-core-winrt-string-l1-1-0.dll"
#func global WindowsCreateString "WindowsCreateString" sptr, sptr, sptr
; WindowsCreateString sourceString, length, string ; 戻り値は stat
; sourceString : LPCWSTR optional -> "sptr"
; length : DWORD -> "sptr"
; string : HSTRING* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "api-ms-win-core-winrt-string-l1-1-0.dll"
#cfunc global WindowsCreateString "WindowsCreateString" wstr, int, sptr
; res = WindowsCreateString(sourceString, length, string)
; sourceString : LPCWSTR optional -> "wstr"
; length : DWORD -> "int"
; string : HSTRING* out -> "sptr"; HRESULT WindowsCreateString(LPCWSTR sourceString, DWORD length, HSTRING* string)
#uselib "api-ms-win-core-winrt-string-l1-1-0.dll"
#cfunc global WindowsCreateString "WindowsCreateString" wstr, int, intptr
; res = WindowsCreateString(sourceString, length, string)
; sourceString : LPCWSTR optional -> "wstr"
; length : DWORD -> "int"
; string : HSTRING* out -> "intptr"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")
procWindowsCreateString = api_ms_win_core_winrt_string_l1_1_0.NewProc("WindowsCreateString")
)
// sourceString (LPCWSTR optional), length (DWORD), string (HSTRING* out)
r1, _, err := procWindowsCreateString.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(sourceString))),
uintptr(length),
uintptr(string),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction WindowsCreateString(
sourceString: PWideChar; // LPCWSTR optional
length: DWORD; // DWORD
string: Pointer // HSTRING* out
): Integer; stdcall;
external 'api-ms-win-core-winrt-string-l1-1-0.dll' name 'WindowsCreateString';result := DllCall("api-ms-win-core-winrt-string-l1-1-0\WindowsCreateString"
, "WStr", sourceString ; LPCWSTR optional
, "UInt", length ; DWORD
, "Ptr", string ; HSTRING* out
, "Int") ; return: HRESULT●WindowsCreateString(sourceString, length, string) = DLL("api-ms-win-core-winrt-string-l1-1-0.dll", "int WindowsCreateString(char*, dword, void*)")
# 呼び出し: WindowsCreateString(sourceString, length, string)
# sourceString : LPCWSTR optional -> "char*"
# length : DWORD -> "dword"
# string : HSTRING* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "api-ms-win-core-winrt-string-l1-1-0" fn WindowsCreateString(
sourceString: [*c]const u16, // LPCWSTR optional
length: u32, // DWORD
string: ?*anyopaque // HSTRING* out
) callconv(std.os.windows.WINAPI) i32;proc WindowsCreateString(
sourceString: WideCString, # LPCWSTR optional
length: uint32, # DWORD
string: pointer # HSTRING* out
): int32 {.importc: "WindowsCreateString", stdcall, dynlib: "api-ms-win-core-winrt-string-l1-1-0.dll".}pragma(lib, "api-ms-win-core-winrt-string-l1-1-0");
extern(Windows)
int WindowsCreateString(
const(wchar)* sourceString, // LPCWSTR optional
uint length, // DWORD
void* string // HSTRING* out
);ccall((:WindowsCreateString, "api-ms-win-core-winrt-string-l1-1-0.dll"), stdcall, Int32,
(Cwstring, UInt32, Ptr{Cvoid}),
sourceString, length, string)
# sourceString : LPCWSTR optional -> Cwstring
# length : DWORD -> UInt32
# string : HSTRING* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t WindowsCreateString(
const uint16_t* sourceString,
uint32_t length,
void* string);
]]
local api-ms-win-core-winrt-string-l1-1-0 = ffi.load("api-ms-win-core-winrt-string-l1-1-0")
-- api-ms-win-core-winrt-string-l1-1-0.WindowsCreateString(sourceString, length, string)
-- sourceString : LPCWSTR optional
-- length : DWORD
-- string : HSTRING* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('api-ms-win-core-winrt-string-l1-1-0.dll');
const WindowsCreateString = lib.func('__stdcall', 'WindowsCreateString', 'int32_t', ['str16', 'uint32_t', 'void *']);
// WindowsCreateString(sourceString, length, string)
// sourceString : LPCWSTR optional -> 'str16'
// length : DWORD -> 'uint32_t'
// string : HSTRING* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("api-ms-win-core-winrt-string-l1-1-0.dll", {
WindowsCreateString: { parameters: ["buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.WindowsCreateString(sourceString, length, string)
// sourceString : LPCWSTR optional -> "buffer"
// length : DWORD -> "u32"
// string : HSTRING* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t WindowsCreateString(
const uint16_t* sourceString,
uint32_t length,
void* string);
C, "api-ms-win-core-winrt-string-l1-1-0.dll");
// $ffi->WindowsCreateString(sourceString, length, string);
// sourceString : LPCWSTR optional
// length : DWORD
// string : HSTRING* 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 Api-ms-win-core-winrt-string-l1-1-0 extends StdCallLibrary {
Api-ms-win-core-winrt-string-l1-1-0 INSTANCE = Native.load("api-ms-win-core-winrt-string-l1-1-0", Api-ms-win-core-winrt-string-l1-1-0.class);
int WindowsCreateString(
WString sourceString, // LPCWSTR optional
int length, // DWORD
Pointer string // HSTRING* out
);
}@[Link("api-ms-win-core-winrt-string-l1-1-0")]
lib Libapi-ms-win-core-winrt-string-l1-1-0
fun WindowsCreateString = WindowsCreateString(
sourceString : UInt16*, # LPCWSTR optional
length : UInt32, # DWORD
string : Void* # HSTRING* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef WindowsCreateStringNative = Int32 Function(Pointer<Utf16>, Uint32, Pointer<Void>);
typedef WindowsCreateStringDart = int Function(Pointer<Utf16>, int, Pointer<Void>);
final WindowsCreateString = DynamicLibrary.open('api-ms-win-core-winrt-string-l1-1-0.dll')
.lookupFunction<WindowsCreateStringNative, WindowsCreateStringDart>('WindowsCreateString');
// sourceString : LPCWSTR optional -> Pointer<Utf16>
// length : DWORD -> Uint32
// string : HSTRING* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function WindowsCreateString(
sourceString: PWideChar; // LPCWSTR optional
length: DWORD; // DWORD
string: Pointer // HSTRING* out
): Integer; stdcall;
external 'api-ms-win-core-winrt-string-l1-1-0.dll' name 'WindowsCreateString';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WindowsCreateString"
c_WindowsCreateString :: CWString -> Word32 -> Ptr () -> IO Int32
-- sourceString : LPCWSTR optional -> CWString
-- length : DWORD -> Word32
-- string : HSTRING* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let windowscreatestring =
foreign "WindowsCreateString"
((ptr uint16_t) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* sourceString : LPCWSTR optional -> (ptr uint16_t) *)
(* length : DWORD -> uint32_t *)
(* string : HSTRING* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library api-ms-win-core-winrt-string-l1-1-0 (t "api-ms-win-core-winrt-string-l1-1-0.dll"))
(cffi:use-foreign-library api-ms-win-core-winrt-string-l1-1-0)
(cffi:defcfun ("WindowsCreateString" windows-create-string :convention :stdcall) :int32
(source-string (:string :encoding :utf-16le)) ; LPCWSTR optional
(length :uint32) ; DWORD
(string :pointer)) ; HSTRING* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $WindowsCreateString = Win32::API::More->new('api-ms-win-core-winrt-string-l1-1-0',
'int WindowsCreateString(LPCWSTR sourceString, DWORD length, HANDLE string)');
# my $ret = $WindowsCreateString->Call($sourceString, $length, $string);
# sourceString : LPCWSTR optional -> LPCWSTR
# length : DWORD -> DWORD
# string : HSTRING* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。