ホーム › System.DataExchange › DdeCreateDataHandle
DdeCreateDataHandle
関数指定データから新しいDDEデータハンドルを作成する。
シグネチャ
// USER32.dll
#include <windows.h>
HDDEDATA DdeCreateDataHandle(
DWORD idInst,
BYTE* pSrc, // optional
DWORD cb,
DWORD cbOff,
HSZ hszItem, // optional
DWORD wFmt,
DWORD afCmd
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| idInst | DWORD | in | 以前に DdeInitialize 関数を呼び出して取得したアプリケーションインスタンス識別子。 |
| pSrc | BYTE* | inoptional | DDE オブジェクトにコピーするデータ。このパラメーターが NULL の場合、オブジェクトにはデータがコピーされません。 |
| cb | DWORD | in | |
| cbOff | DWORD | in | |
| hszItem | HSZ | inoptional | DDE オブジェクトに対応するデータ項目を指定する文字列へのハンドル。このハンドルは、以前に DdeCreateStringHandle 関数を呼び出して作成しておく必要があります。データハンドルを XTYP_EXECUTE トランザクションで使用する場合、このパラメーターは 0L でなければなりません。 |
| wFmt | DWORD | in | データの標準クリップボード形式。 |
| afCmd | DWORD | in | 作成フラグ。このパラメーターには HDATA_APPOWNED を指定できます。これは、DdeCreateDataHandle 関数を呼び出したサーバーアプリケーションが、この関数が作成するデータハンドルを所有することを指定します。このフラグを使用すると、アプリケーションは各アプリケーションへ渡す個別のハンドルを作成する代わりに、データハンドルを他の DDEML アプリケーションと共有できます。このフラグを指定した場合、アプリケーションは最終的に DdeFreeDataHandle 関数を使用して、ハンドルに関連付けられた共有メモリオブジェクトを解放する必要があります。このフラグを指定しない場合、ハンドルは、アプリケーションの DDE コールバック関数から返されるか、別の DDEML 関数のパラメーターとして使用された後、そのハンドルを作成したアプリケーション内で無効になります。 |
戻り値の型: HDDEDATA
公式ドキュメント
ダイナミックデータエクスチェンジ (DDE) オブジェクトを作成し、指定したバッファのデータでそのオブジェクトを満たします。DDE アプリケーションは、相手側アプリケーションへのデータ受け渡しを伴うトランザクションでこの関数を使用します。
戻り値
型: HDDEDATA
関数が成功した場合、戻り値はデータハンドルです。
関数が失敗した場合、戻り値は 0L です。
DdeGetLastError 関数を使用してエラーコードを取得できます。エラーコードは次の値のいずれかになります。
解説(Remarks)
DDE オブジェクト内の未充填の位置は未定義です。
データハンドルが別の DDEML 関数のパラメーターとして使用された後、または DDE コールバック関数から返された後は、そのハンドルが識別する DDE オブジェクトへの読み取りアクセスにのみ使用できます。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// USER32.dll
#include <windows.h>
HDDEDATA DdeCreateDataHandle(
DWORD idInst,
BYTE* pSrc, // optional
DWORD cb,
DWORD cbOff,
HSZ hszItem, // optional
DWORD wFmt,
DWORD afCmd
);[DllImport("USER32.dll", ExactSpelling = true)]
static extern IntPtr DdeCreateDataHandle(
uint idInst, // DWORD
IntPtr pSrc, // BYTE* optional
uint cb, // DWORD
uint cbOff, // DWORD
IntPtr hszItem, // HSZ optional
uint wFmt, // DWORD
uint afCmd // DWORD
);<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function DdeCreateDataHandle(
idInst As UInteger, ' DWORD
pSrc As IntPtr, ' BYTE* optional
cb As UInteger, ' DWORD
cbOff As UInteger, ' DWORD
hszItem As IntPtr, ' HSZ optional
wFmt As UInteger, ' DWORD
afCmd As UInteger ' DWORD
) As IntPtr
End Function' idInst : DWORD
' pSrc : BYTE* optional
' cb : DWORD
' cbOff : DWORD
' hszItem : HSZ optional
' wFmt : DWORD
' afCmd : DWORD
Declare PtrSafe Function DdeCreateDataHandle Lib "user32" ( _
ByVal idInst As Long, _
ByVal pSrc As LongPtr, _
ByVal cb As Long, _
ByVal cbOff As Long, _
ByVal hszItem As LongPtr, _
ByVal wFmt As Long, _
ByVal afCmd As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DdeCreateDataHandle = ctypes.windll.user32.DdeCreateDataHandle
DdeCreateDataHandle.restype = ctypes.c_void_p
DdeCreateDataHandle.argtypes = [
wintypes.DWORD, # idInst : DWORD
ctypes.POINTER(ctypes.c_ubyte), # pSrc : BYTE* optional
wintypes.DWORD, # cb : DWORD
wintypes.DWORD, # cbOff : DWORD
wintypes.HANDLE, # hszItem : HSZ optional
wintypes.DWORD, # wFmt : DWORD
wintypes.DWORD, # afCmd : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
DdeCreateDataHandle = Fiddle::Function.new(
lib['DdeCreateDataHandle'],
[
-Fiddle::TYPE_INT, # idInst : DWORD
Fiddle::TYPE_VOIDP, # pSrc : BYTE* optional
-Fiddle::TYPE_INT, # cb : DWORD
-Fiddle::TYPE_INT, # cbOff : DWORD
Fiddle::TYPE_VOIDP, # hszItem : HSZ optional
-Fiddle::TYPE_INT, # wFmt : DWORD
-Fiddle::TYPE_INT, # afCmd : DWORD
],
Fiddle::TYPE_VOIDP)#[link(name = "user32")]
extern "system" {
fn DdeCreateDataHandle(
idInst: u32, // DWORD
pSrc: *mut u8, // BYTE* optional
cb: u32, // DWORD
cbOff: u32, // DWORD
hszItem: *mut core::ffi::c_void, // HSZ optional
wFmt: u32, // DWORD
afCmd: u32 // DWORD
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll")]
public static extern IntPtr DdeCreateDataHandle(uint idInst, IntPtr pSrc, uint cb, uint cbOff, IntPtr hszItem, uint wFmt, uint afCmd);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_DdeCreateDataHandle' -Namespace Win32 -PassThru
# $api::DdeCreateDataHandle(idInst, pSrc, cb, cbOff, hszItem, wFmt, afCmd)#uselib "USER32.dll"
#func global DdeCreateDataHandle "DdeCreateDataHandle" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; DdeCreateDataHandle idInst, varptr(pSrc), cb, cbOff, hszItem, wFmt, afCmd ; 戻り値は stat
; idInst : DWORD -> "sptr"
; pSrc : BYTE* optional -> "sptr"
; cb : DWORD -> "sptr"
; cbOff : DWORD -> "sptr"
; hszItem : HSZ optional -> "sptr"
; wFmt : DWORD -> "sptr"
; afCmd : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "USER32.dll" #cfunc global DdeCreateDataHandle "DdeCreateDataHandle" int, var, int, int, sptr, int, int ; res = DdeCreateDataHandle(idInst, pSrc, cb, cbOff, hszItem, wFmt, afCmd) ; idInst : DWORD -> "int" ; pSrc : BYTE* optional -> "var" ; cb : DWORD -> "int" ; cbOff : DWORD -> "int" ; hszItem : HSZ optional -> "sptr" ; wFmt : DWORD -> "int" ; afCmd : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USER32.dll" #cfunc global DdeCreateDataHandle "DdeCreateDataHandle" int, sptr, int, int, sptr, int, int ; res = DdeCreateDataHandle(idInst, varptr(pSrc), cb, cbOff, hszItem, wFmt, afCmd) ; idInst : DWORD -> "int" ; pSrc : BYTE* optional -> "sptr" ; cb : DWORD -> "int" ; cbOff : DWORD -> "int" ; hszItem : HSZ optional -> "sptr" ; wFmt : DWORD -> "int" ; afCmd : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HDDEDATA DdeCreateDataHandle(DWORD idInst, BYTE* pSrc, DWORD cb, DWORD cbOff, HSZ hszItem, DWORD wFmt, DWORD afCmd) #uselib "USER32.dll" #cfunc global DdeCreateDataHandle "DdeCreateDataHandle" int, var, int, int, intptr, int, int ; res = DdeCreateDataHandle(idInst, pSrc, cb, cbOff, hszItem, wFmt, afCmd) ; idInst : DWORD -> "int" ; pSrc : BYTE* optional -> "var" ; cb : DWORD -> "int" ; cbOff : DWORD -> "int" ; hszItem : HSZ optional -> "intptr" ; wFmt : DWORD -> "int" ; afCmd : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HDDEDATA DdeCreateDataHandle(DWORD idInst, BYTE* pSrc, DWORD cb, DWORD cbOff, HSZ hszItem, DWORD wFmt, DWORD afCmd) #uselib "USER32.dll" #cfunc global DdeCreateDataHandle "DdeCreateDataHandle" int, intptr, int, int, intptr, int, int ; res = DdeCreateDataHandle(idInst, varptr(pSrc), cb, cbOff, hszItem, wFmt, afCmd) ; idInst : DWORD -> "int" ; pSrc : BYTE* optional -> "intptr" ; cb : DWORD -> "int" ; cbOff : DWORD -> "int" ; hszItem : HSZ optional -> "intptr" ; wFmt : DWORD -> "int" ; afCmd : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procDdeCreateDataHandle = user32.NewProc("DdeCreateDataHandle")
)
// idInst (DWORD), pSrc (BYTE* optional), cb (DWORD), cbOff (DWORD), hszItem (HSZ optional), wFmt (DWORD), afCmd (DWORD)
r1, _, err := procDdeCreateDataHandle.Call(
uintptr(idInst),
uintptr(pSrc),
uintptr(cb),
uintptr(cbOff),
uintptr(hszItem),
uintptr(wFmt),
uintptr(afCmd),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HDDEDATAfunction DdeCreateDataHandle(
idInst: DWORD; // DWORD
pSrc: Pointer; // BYTE* optional
cb: DWORD; // DWORD
cbOff: DWORD; // DWORD
hszItem: THandle; // HSZ optional
wFmt: DWORD; // DWORD
afCmd: DWORD // DWORD
): THandle; stdcall;
external 'USER32.dll' name 'DdeCreateDataHandle';result := DllCall("USER32\DdeCreateDataHandle"
, "UInt", idInst ; DWORD
, "Ptr", pSrc ; BYTE* optional
, "UInt", cb ; DWORD
, "UInt", cbOff ; DWORD
, "Ptr", hszItem ; HSZ optional
, "UInt", wFmt ; DWORD
, "UInt", afCmd ; DWORD
, "Ptr") ; return: HDDEDATA●DdeCreateDataHandle(idInst, pSrc, cb, cbOff, hszItem, wFmt, afCmd) = DLL("USER32.dll", "void* DdeCreateDataHandle(dword, void*, dword, dword, void*, dword, dword)")
# 呼び出し: DdeCreateDataHandle(idInst, pSrc, cb, cbOff, hszItem, wFmt, afCmd)
# idInst : DWORD -> "dword"
# pSrc : BYTE* optional -> "void*"
# cb : DWORD -> "dword"
# cbOff : DWORD -> "dword"
# hszItem : HSZ optional -> "void*"
# wFmt : DWORD -> "dword"
# afCmd : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "user32" fn DdeCreateDataHandle(
idInst: u32, // DWORD
pSrc: [*c]u8, // BYTE* optional
cb: u32, // DWORD
cbOff: u32, // DWORD
hszItem: ?*anyopaque, // HSZ optional
wFmt: u32, // DWORD
afCmd: u32 // DWORD
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc DdeCreateDataHandle(
idInst: uint32, # DWORD
pSrc: ptr uint8, # BYTE* optional
cb: uint32, # DWORD
cbOff: uint32, # DWORD
hszItem: pointer, # HSZ optional
wFmt: uint32, # DWORD
afCmd: uint32 # DWORD
): pointer {.importc: "DdeCreateDataHandle", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
void* DdeCreateDataHandle(
uint idInst, // DWORD
ubyte* pSrc, // BYTE* optional
uint cb, // DWORD
uint cbOff, // DWORD
void* hszItem, // HSZ optional
uint wFmt, // DWORD
uint afCmd // DWORD
);ccall((:DdeCreateDataHandle, "USER32.dll"), stdcall, Ptr{Cvoid},
(UInt32, Ptr{UInt8}, UInt32, UInt32, Ptr{Cvoid}, UInt32, UInt32),
idInst, pSrc, cb, cbOff, hszItem, wFmt, afCmd)
# idInst : DWORD -> UInt32
# pSrc : BYTE* optional -> Ptr{UInt8}
# cb : DWORD -> UInt32
# cbOff : DWORD -> UInt32
# hszItem : HSZ optional -> Ptr{Cvoid}
# wFmt : DWORD -> UInt32
# afCmd : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* DdeCreateDataHandle(
uint32_t idInst,
uint8_t* pSrc,
uint32_t cb,
uint32_t cbOff,
void* hszItem,
uint32_t wFmt,
uint32_t afCmd);
]]
local user32 = ffi.load("user32")
-- user32.DdeCreateDataHandle(idInst, pSrc, cb, cbOff, hszItem, wFmt, afCmd)
-- idInst : DWORD
-- pSrc : BYTE* optional
-- cb : DWORD
-- cbOff : DWORD
-- hszItem : HSZ optional
-- wFmt : DWORD
-- afCmd : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const DdeCreateDataHandle = lib.func('__stdcall', 'DdeCreateDataHandle', 'void *', ['uint32_t', 'uint8_t *', 'uint32_t', 'uint32_t', 'void *', 'uint32_t', 'uint32_t']);
// DdeCreateDataHandle(idInst, pSrc, cb, cbOff, hszItem, wFmt, afCmd)
// idInst : DWORD -> 'uint32_t'
// pSrc : BYTE* optional -> 'uint8_t *'
// cb : DWORD -> 'uint32_t'
// cbOff : DWORD -> 'uint32_t'
// hszItem : HSZ optional -> 'void *'
// wFmt : DWORD -> 'uint32_t'
// afCmd : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
DdeCreateDataHandle: { parameters: ["u32", "pointer", "u32", "u32", "pointer", "u32", "u32"], result: "pointer" },
});
// lib.symbols.DdeCreateDataHandle(idInst, pSrc, cb, cbOff, hszItem, wFmt, afCmd)
// idInst : DWORD -> "u32"
// pSrc : BYTE* optional -> "pointer"
// cb : DWORD -> "u32"
// cbOff : DWORD -> "u32"
// hszItem : HSZ optional -> "pointer"
// wFmt : DWORD -> "u32"
// afCmd : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* DdeCreateDataHandle(
uint32_t idInst,
uint8_t* pSrc,
uint32_t cb,
uint32_t cbOff,
void* hszItem,
uint32_t wFmt,
uint32_t afCmd);
C, "USER32.dll");
// $ffi->DdeCreateDataHandle(idInst, pSrc, cb, cbOff, hszItem, wFmt, afCmd);
// idInst : DWORD
// pSrc : BYTE* optional
// cb : DWORD
// cbOff : DWORD
// hszItem : HSZ optional
// wFmt : DWORD
// afCmd : DWORD
// 構造体/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);
Pointer DdeCreateDataHandle(
int idInst, // DWORD
byte[] pSrc, // BYTE* optional
int cb, // DWORD
int cbOff, // DWORD
Pointer hszItem, // HSZ optional
int wFmt, // DWORD
int afCmd // DWORD
);
}@[Link("user32")]
lib LibUSER32
fun DdeCreateDataHandle = DdeCreateDataHandle(
idInst : UInt32, # DWORD
pSrc : UInt8*, # BYTE* optional
cb : UInt32, # DWORD
cbOff : UInt32, # DWORD
hszItem : Void*, # HSZ optional
wFmt : UInt32, # DWORD
afCmd : UInt32 # DWORD
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DdeCreateDataHandleNative = Pointer<Void> Function(Uint32, Pointer<Uint8>, Uint32, Uint32, Pointer<Void>, Uint32, Uint32);
typedef DdeCreateDataHandleDart = Pointer<Void> Function(int, Pointer<Uint8>, int, int, Pointer<Void>, int, int);
final DdeCreateDataHandle = DynamicLibrary.open('USER32.dll')
.lookupFunction<DdeCreateDataHandleNative, DdeCreateDataHandleDart>('DdeCreateDataHandle');
// idInst : DWORD -> Uint32
// pSrc : BYTE* optional -> Pointer<Uint8>
// cb : DWORD -> Uint32
// cbOff : DWORD -> Uint32
// hszItem : HSZ optional -> Pointer<Void>
// wFmt : DWORD -> Uint32
// afCmd : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DdeCreateDataHandle(
idInst: DWORD; // DWORD
pSrc: Pointer; // BYTE* optional
cb: DWORD; // DWORD
cbOff: DWORD; // DWORD
hszItem: THandle; // HSZ optional
wFmt: DWORD; // DWORD
afCmd: DWORD // DWORD
): THandle; stdcall;
external 'USER32.dll' name 'DdeCreateDataHandle';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DdeCreateDataHandle"
c_DdeCreateDataHandle :: Word32 -> Ptr Word8 -> Word32 -> Word32 -> Ptr () -> Word32 -> Word32 -> IO (Ptr ())
-- idInst : DWORD -> Word32
-- pSrc : BYTE* optional -> Ptr Word8
-- cb : DWORD -> Word32
-- cbOff : DWORD -> Word32
-- hszItem : HSZ optional -> Ptr ()
-- wFmt : DWORD -> Word32
-- afCmd : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ddecreatedatahandle =
foreign "DdeCreateDataHandle"
(uint32_t @-> (ptr uint8_t) @-> uint32_t @-> uint32_t @-> (ptr void) @-> uint32_t @-> uint32_t @-> returning (ptr void))
(* idInst : DWORD -> uint32_t *)
(* pSrc : BYTE* optional -> (ptr uint8_t) *)
(* cb : DWORD -> uint32_t *)
(* cbOff : DWORD -> uint32_t *)
(* hszItem : HSZ optional -> (ptr void) *)
(* wFmt : DWORD -> uint32_t *)
(* afCmd : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("DdeCreateDataHandle" dde-create-data-handle :convention :stdcall) :pointer
(id-inst :uint32) ; DWORD
(p-src :pointer) ; BYTE* optional
(cb :uint32) ; DWORD
(cb-off :uint32) ; DWORD
(hsz-item :pointer) ; HSZ optional
(w-fmt :uint32) ; DWORD
(af-cmd :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DdeCreateDataHandle = Win32::API::More->new('USER32',
'HANDLE DdeCreateDataHandle(DWORD idInst, LPVOID pSrc, DWORD cb, DWORD cbOff, HANDLE hszItem, DWORD wFmt, DWORD afCmd)');
# my $ret = $DdeCreateDataHandle->Call($idInst, $pSrc, $cb, $cbOff, $hszItem, $wFmt, $afCmd);
# idInst : DWORD -> DWORD
# pSrc : BYTE* optional -> LPVOID
# cb : DWORD -> DWORD
# cbOff : DWORD -> DWORD
# hszItem : HSZ optional -> HANDLE
# wFmt : DWORD -> DWORD
# afCmd : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f DdeAccessData — DDEデータオブジェクトのメモリへの読み取りアクセスを得る。
- f DdeCreateStringHandleW — 文字列からDDE文字列ハンドルを作成する(Unicode版)。
- f DdeFreeDataHandle — 指定したDDEデータハンドルを解放する。
- f DdeGetData — DDEデータオブジェクトの内容をバッファにコピーする。
- f DdeInitializeW — DDEMLライブラリを初期化しコールバックを登録する(Unicode版)。