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

DdeCreateStringHandleW

関数
文字列からDDE文字列ハンドルを作成する(Unicode版)。
DLLUSER32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// USER32.dll  (Unicode / -W)
#include <windows.h>

HSZ DdeCreateStringHandleW(
    DWORD idInst,
    LPCWSTR psz,
    INT iCodePage
);

パラメーター

名前方向
idInstDWORDin
pszLPCWSTRin
iCodePageINTin

戻り値の型: HSZ

各言語での呼び出し定義

// USER32.dll  (Unicode / -W)
#include <windows.h>

HSZ DdeCreateStringHandleW(
    DWORD idInst,
    LPCWSTR psz,
    INT iCodePage
);
[DllImport("USER32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr DdeCreateStringHandleW(
    uint idInst,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string psz,   // LPCWSTR
    int iCodePage   // INT
);
<DllImport("USER32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function DdeCreateStringHandleW(
    idInst As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> psz As String,   ' LPCWSTR
    iCodePage As Integer   ' INT
) As IntPtr
End Function
' idInst : DWORD
' psz : LPCWSTR
' iCodePage : INT
Declare PtrSafe Function DdeCreateStringHandleW Lib "user32" ( _
    ByVal idInst As Long, _
    ByVal psz As LongPtr, _
    ByVal iCodePage As Long) As LongPtr
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DdeCreateStringHandleW = ctypes.windll.user32.DdeCreateStringHandleW
DdeCreateStringHandleW.restype = ctypes.c_void_p
DdeCreateStringHandleW.argtypes = [
    wintypes.DWORD,  # idInst : DWORD
    wintypes.LPCWSTR,  # psz : LPCWSTR
    ctypes.c_int,  # iCodePage : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
DdeCreateStringHandleW = Fiddle::Function.new(
  lib['DdeCreateStringHandleW'],
  [
    -Fiddle::TYPE_INT,  # idInst : DWORD
    Fiddle::TYPE_VOIDP,  # psz : LPCWSTR
    Fiddle::TYPE_INT,  # iCodePage : INT
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "user32")]
extern "system" {
    fn DdeCreateStringHandleW(
        idInst: u32,  // DWORD
        psz: *const u16,  // LPCWSTR
        iCodePage: i32  // INT
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr DdeCreateStringHandleW(uint idInst, [MarshalAs(UnmanagedType.LPWStr)] string psz, int iCodePage);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_DdeCreateStringHandleW' -Namespace Win32 -PassThru
# $api::DdeCreateStringHandleW(idInst, psz, iCodePage)
#uselib "USER32.dll"
#func global DdeCreateStringHandleW "DdeCreateStringHandleW" wptr, wptr, wptr
; DdeCreateStringHandleW idInst, psz, iCodePage   ; 戻り値は stat
; idInst : DWORD -> "wptr"
; psz : LPCWSTR -> "wptr"
; iCodePage : INT -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global DdeCreateStringHandleW "DdeCreateStringHandleW" int, wstr, int
; res = DdeCreateStringHandleW(idInst, psz, iCodePage)
; idInst : DWORD -> "int"
; psz : LPCWSTR -> "wstr"
; iCodePage : INT -> "int"
; HSZ DdeCreateStringHandleW(DWORD idInst, LPCWSTR psz, INT iCodePage)
#uselib "USER32.dll"
#cfunc global DdeCreateStringHandleW "DdeCreateStringHandleW" int, wstr, int
; res = DdeCreateStringHandleW(idInst, psz, iCodePage)
; idInst : DWORD -> "int"
; psz : LPCWSTR -> "wstr"
; iCodePage : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procDdeCreateStringHandleW = user32.NewProc("DdeCreateStringHandleW")
)

// idInst (DWORD), psz (LPCWSTR), iCodePage (INT)
r1, _, err := procDdeCreateStringHandleW.Call(
	uintptr(idInst),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(psz))),
	uintptr(iCodePage),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HSZ
function DdeCreateStringHandleW(
  idInst: DWORD;   // DWORD
  psz: PWideChar;   // LPCWSTR
  iCodePage: Integer   // INT
): THandle; stdcall;
  external 'USER32.dll' name 'DdeCreateStringHandleW';
result := DllCall("USER32\DdeCreateStringHandleW"
    , "UInt", idInst   ; DWORD
    , "WStr", psz   ; LPCWSTR
    , "Int", iCodePage   ; INT
    , "Ptr")   ; return: HSZ
●DdeCreateStringHandleW(idInst, psz, iCodePage) = DLL("USER32.dll", "void* DdeCreateStringHandleW(dword, char*, int)")
# 呼び出し: DdeCreateStringHandleW(idInst, psz, iCodePage)
# idInst : DWORD -> "dword"
# psz : LPCWSTR -> "char*"
# iCodePage : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。