using System; using System.Runtime.InteropServices; using Vanara.Extensions; using Vanara.InteropServices; namespace Vanara.PInvoke { /// Items from the Rpc.dll public static partial class Rpc { /// Dispatch function delegate. /// The message. [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void RPC_DISPATCH_FUNCTION(ref RPC_MESSAGE Message); /// /// /// [The I_RpcBindingInqLocalClientPID function is available for use in the operating systems specified in the Requirements /// section. Instead, call RpcServerInqCallAttributes.] /// /// The I_RpcBindingInqLocalClientPID function obtains a client process ID. /// /// /// RPC_BINDING_HANDLE that specifies the binding handle for an explicit RPC binding from the client to a server application. /// /// Contains the process ID of the client that issued the call upon return. /// /// /// /// Value /// Meaning /// /// /// RPC_S_OK /// The function call was successful. /// /// /// RPC_S_NO_CALL_ACTIVE /// The current thread does not have an active RPC call. /// /// /// RPC_S_INVALID_BINDING /// The RPC binding handle is invalid. /// /// /// Note For a list of valid error codes, see RPC Return Values. /// /// /// The client process ID is only returned in ClientBinding when the "ncalrpc" protocol sequence is used. Until the process /// terminates, the process ID value uniquely identifies it on the client. When the process terminates, the process ID can be used /// by new processes. /// // https://docs.microsoft.com/en-us/windows/win32/api/rpcdcep/nf-rpcdcep-i_rpcbindinginqlocalclientpid RPC_STATUS // I_RpcBindingInqLocalClientPID( RPC_BINDING_HANDLE Binding, unsigned long *Pid ); [DllImport(Lib_rpcrt4, SetLastError = false, ExactSpelling = true)] [PInvokeData("rpcdcep.h", MSDNShortId = "NF:rpcdcep.I_RpcBindingInqLocalClientPID")] public static extern Win32Error I_RpcBindingInqLocalClientPID(RPC_BINDING_HANDLE Binding, out uint Pid); /// /// /// The RPC_CLIENT_INTERFACE structure is part of the private interface between the run-time libraries and the stubs. Most /// distributed applications that use Microsoft RPC do not need this structure. /// /// The data structure is defined in the header file Rpcdcep.h. See the header file for syntax block and member definitions. /// // https://docs.microsoft.com/en-us/windows/win32/api/rpcdcep/ns-rpcdcep-rpc_client_interface typedef struct _RPC_CLIENT_INTERFACE { // unsigned int Length; RPC_SYNTAX_IDENTIFIER InterfaceId; RPC_SYNTAX_IDENTIFIER TransferSyntax; PRPC_DISPATCH_TABLE DispatchTable; // unsigned int RpcProtseqEndpointCount; PRPC_PROTSEQ_ENDPOINT RpcProtseqEndpoint; ULONG_PTR Reserved; void const *InterpreterInfo; // unsigned int Flags; } RPC_CLIENT_INTERFACE, *PRPC_CLIENT_INTERFACE; [PInvokeData("rpcdcep.h", MSDNShortId = "NS:rpcdcep._RPC_CLIENT_INTERFACE")] [StructLayout(LayoutKind.Sequential)] public unsafe struct RPC_CLIENT_INTERFACE { /// public uint Length; /// public RPC_SYNTAX_IDENTIFIER InterfaceId; /// public RPC_SYNTAX_IDENTIFIER TransferSyntax; /// public RPC_DISPATCH_TABLE* DispatchTable; /// public uint RpcProtseqEndpointCount; /// public RPC_PROTSEQ_ENDPOINT* RpcProtseqEndpoint; /// public UIntPtr Reserved; /// public IntPtr InterpreterInfo; /// public uint Flags; } /// /// /// The RPC_DISPATCH_TABLE structure is part of the private interface between the run-time libraries and the stubs. Most /// distributed applications that use Microsoft RPC do not need this structure. /// /// The structure is defined in the header file Rpcdcep.h. See the header file for syntax block and member definitions. /// // https://docs.microsoft.com/en-us/windows/win32/api/rpcdcep/ns-rpcdcep-rpc_dispatch_table typedef struct { unsigned int // DispatchTableCount; RPC_DISPATCH_FUNCTION *DispatchTable; LONG_PTR Reserved; } RPC_DISPATCH_TABLE, *PRPC_DISPATCH_TABLE; [PInvokeData("rpcdcep.h", MSDNShortId = "NS:rpcdcep.__unnamed_struct_0")] [StructLayout(LayoutKind.Sequential)] public struct RPC_DISPATCH_TABLE { /// public uint DispatchTableCount; /// public IntPtr DispatchTable; /// public IntPtr Reserved; /// public IntPtr[] GetDispatchTable() => DispatchTable.ToArray((int)DispatchTableCount); } /// The RPC_MESSAGE structure contains information shared between NDR and the rest of the RPC or OLE runtime. // https://docs.microsoft.com/en-us/windows/win32/api/rpcdcep/ns-rpcdcep-rpc_message typedef struct _RPC_MESSAGE { // RPC_BINDING_HANDLE Handle; unsigned long DataRepresentation; void *Buffer; unsigned int BufferLength; unsigned int ProcNum; // PRPC_SYNTAX_IDENTIFIER TransferSyntax; void *RpcInterfaceInformation; void *ReservedForRuntime; RPC_MGR_EPV *ManagerEpv; void // *ImportContext; unsigned long RpcFlags; } RPC_MESSAGE, *PRPC_MESSAGE; [PInvokeData("rpcdcep.h", MSDNShortId = "NS:rpcdcep._RPC_MESSAGE")] [StructLayout(LayoutKind.Sequential)] public unsafe struct RPC_MESSAGE { /// Reserved. public RPC_BINDING_HANDLE Handle; /// Data representation of the network buffer as defined by the NDR specification. public uint DataRepresentation; /// Pointer to the beginning of the network buffer. public IntPtr Buffer; /// Size, in bytes, of Buffer. public uint BufferLength; /// Reserved. public uint ProcNum; /// Reserved. public RPC_SYNTAX_IDENTIFIER* TransferSyntax; /// Reserved. public IntPtr RpcInterfaceInformation; /// Reserved. public IntPtr ReservedForRuntime; /// Reserved. public IntPtr ManagerEpv; /// Reserved. public IntPtr ImportContext; /// Reserved. public uint RpcFlags; } /// [StructLayout(LayoutKind.Sequential)] public struct RPC_PROTSEQ_ENDPOINT { /// public StrPtrAnsi RpcProtocolSequence; /// public StrPtrAnsi Endpoint; } /// [StructLayout(LayoutKind.Sequential)] public unsafe struct RPC_SERVER_INTERFACE { /// public uint Length; /// public RPC_SYNTAX_IDENTIFIER InterfaceId; /// public RPC_SYNTAX_IDENTIFIER TransferSyntax; /// public RPC_DISPATCH_TABLE* DispatchTable; /// public uint RpcProtseqEndpointCount; /// public RPC_PROTSEQ_ENDPOINT* RpcProtseqEndpoint; /// public IntPtr DefaultManagerEpv; /// public IntPtr InterpreterInfo; /// public uint Flags; } /// [StructLayout(LayoutKind.Sequential)] public struct RPC_SYNTAX_IDENTIFIER { /// public Guid SyntaxGUID; /// public RPC_VERSION SyntaxVersion; /// Initializes a new instance of the struct. /// The syntax. /// The maj ver. /// The minimum ver. public RPC_SYNTAX_IDENTIFIER(in Guid syntax, ushort majVer, ushort minVer = 0) { SyntaxGUID = syntax; SyntaxVersion = new RPC_VERSION { MajorVersion = majVer, MinorVersion = minVer }; } } /// [StructLayout(LayoutKind.Sequential)] public struct RPC_VERSION { /// public ushort MajorVersion; /// public ushort MinorVersion; } } }