using System; using System.Runtime.InteropServices; namespace Vanara.PInvoke { /// Items from the Rpc.dll public static partial class Rpc { /// /// public unsafe delegate int SERVER_ROUTINE(); /// The NdrClientCall2 function is the client-side entry point for the /Oicf mode stub. /// /// Pointer to the MIDL-generated MIDL_STUB_DESC structure that contains information about the description of the remote interface. /// /// Pointer to the MIDL-generated procedure format string that describes the method and parameters. /// Pointer to the client-side calling stack. /// /// /// Return value of the remote call. The maximum size of a return value is equivalent to the register size of the system. MIDL /// switches to the /Os mode stub if the return value size is larger than the register size. /// /// Depending on the method definition, this function can throw an exception if there is a network or server failure. /// /// /// The NdrClientCall2 function is used by all /Oicf mode client-side stubs. The NdrClientCall2 function transmits all /// [in] data to the remote server, and upon receipt of the response packet, returns the [out] value to the client-side application. /// // https://docs.microsoft.com/en-us/windows/win32/api/rpcndr/nf-rpcndr-ndrclientcall2 CLIENT_CALL_RETURN RPC_VAR_ENTRY // NdrClientCall2( PMIDL_STUB_DESC pStubDescriptor, PFORMAT_STRING pFormat, ... ); [DllImport(Lib_rpcrt4, SetLastError = false, ExactSpelling = true)] [PInvokeData("rpcndr.h", MSDNShortId = "NF:rpcndr.NdrClientCall2")] public static extern IntPtr NdrClientCall2(/*PMIDL_STUB_DESC*/ IntPtr pStubDescriptor, /*PFORMAT_STRING*/ IntPtr pFormat, IntPtr pArguments); /// Converts a value to a four-byte array. /// The value. /// The byte array. public static byte[] NdrFcLong(int s) => new[] { (byte)(s & 0xff), (byte)((s & 0x0000ff00) >> 8), (byte)((s & 0x00ff0000) >> 16), (byte)(s >> 24) }; /// Converts a value to a two-byte array. /// The value. /// The byte array. public static byte[] NdrFcShort(int s) => new[] { (byte)(s & 0xff), (byte)(s >> 8) }; /// [PInvokeData("rpcndr.h")] [StructLayout(LayoutKind.Sequential)] public struct MIDL_SERVER_INFO { /// public IntPtr /* PMIDL_STUB_DESC */ pStubDesc; /// public IntPtr /* const SERVER_ROUTINE* */ DispatchTable; /// public IntPtr /* PFORMAT_STRING */ ProcString; /// public IntPtr /* const unsigned short* */ FmtStringOffset; /// public IntPtr /* const STUB_THUNK* */ ThunkTable; /// public IntPtr /* PRPC_SYNTAX_IDENTIFIER */ pTransferSyntax; /// public IntPtr /* ULONG_PTR */ nCount; /// public IntPtr /* PMIDL_SYNTAX_INFO */ pSyntaxInfo; } /// /// The MIDL_STUB_DESC structure is a MIDL-generated structure that contains information about the interface stub regarding /// RPC calls between the client and server. /// // https://docs.microsoft.com/en-us/windows/win32/api/rpcndr/ns-rpcndr-midl_stub_desc typedef struct _MIDL_STUB_DESC { void // *RpcInterfaceInformation; void * )(size_t) *(pfnAllocate; void()(void *) * pfnFree; union { handle_t *pAutoHandle; handle_t // *pPrimitiveHandle; PGENERIC_BINDING_INFO pGenericBindingInfo; } IMPLICIT_HANDLE_INFO; const NDR_RUNDOWN *apfnNdrRundownRoutines; // const GENERIC_BINDING_ROUTINE_PAIR *aGenericBindingRoutinePairs; const EXPR_EVAL *apfnExprEval; const XMIT_ROUTINE_QUINTUPLE // *aXmitQuintuple; const unsigned char *pFormatTypes; int fCheckBounds; unsigned long Version; MALLOC_FREE_STRUCT // *pMallocFreeStruct; long MIDLVersion; const COMM_FAULT_OFFSETS *CommFaultOffsets; const USER_MARSHAL_ROUTINE_QUADRUPLE // *aUserMarshalQuadruple; const NDR_NOTIFY_ROUTINE *NotifyRoutineTable; ULONG_PTR mFlags; const NDR_CS_ROUTINES *CsRoutineTables; // void *ProxyServerInfo; const NDR_EXPR_DESC *pExprInfo; } MIDL_STUB_DESC; [PInvokeData("rpcndr.h", MSDNShortId = "NS:rpcndr._MIDL_STUB_DESC")] [StructLayout(LayoutKind.Sequential)] public struct MIDL_STUB_DESC { /// /// For a nonobject RPC interface on the server-side, it points to an RPC server interface structure. On the client-side, it /// points to an RPC client interface structure. It is null for an object interface. /// public IntPtr RpcInterfaceInformation; /// /// Memory allocation function to be used by the stub. Set to midl_user_allocate for nonobject interface and NdrOleAllocate for /// object interface. /// [MarshalAs(UnmanagedType.FunctionPtr)] public Func pfnAllocate; /// /// Memory-free function to be used by the stub. Set to midl_user_free for nonobject interface and NdrOleFree for object interface. /// [MarshalAs(UnmanagedType.FunctionPtr)] public Action pfnFree; /// /// The union contains one of the following handles. /// /// Pointer to the implicit auto handle for the RPC call. /// Pointer to the implicit primitive handle for the RPC call. /// Pointer to the information about the implicit generic handle. /// /// public IntPtr pImplicitHandleInfo; /// Array of context handle rundown functions. public IntPtr apfnNdrRundownRoutines; /// Array of function pointers to bind and unbind function pairs for the implicit generic handle. public IntPtr aGenericBindingRoutinePairs; /// /// Array of function pointers to expression evaluator functions used to evaluate MIDL complex conformance and varying /// descriptions. For example, size_is(param1 + param2). /// public IntPtr apfnExprEval; /// Array of an array of function pointers for user-defined transmit_as and represent_as types. public IntPtr aXmitQuintuple; /// Pointer to the type format description. public IntPtr pFormatTypes; /// Flag describing the user-specified /error MIDL compiler option. public int fCheckBounds; /// NDR version required for the stub. public uint Version; /// /// Pointer to the MALLOC_FREE_STRUCT structure which contains the allocate and free function pointers. Use if the /// enable_allocate MIDL attribute is specified. /// public IntPtr pMallocFreeStruct; /// Version of the MIDL compiler used to compile the .idl file. public long MIDLVersion; /// Array of stack offsets for parameters with comm_status or fault_status attributes. public IntPtr CommFaultOffsets; /// Array of an array of function pointers for user-defined user_marshal and wire_marshal types. public IntPtr aUserMarshalQuadruple; /// Array of notification function pointers for methods with the notify or notify_flag attribute specified. public IntPtr NotifyRoutineTable; /// /// Flag describing the attributes of the stub /// /// /// Value /// Meaning /// /// /// RPCFLG_HAS_MULTI_SYNTAXES /// Set if the stub supports multiple transfer syntaxes. /// /// /// RPCFLG_HAS_CALLBACK /// Set if the interface contains callback functions. /// /// /// RPC_INTERFACE_HAS_PIPES /// Set if the interface contains a method that uses pipes. /// /// /// public UIntPtr mFlags; /// Unused. public IntPtr CsRoutineTables; /// public IntPtr ProxyServerInfo; /// public IntPtr pExprInfo; } } }