From 6d7fd73bba6b59e37aa4f09777b1d3644b6685cc Mon Sep 17 00:00:00 2001 From: dahall Date: Mon, 8 Feb 2021 09:19:12 -0700 Subject: [PATCH] Added IContextCallback (#209) --- PInvoke/Ole/Ole32/CtxtCall.cs | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 PInvoke/Ole/Ole32/CtxtCall.cs diff --git a/PInvoke/Ole/Ole32/CtxtCall.cs b/PInvoke/Ole/Ole32/CtxtCall.cs new file mode 100644 index 00000000..a686c475 --- /dev/null +++ b/PInvoke/Ole/Ole32/CtxtCall.cs @@ -0,0 +1,70 @@ +using System; +using System.Runtime.InteropServices; + +namespace Vanara.PInvoke +{ + public static partial class Ole32 + { + /// + /// The function to be called inside the object context if . + /// + /// The data passed to the function when it is called in the context. + /// The result. Typically the result of . + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + [PInvokeData("ctxtcall.h", MSDNShortId = "NN:ctxtcall.IContextCallback")] + public delegate HRESULT PFNCONTEXTCALL(in ComCallData data); + + /// Provides a mechanism to execute a function inside a specific COM+ object context. + /// An instance of this interface for the current context can be obtained using CoGetObjectContext. + // https://docs.microsoft.com/en-us/windows/win32/api/ctxtcall/nn-ctxtcall-icontextcallback + [PInvokeData("ctxtcall.h", MSDNShortId = "NN:ctxtcall.IContextCallback")] + [ComImport, Guid("000001da-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface IContextCallback + { + /// Enters the object context, executes the specified function, and returns. + /// The function to be called inside the object context. + /// The data to be passed to the function when it is called in the context. + /// The IID of the call that is being simulated. See Remarks for more information. + /// The method number of the call that is being simulated. See Remarks for more information. + /// This parameter is reserved and must be NULL. + /// + /// This method can return the standard return values E_INVALIDARG, E_OUTOFMEMORY, E_UNEXPECTED, and E_FAIL. If none of these + /// failures occur, the return value of this function is the HRESULT value returned by the pfnCallback function. + /// + /// + /// + /// This method simulates a method call on an object inside the context. It is intended for low-level operations, such as + /// cleanup/lazy marshaling, that respect the application's reentrancy expectations. + /// + /// + /// To give the infrastructure information, an interface and method number must be specified. The parameter riid must not be + /// IID_IUnknown, and the method number must not be less than 3. + /// + /// If riid is set to IID_IEnterActivityWithNoLock, the function is executed without an activity lock. + /// + /// If riid is set to IID_ICallbackWithNoReentrancyToApplicationSTA, the function does not reenter an ASTA arbitrarily. Most + /// apps should set riid to this values for general purpose use. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/ctxtcall/nf-ctxtcall-icontextcallback-contextcallback + [PreserveSig] + HRESULT ContextCallback(PFNCONTEXTCALL pfnCallback, in ComCallData pParam, in Guid riid, int iMethod, [In, Optional] IntPtr pUnk); + } + + /// + [PInvokeData("ctxtcall.h", MSDNShortId = "NN:ctxtcall.IContextCallback")] + [StructLayout(LayoutKind.Sequential)] + public struct ComCallData + { + /// + public int dwDispid; + + /// + public int dwReserved; + + /// + public IntPtr pUserDefined; + } + } +} \ No newline at end of file