Win32 API 日本語リファレンス
ホームUI.Controls › Str_SetPtrW

Str_SetPtrW

関数
文字列ポインタの内容を割り当てて複製する(Unicode版)。
DLLCOMCTL32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

BOOL Str_SetPtrW(
    LPWSTR* ppsz,
    LPCWSTR psz   // optional
);

パラメーター

名前方向説明
ppszLPWSTR*inout現在の文字列へのポインターのアドレス。現在の文字列は解放され、このポインターは pszNew のコピーに設定されます。
pszLPCWSTRinoptionalppszCurrent にコピーする文字列へのポインター。

戻り値の型: BOOL

公式ドキュメント

ppszCurrent を pszNew のコピーに設定し、必要に応じて以前の値を解放します。

戻り値

型: BOOL

成功した場合は TRUE を、それ以外の場合は FALSE を返します。

解説(Remarks)

Str_SetPtrW の ANSI 版である Str_SetPtrA は、名前でエクスポートされておらず、公開ヘッダー ファイルでも宣言されていません。これを使用するには、GetProcAddress を使用し、ComCtl32.dll の序数 234 を要求して関数ポインターを取得する必要があります。

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

各言語での呼び出し定義

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

BOOL Str_SetPtrW(
    LPWSTR* ppsz,
    LPCWSTR psz   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("COMCTL32.dll", ExactSpelling = true)]
static extern bool Str_SetPtrW(
    IntPtr ppsz,   // LPWSTR* in/out
    [MarshalAs(UnmanagedType.LPWStr)] string psz   // LPCWSTR optional
);
<DllImport("COMCTL32.dll", ExactSpelling:=True)>
Public Shared Function Str_SetPtrW(
    ppsz As IntPtr,   ' LPWSTR* in/out
    <MarshalAs(UnmanagedType.LPWStr)> psz As String   ' LPCWSTR optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' ppsz : LPWSTR* in/out
' psz : LPCWSTR optional
Declare PtrSafe Function Str_SetPtrW Lib "comctl32" ( _
    ByVal ppsz As LongPtr, _
    ByVal psz As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

Str_SetPtrW = ctypes.windll.comctl32.Str_SetPtrW
Str_SetPtrW.restype = wintypes.BOOL
Str_SetPtrW.argtypes = [
    ctypes.c_void_p,  # ppsz : LPWSTR* in/out
    wintypes.LPCWSTR,  # psz : LPCWSTR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('COMCTL32.dll')
Str_SetPtrW = Fiddle::Function.new(
  lib['Str_SetPtrW'],
  [
    Fiddle::TYPE_VOIDP,  # ppsz : LPWSTR* in/out
    Fiddle::TYPE_VOIDP,  # psz : LPCWSTR optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "comctl32")]
extern "system" {
    fn Str_SetPtrW(
        ppsz: *mut *mut u16,  // LPWSTR* in/out
        psz: *const u16  // LPCWSTR optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("COMCTL32.dll")]
public static extern bool Str_SetPtrW(IntPtr ppsz, [MarshalAs(UnmanagedType.LPWStr)] string psz);
"@
$api = Add-Type -MemberDefinition $sig -Name 'COMCTL32_Str_SetPtrW' -Namespace Win32 -PassThru
# $api::Str_SetPtrW(ppsz, psz)
#uselib "COMCTL32.dll"
#func global Str_SetPtrW "Str_SetPtrW" sptr, sptr
; Str_SetPtrW varptr(ppsz), psz   ; 戻り値は stat
; ppsz : LPWSTR* in/out -> "sptr"
; psz : LPCWSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "COMCTL32.dll"
#cfunc global Str_SetPtrW "Str_SetPtrW" var, wstr
; res = Str_SetPtrW(ppsz, psz)
; ppsz : LPWSTR* in/out -> "var"
; psz : LPCWSTR optional -> "wstr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL Str_SetPtrW(LPWSTR* ppsz, LPCWSTR psz)
#uselib "COMCTL32.dll"
#cfunc global Str_SetPtrW "Str_SetPtrW" var, wstr
; res = Str_SetPtrW(ppsz, psz)
; ppsz : LPWSTR* in/out -> "var"
; psz : LPCWSTR optional -> "wstr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	comctl32 = windows.NewLazySystemDLL("COMCTL32.dll")
	procStr_SetPtrW = comctl32.NewProc("Str_SetPtrW")
)

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

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

typedef Str_SetPtrWNative = Int32 Function(Pointer<Pointer<Utf16>>, Pointer<Utf16>);
typedef Str_SetPtrWDart = int Function(Pointer<Pointer<Utf16>>, Pointer<Utf16>);
final Str_SetPtrW = DynamicLibrary.open('COMCTL32.dll')
    .lookupFunction<Str_SetPtrWNative, Str_SetPtrWDart>('Str_SetPtrW');
// ppsz : LPWSTR* in/out -> Pointer<Pointer<Utf16>>
// psz : LPCWSTR optional -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function Str_SetPtrW(
  ppsz: PPWideChar;   // LPWSTR* in/out
  psz: PWideChar   // LPCWSTR optional
): BOOL; stdcall;
  external 'COMCTL32.dll' name 'Str_SetPtrW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "Str_SetPtrW"
  c_Str_SetPtrW :: Ptr CWString -> CWString -> IO CInt
-- ppsz : LPWSTR* in/out -> Ptr CWString
-- psz : LPCWSTR optional -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let str_setptrw =
  foreign "Str_SetPtrW"
    ((ptr (ptr uint16_t)) @-> (ptr uint16_t) @-> returning int32_t)
(* ppsz : LPWSTR* in/out -> (ptr (ptr uint16_t)) *)
(* psz : LPCWSTR optional -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library comctl32 (t "COMCTL32.dll"))
(cffi:use-foreign-library comctl32)

(cffi:defcfun ("Str_SetPtrW" str-set-ptr-w :convention :stdcall) :int32
  (ppsz :pointer)   ; LPWSTR* in/out
  (psz (:string :encoding :utf-16le)))   ; LPCWSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $Str_SetPtrW = Win32::API::More->new('COMCTL32',
    'BOOL Str_SetPtrW(LPVOID ppsz, LPCWSTR psz)');
# my $ret = $Str_SetPtrW->Call($ppsz, $psz);
# ppsz : LPWSTR* in/out -> LPVOID
# psz : LPCWSTR optional -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。