DdeCreateStringHandleW
関数シグネチャ
// USER32.dll (Unicode / -W)
#include <windows.h>
HSZ DdeCreateStringHandleW(
DWORD idInst,
LPCWSTR psz,
INT iCodePage
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| idInst | DWORD | in | 以前の DdeInitialize 関数の呼び出しで取得したアプリケーションインスタンス識別子です。 |
| psz | LPCWSTR | in | ハンドルを作成する対象となる、null で終端された文字列です。この文字列は最大 255 文字までです。この制限は、DDEML の文字列管理関数がアトムを使用して実装されているためです。 |
| iCodePage | INT | in | 文字列のレンダリングに使用するコードページです。この値は CP_WINANSI (既定のコードページ) または CP_WINUNICODE のいずれかを指定します。どちらを指定するかは、クライアントアプリケーションが ANSI 版と Unicode 版のどちらの DdeInitialize を呼び出したかによって決まります。 |
戻り値の型: HSZ
公式ドキュメント
指定した文字列を識別するハンドルを作成します。Dynamic Data Exchange (DDE) のクライアントアプリケーションまたはサーバーアプリケーションは、この文字列ハンドルを引数として他の Dynamic Data Exchange Management Library (DDEML) 関数に渡すことができます。(Unicode)
戻り値
型: HSZ
関数が成功した場合、戻り値は文字列ハンドルです。
関数が失敗した場合、戻り値は 0L です。
エラーコードの取得には DdeGetLastError 関数を使用できます。エラーコードは次のいずれかの値になります。
解説(Remarks)
文字列ハンドルの値は、それが識別する文字列の大文字・小文字の違いには影響されません。
アプリケーションが文字列ハンドルを作成した場合、またはコールバック関数で文字列ハンドルを受け取り、DdeKeepStringHandle 関数を使用してそれを保持した場合、不要になった時点でその文字列ハンドルを解放する必要があります。
インスタンス固有の文字列ハンドルは、文字列ハンドルから文字列へ、さらに文字列から文字列ハンドルへとマッピングして元に戻すことはできません。これは次の例で示されています。この例では、DdeQueryString 関数が文字列ハンドルから文字列を作成し、DdeCreateStringHandle がその文字列から文字列ハンドルを作成していますが、2 つのハンドルは同一ではありません。
DWORD idInst;
DWORD cb;
HSZ hszInst, hszNew;
PSZ pszInst;
DdeQueryString(idInst, hszInst, pszInst, cb, CP_WINANSI);
hszNew = DdeCreateStringHandle(idInst, pszInst, CP_WINANSI);
// hszNew != hszInst !
ddeml.h ヘッダーは DdeCreateStringHandle を、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義しています。エンコーディング非依存のエイリアスを、エンコーディング非依存ではないコードと混在させて使用すると、不整合が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規約 を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 // HSZfunction 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 版の利用を推奨。const std = @import("std");
extern "user32" fn DdeCreateStringHandleW(
idInst: u32, // DWORD
psz: [*c]const u16, // LPCWSTR
iCodePage: i32 // INT
) callconv(std.os.windows.WINAPI) ?*anyopaque;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc DdeCreateStringHandleW(
idInst: uint32, # DWORD
psz: WideCString, # LPCWSTR
iCodePage: int32 # INT
): pointer {.importc: "DdeCreateStringHandleW", stdcall, dynlib: "USER32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "user32");
extern(Windows)
void* DdeCreateStringHandleW(
uint idInst, // DWORD
const(wchar)* psz, // LPCWSTR
int iCodePage // INT
);ccall((:DdeCreateStringHandleW, "USER32.dll"), stdcall, Ptr{Cvoid},
(UInt32, Cwstring, Int32),
idInst, psz, iCodePage)
# idInst : DWORD -> UInt32
# psz : LPCWSTR -> Cwstring
# iCodePage : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
void* DdeCreateStringHandleW(
uint32_t idInst,
const uint16_t* psz,
int32_t iCodePage);
]]
local user32 = ffi.load("user32")
-- user32.DdeCreateStringHandleW(idInst, psz, iCodePage)
-- idInst : DWORD
-- psz : LPCWSTR
-- iCodePage : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const DdeCreateStringHandleW = lib.func('__stdcall', 'DdeCreateStringHandleW', 'void *', ['uint32_t', 'str16', 'int32_t']);
// DdeCreateStringHandleW(idInst, psz, iCodePage)
// idInst : DWORD -> 'uint32_t'
// psz : LPCWSTR -> 'str16'
// iCodePage : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
DdeCreateStringHandleW: { parameters: ["u32", "buffer", "i32"], result: "pointer" },
});
// lib.symbols.DdeCreateStringHandleW(idInst, psz, iCodePage)
// idInst : DWORD -> "u32"
// psz : LPCWSTR -> "buffer"
// iCodePage : INT -> "i32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* DdeCreateStringHandleW(
uint32_t idInst,
const uint16_t* psz,
int32_t iCodePage);
C, "USER32.dll");
// $ffi->DdeCreateStringHandleW(idInst, psz, iCodePage);
// idInst : DWORD
// psz : LPCWSTR
// iCodePage : INT
// 構造体/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 User32 extends StdCallLibrary {
User32 INSTANCE = Native.load("user32", User32.class, W32APIOptions.UNICODE_OPTIONS);
Pointer DdeCreateStringHandleW(
int idInst, // DWORD
WString psz, // LPCWSTR
int iCodePage // INT
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("user32")]
lib LibUSER32
fun DdeCreateStringHandleW = DdeCreateStringHandleW(
idInst : UInt32, # DWORD
psz : UInt16*, # LPCWSTR
iCodePage : Int32 # INT
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DdeCreateStringHandleWNative = Pointer<Void> Function(Uint32, Pointer<Utf16>, Int32);
typedef DdeCreateStringHandleWDart = Pointer<Void> Function(int, Pointer<Utf16>, int);
final DdeCreateStringHandleW = DynamicLibrary.open('USER32.dll')
.lookupFunction<DdeCreateStringHandleWNative, DdeCreateStringHandleWDart>('DdeCreateStringHandleW');
// idInst : DWORD -> Uint32
// psz : LPCWSTR -> Pointer<Utf16>
// iCodePage : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DdeCreateStringHandleW(
idInst: DWORD; // DWORD
psz: PWideChar; // LPCWSTR
iCodePage: Integer // INT
): THandle; stdcall;
external 'USER32.dll' name 'DdeCreateStringHandleW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DdeCreateStringHandleW"
c_DdeCreateStringHandleW :: Word32 -> CWString -> Int32 -> IO (Ptr ())
-- idInst : DWORD -> Word32
-- psz : LPCWSTR -> CWString
-- iCodePage : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ddecreatestringhandlew =
foreign "DdeCreateStringHandleW"
(uint32_t @-> (ptr uint16_t) @-> int32_t @-> returning (ptr void))
(* idInst : DWORD -> uint32_t *)
(* psz : LPCWSTR -> (ptr uint16_t) *)
(* iCodePage : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("DdeCreateStringHandleW" dde-create-string-handle-w :convention :stdcall) :pointer
(id-inst :uint32) ; DWORD
(psz (:string :encoding :utf-16le)) ; LPCWSTR
(i-code-page :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DdeCreateStringHandleW = Win32::API::More->new('USER32',
'HANDLE DdeCreateStringHandleW(DWORD idInst, LPCWSTR psz, int iCodePage)');
# my $ret = $DdeCreateStringHandleW->Call($idInst, $psz, $iCodePage);
# idInst : DWORD -> DWORD
# psz : LPCWSTR -> LPCWSTR
# iCodePage : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f DdeCreateStringHandleA (ANSI版) — 文字列からDDE文字列ハンドルを作成する(ANSI版)。
- f DdeAccessData — DDEデータオブジェクトのメモリへの読み取りアクセスを得る。
- f DdeCmpStringHandles — 2つのDDE文字列ハンドルが指す文字列を比較する。
- f DdeFreeStringHandle — 指定したDDE文字列ハンドルを解放する。
- f DdeInitializeW — DDEMLライブラリを初期化しコールバックを登録する(Unicode版)。
- f DdeKeepStringHandle — DDE文字列ハンドルの参照カウントを増やして保持する。
- f DdeQueryStringW — DDE文字列ハンドルから文字列の内容を取得する(Unicode版)。