protected void InitializeStub(Guid interfaceID, byte[] MIDL_ProcFormatString, byte[] MIDL_TypeFormatString, string pipe, ushort MajorVerson = 1, ushort MinorVersion = 0) { this.MIDL_ProcFormatString = MIDL_ProcFormatString; this.MIDL_TypeFormatString = MIDL_TypeFormatString; PipeName = pipe; procString = GCHandle.Alloc(this.MIDL_ProcFormatString, GCHandleType.Pinned); RPC_CLIENT_INTERFACE clientinterfaceObject = new RPC_CLIENT_INTERFACE(interfaceID, MajorVerson, MinorVersion); GENERIC_BINDING_ROUTINE_PAIR bindingObject = new GENERIC_BINDING_ROUTINE_PAIR(); // important: keep a reference to avoid CallbakcOnCollectedDelegate Exception BindDelegate = Bind; UnbindDelegate = Unbind; bindingObject.Bind = Marshal.GetFunctionPointerForDelegate((bind)BindDelegate); bindingObject.Unbind = Marshal.GetFunctionPointerForDelegate((unbind)UnbindDelegate); faultoffsets = GCHandle.Alloc(new COMM_FAULT_OFFSETS() { CommOffset = -1, FaultOffset = -1 }, GCHandleType.Pinned); clientinterface = GCHandle.Alloc(clientinterfaceObject, GCHandleType.Pinned); formatString = GCHandle.Alloc(MIDL_TypeFormatString, GCHandleType.Pinned); bindinghandle = GCHandle.Alloc(bindingObject, GCHandleType.Pinned); MIDL_STUB_DESC stubObject = new MIDL_STUB_DESC(formatString.AddrOfPinnedObject(), clientinterface.AddrOfPinnedObject(), Marshal.GetFunctionPointerForDelegate(AllocateMemoryDelegate), Marshal.GetFunctionPointerForDelegate(FreeMemoryDelegate), bindinghandle.AddrOfPinnedObject()); rpcClientInterface = stubObject.RpcInterfaceInformation; stub = GCHandle.Alloc(stubObject, GCHandleType.Pinned); }
private static IntPtr GetClientInterface() { RPC_VERSION rpcv1 = new RPC_VERSION { MajorVersion = 1, MinorVersion = 0 }; RPC_VERSION rpcv2 = new RPC_VERSION { MajorVersion = 2, MinorVersion = 0 }; RPC_SYNTAX_IDENTIFIER InterfaceId = new RPC_SYNTAX_IDENTIFIER { SyntaxGUID = new Guid(0x76f03f96, 0xcdfd, 0x44fc, 0xa2, 0x2c, 0x64, 0x95, 0x0a, 0x00, 0x12, 0x09), SyntaxVersion = rpcv1 }; RPC_SYNTAX_IDENTIFIER TransferSyntax = new RPC_SYNTAX_IDENTIFIER { SyntaxGUID = new Guid(0x8a885d04, 0x1ceb, 0x11c9, 0x9f, 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60), SyntaxVersion = rpcv2 }; RPC_CLIENT_INTERFACE logonRpcClientInterface = new RPC_CLIENT_INTERFACE { Length = (uint)Marshal.SizeOf(typeof(RPC_CLIENT_INTERFACE)), InterfaceId = InterfaceId, TransferSyntax = TransferSyntax, DispatchTable = IntPtr.Zero, //PRPC_DISPATCH_TABLE RpcProtseqEndpointCount = 0, RpcProtseqEndpoint = IntPtr.Zero, //PRPC_PROTSEQ_ENDPOINT Reserved = IntPtr.Zero, InterpreterInfo = IntPtr.Zero, Flags = 0x00000000 }; IntPtr plogonRpcClientInterface = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(RPC_CLIENT_INTERFACE))); Marshal.StructureToPtr(logonRpcClientInterface, plogonRpcClientInterface, false); return(plogonRpcClientInterface); }
public static RPC_CLIENT_INTERFACE CreatExplicitBytesClient(Guid iid) { var client = new RPC_CLIENT_INTERFACE(); client.Length = (uint)Marshal.SizeOf(typeof(RPC_CLIENT_INTERFACE)); client.InterfaceId = new RPC_SYNTAX_IDENTIFIER() { SyntaxGUID = iid, SyntaxVersion = ExplicitBytesConstants.INTERFACE_VERSION }; client.TransferSyntax = new RPC_SYNTAX_IDENTIFIER() { SyntaxGUID = SYNTAX.SYNTAX_IID, SyntaxVersion = SYNTAX.SYNTAX_VERSION }; client.DispatchTable = IntPtr.Zero; client.RpcProtseqEndpointCount = 0u; client.RpcProtseqEndpoint = IntPtr.Zero; client.Reserved = IntPtr.Zero; client.InterpreterInfo = IntPtr.Zero; client.Flags = 0u; return(client); }