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

CoAllowSetForegroundWindow

関数
指定したCOMオブジェクトに前面ウィンドウ設定を許可する。
DLLOLE32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HRESULT CoAllowSetForegroundWindow(
    IUnknown* pUnk,
    void* lpvReserved   // optional
);

パラメーター

名前方向
pUnkIUnknown*in
lpvReservedvoid*inoptional

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT CoAllowSetForegroundWindow(
    IUnknown* pUnk,
    void* lpvReserved   // optional
);
[DllImport("OLE32.dll", ExactSpelling = true)]
static extern int CoAllowSetForegroundWindow(
    IntPtr pUnk,   // IUnknown*
    IntPtr lpvReserved   // void* optional
);
<DllImport("OLE32.dll", ExactSpelling:=True)>
Public Shared Function CoAllowSetForegroundWindow(
    pUnk As IntPtr,   ' IUnknown*
    lpvReserved As IntPtr   ' void* optional
) As Integer
End Function
' pUnk : IUnknown*
' lpvReserved : void* optional
Declare PtrSafe Function CoAllowSetForegroundWindow Lib "ole32" ( _
    ByVal pUnk As LongPtr, _
    ByVal lpvReserved As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CoAllowSetForegroundWindow = ctypes.windll.ole32.CoAllowSetForegroundWindow
CoAllowSetForegroundWindow.restype = ctypes.c_int
CoAllowSetForegroundWindow.argtypes = [
    ctypes.c_void_p,  # pUnk : IUnknown*
    ctypes.POINTER(None),  # lpvReserved : void* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('OLE32.dll')
CoAllowSetForegroundWindow = Fiddle::Function.new(
  lib['CoAllowSetForegroundWindow'],
  [
    Fiddle::TYPE_VOIDP,  # pUnk : IUnknown*
    Fiddle::TYPE_VOIDP,  # lpvReserved : void* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "ole32")]
extern "system" {
    fn CoAllowSetForegroundWindow(
        pUnk: *mut core::ffi::c_void,  // IUnknown*
        lpvReserved: *mut ()  // void* optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("OLE32.dll")]
public static extern int CoAllowSetForegroundWindow(IntPtr pUnk, IntPtr lpvReserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLE32_CoAllowSetForegroundWindow' -Namespace Win32 -PassThru
# $api::CoAllowSetForegroundWindow(pUnk, lpvReserved)
#uselib "OLE32.dll"
#func global CoAllowSetForegroundWindow "CoAllowSetForegroundWindow" sptr, sptr
; CoAllowSetForegroundWindow pUnk, lpvReserved   ; 戻り値は stat
; pUnk : IUnknown* -> "sptr"
; lpvReserved : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "OLE32.dll"
#cfunc global CoAllowSetForegroundWindow "CoAllowSetForegroundWindow" sptr, sptr
; res = CoAllowSetForegroundWindow(pUnk, lpvReserved)
; pUnk : IUnknown* -> "sptr"
; lpvReserved : void* optional -> "sptr"
; HRESULT CoAllowSetForegroundWindow(IUnknown* pUnk, void* lpvReserved)
#uselib "OLE32.dll"
#cfunc global CoAllowSetForegroundWindow "CoAllowSetForegroundWindow" intptr, intptr
; res = CoAllowSetForegroundWindow(pUnk, lpvReserved)
; pUnk : IUnknown* -> "intptr"
; lpvReserved : void* optional -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ole32 = windows.NewLazySystemDLL("OLE32.dll")
	procCoAllowSetForegroundWindow = ole32.NewProc("CoAllowSetForegroundWindow")
)

// pUnk (IUnknown*), lpvReserved (void* optional)
r1, _, err := procCoAllowSetForegroundWindow.Call(
	uintptr(pUnk),
	uintptr(lpvReserved),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function CoAllowSetForegroundWindow(
  pUnk: Pointer;   // IUnknown*
  lpvReserved: Pointer   // void* optional
): Integer; stdcall;
  external 'OLE32.dll' name 'CoAllowSetForegroundWindow';
result := DllCall("OLE32\CoAllowSetForegroundWindow"
    , "Ptr", pUnk   ; IUnknown*
    , "Ptr", lpvReserved   ; void* optional
    , "Int")   ; return: HRESULT
●CoAllowSetForegroundWindow(pUnk, lpvReserved) = DLL("OLE32.dll", "int CoAllowSetForegroundWindow(void*, void*)")
# 呼び出し: CoAllowSetForegroundWindow(pUnk, lpvReserved)
# pUnk : IUnknown* -> "void*"
# lpvReserved : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。