ホーム › System.DataExchange › ImpersonateDdeClientWindow
ImpersonateDdeClientWindow
関数DDEサーバーがクライアントのセキュリティコンテキストになりすます。
シグネチャ
// USER32.dll
#include <windows.h>
BOOL ImpersonateDdeClientWindow(
HWND hWndClient,
HWND hWndServer
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hWndClient | HWND | in | 偽装する DDE クライアントウィンドウへのハンドルです。クライアントウィンドウは、 hWndServer パラメーターで指定されたサーバーウィンドウとの DDE 会話を確立している必要があります。 |
| hWndServer | HWND | in | DDE サーバーウィンドウへのハンドルです。アプリケーションは、この関数を呼び出す前にサーバーウィンドウを作成しておく必要があります。 |
戻り値の型: BOOL
公式ドキュメント
動的データ交換 (DDE) サーバーアプリケーションが、DDE クライアントアプリケーションのセキュリティコンテキストを偽装 (impersonate) できるようにします。これにより、保護されたサーバーデータを不正な DDE クライアントから守ります。
戻り値
解説(Remarks)
アプリケーションは、ImpersonateDdeClientWindow 関数によって設定された偽装を取り消すために、RevertToSelf 関数を呼び出す必要があります。
DDEML アプリケーションでは、DdeImpersonateClient 関数を使用してください。
セキュリティに関する考慮事項
この関数を誤って使用すると、プログラムのセキュリティが損なわれる可能性があります。呼び出しの戻り値を確認することが非常に重要です。何らかの理由で関数が失敗した場合、クライアントは偽装されず、それ以降のクライアント要求はすべて呼び出し元プロセスのセキュリティコンテキストで実行されます。呼び出し元プロセスが LocalSystem や管理者グループのメンバーなど、高い権限を持つアカウントで実行されている場合、本来許可されないはずの操作をユーザーが実行できてしまう可能性があります。したがって、呼び出しが失敗したりエラーが発生したりした場合は、クライアント要求の実行を続行しないでください。出典・ライセンス: 上記「公式ドキュメント」の内容は 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>
BOOL ImpersonateDdeClientWindow(
HWND hWndClient,
HWND hWndServer
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool ImpersonateDdeClientWindow(
IntPtr hWndClient, // HWND
IntPtr hWndServer // HWND
);<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function ImpersonateDdeClientWindow(
hWndClient As IntPtr, ' HWND
hWndServer As IntPtr ' HWND
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hWndClient : HWND
' hWndServer : HWND
Declare PtrSafe Function ImpersonateDdeClientWindow Lib "user32" ( _
ByVal hWndClient As LongPtr, _
ByVal hWndServer As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ImpersonateDdeClientWindow = ctypes.windll.user32.ImpersonateDdeClientWindow
ImpersonateDdeClientWindow.restype = wintypes.BOOL
ImpersonateDdeClientWindow.argtypes = [
wintypes.HANDLE, # hWndClient : HWND
wintypes.HANDLE, # hWndServer : HWND
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
ImpersonateDdeClientWindow = Fiddle::Function.new(
lib['ImpersonateDdeClientWindow'],
[
Fiddle::TYPE_VOIDP, # hWndClient : HWND
Fiddle::TYPE_VOIDP, # hWndServer : HWND
],
Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn ImpersonateDdeClientWindow(
hWndClient: *mut core::ffi::c_void, // HWND
hWndServer: *mut core::ffi::c_void // HWND
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true)]
public static extern bool ImpersonateDdeClientWindow(IntPtr hWndClient, IntPtr hWndServer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_ImpersonateDdeClientWindow' -Namespace Win32 -PassThru
# $api::ImpersonateDdeClientWindow(hWndClient, hWndServer)#uselib "USER32.dll"
#func global ImpersonateDdeClientWindow "ImpersonateDdeClientWindow" sptr, sptr
; ImpersonateDdeClientWindow hWndClient, hWndServer ; 戻り値は stat
; hWndClient : HWND -> "sptr"
; hWndServer : HWND -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global ImpersonateDdeClientWindow "ImpersonateDdeClientWindow" sptr, sptr
; res = ImpersonateDdeClientWindow(hWndClient, hWndServer)
; hWndClient : HWND -> "sptr"
; hWndServer : HWND -> "sptr"; BOOL ImpersonateDdeClientWindow(HWND hWndClient, HWND hWndServer)
#uselib "USER32.dll"
#cfunc global ImpersonateDdeClientWindow "ImpersonateDdeClientWindow" intptr, intptr
; res = ImpersonateDdeClientWindow(hWndClient, hWndServer)
; hWndClient : HWND -> "intptr"
; hWndServer : HWND -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procImpersonateDdeClientWindow = user32.NewProc("ImpersonateDdeClientWindow")
)
// hWndClient (HWND), hWndServer (HWND)
r1, _, err := procImpersonateDdeClientWindow.Call(
uintptr(hWndClient),
uintptr(hWndServer),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction ImpersonateDdeClientWindow(
hWndClient: THandle; // HWND
hWndServer: THandle // HWND
): BOOL; stdcall;
external 'USER32.dll' name 'ImpersonateDdeClientWindow';result := DllCall("USER32\ImpersonateDdeClientWindow"
, "Ptr", hWndClient ; HWND
, "Ptr", hWndServer ; HWND
, "Int") ; return: BOOL●ImpersonateDdeClientWindow(hWndClient, hWndServer) = DLL("USER32.dll", "bool ImpersonateDdeClientWindow(void*, void*)")
# 呼び出し: ImpersonateDdeClientWindow(hWndClient, hWndServer)
# hWndClient : HWND -> "void*"
# hWndServer : HWND -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "user32" fn ImpersonateDdeClientWindow(
hWndClient: ?*anyopaque, // HWND
hWndServer: ?*anyopaque // HWND
) callconv(std.os.windows.WINAPI) i32;proc ImpersonateDdeClientWindow(
hWndClient: pointer, # HWND
hWndServer: pointer # HWND
): int32 {.importc: "ImpersonateDdeClientWindow", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
int ImpersonateDdeClientWindow(
void* hWndClient, // HWND
void* hWndServer // HWND
);ccall((:ImpersonateDdeClientWindow, "USER32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}),
hWndClient, hWndServer)
# hWndClient : HWND -> Ptr{Cvoid}
# hWndServer : HWND -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t ImpersonateDdeClientWindow(
void* hWndClient,
void* hWndServer);
]]
local user32 = ffi.load("user32")
-- user32.ImpersonateDdeClientWindow(hWndClient, hWndServer)
-- hWndClient : HWND
-- hWndServer : HWND
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const ImpersonateDdeClientWindow = lib.func('__stdcall', 'ImpersonateDdeClientWindow', 'int32_t', ['void *', 'void *']);
// ImpersonateDdeClientWindow(hWndClient, hWndServer)
// hWndClient : HWND -> 'void *'
// hWndServer : HWND -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
ImpersonateDdeClientWindow: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.ImpersonateDdeClientWindow(hWndClient, hWndServer)
// hWndClient : HWND -> "pointer"
// hWndServer : HWND -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ImpersonateDdeClientWindow(
void* hWndClient,
void* hWndServer);
C, "USER32.dll");
// $ffi->ImpersonateDdeClientWindow(hWndClient, hWndServer);
// hWndClient : HWND
// hWndServer : HWND
// 構造体/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);
boolean ImpersonateDdeClientWindow(
Pointer hWndClient, // HWND
Pointer hWndServer // HWND
);
}@[Link("user32")]
lib LibUSER32
fun ImpersonateDdeClientWindow = ImpersonateDdeClientWindow(
hWndClient : Void*, # HWND
hWndServer : Void* # HWND
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ImpersonateDdeClientWindowNative = Int32 Function(Pointer<Void>, Pointer<Void>);
typedef ImpersonateDdeClientWindowDart = int Function(Pointer<Void>, Pointer<Void>);
final ImpersonateDdeClientWindow = DynamicLibrary.open('USER32.dll')
.lookupFunction<ImpersonateDdeClientWindowNative, ImpersonateDdeClientWindowDart>('ImpersonateDdeClientWindow');
// hWndClient : HWND -> Pointer<Void>
// hWndServer : HWND -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ImpersonateDdeClientWindow(
hWndClient: THandle; // HWND
hWndServer: THandle // HWND
): BOOL; stdcall;
external 'USER32.dll' name 'ImpersonateDdeClientWindow';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ImpersonateDdeClientWindow"
c_ImpersonateDdeClientWindow :: Ptr () -> Ptr () -> IO CInt
-- hWndClient : HWND -> Ptr ()
-- hWndServer : HWND -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let impersonateddeclientwindow =
foreign "ImpersonateDdeClientWindow"
((ptr void) @-> (ptr void) @-> returning int32_t)
(* hWndClient : HWND -> (ptr void) *)
(* hWndServer : HWND -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("ImpersonateDdeClientWindow" impersonate-dde-client-window :convention :stdcall) :int32
(h-wnd-client :pointer) ; HWND
(h-wnd-server :pointer)) ; HWND
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ImpersonateDdeClientWindow = Win32::API::More->new('USER32',
'BOOL ImpersonateDdeClientWindow(HANDLE hWndClient, HANDLE hWndServer)');
# my $ret = $ImpersonateDdeClientWindow->Call($hWndClient, $hWndServer);
# hWndClient : HWND -> HANDLE
# hWndServer : HWND -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f DdeImpersonateClient — DDEサーバーがクライアントになりすましてアクセスする。
- f RevertToSelf — 偽装を終了し元のセキュリティコンテキストに戻す。