internal extern static void NdrMesTypeEncode2(
     IntPtr Handle,
     ref MIDL_TYPE_PICKLING_INFO pPicklingInfo,
     ref MIDL_STUB_DESC pStubDesc,
     [MarshalAs(UnmanagedType.LPArray)]
     byte[] pFormatString,
     ref IntPtr pObject);
        /// <summary>
        /// Initializes an instance of PickleMarshaller class from a type format string.
        /// </summary>
        /// <param name="midlTypeFormatString">The type format string used to initialize the object.
        /// More details about format string and how to generate it please refer to current class' summary.</param>
        public PickleMarshaller(byte[] midlTypeFormatString)
        {
            if (midlTypeFormatString == null)
            {
                throw new ArgumentNullException("midlTypeFormatString");
            }

            typeFormatString = new byte[midlTypeFormatString.Length];
            Buffer.BlockCopy(midlTypeFormatString, 0, typeFormatString, 0, midlTypeFormatString.Length);

            #region MIDL_TYPE_PICKLING_INFO __MIDL_TypePicklingInfo
            // Following values are assigned according to midl.exe generated rpc stub code:
            //    static MIDL_TYPE_PICKLING_INFO __MIDL_TypePicklingInfo =
            //    {
            //    0x33205054, /* Signature & version: TP 1 */
            //    0x3, /* Flags: Oicf NewCorrDesc */
            //    0,
            //    0,
            //    0,
            //    };
            // See summary of current class for details on how to generate rpc stub code.
            __MIDL_TypePicklingInfo          = new MIDL_TYPE_PICKLING_INFO();
            __MIDL_TypePicklingInfo.Version  = 0x33205054; /* Signature & version: TP 1 */
            __MIDL_TypePicklingInfo.Flags    = 0x3;        /* Flags: Oicf NewCorrDesc */
            __MIDL_TypePicklingInfo.Reserved = new uint[] { 0, 0, 0 };
            #endregion

            #region RPC_CLIENT_INTERFACE rpcClientInterface
            // Following values are assigned according to midl.exe generated rpc stub code:
            //        static const RPC_CLIENT_INTERFACE type_pickle___RpcClientInterface =
            //        {
            //        sizeof(RPC_CLIENT_INTERFACE),
            //        {{0x906B0CE0,0xC70B,0x1067,{0xB3,0x17,0x00,0xDD,0x01,0x06,0x62,0xDA}},{1,0}},
            //        {{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}},
            //        0,
            //        0,
            //        0,
            //        0,
            //        0,
            //        0x00000000
            //        };
            // See summary of current class for details on how to generate rpc stub code.
            RPC_CLIENT_INTERFACE rpcClientInterface = new RPC_CLIENT_INTERFACE();
            rpcClientInterface.Length                    = (uint)Marshal.SizeOf(typeof(RPC_CLIENT_INTERFACE));
            rpcClientInterface.InterfaceId               = new RPC_SYNTAX_IDENTIFIER();
            rpcClientInterface.InterfaceId.SyntaxGUID    = new Guid(0x906B0CE0, 0xC70B, 0x1067, 0xB3, 0x17, 0x00, 0xDD, 0x01, 0x06, 0x62, 0xDA);
            rpcClientInterface.InterfaceId.SyntaxVersion = new RPC_VERSION();
            rpcClientInterface.InterfaceId.SyntaxVersion.MajorVersion = 1;
            rpcClientInterface.InterfaceId.SyntaxVersion.MinorVersion = 0;
            rpcClientInterface.TransferSyntax               = new RPC_SYNTAX_IDENTIFIER();
            rpcClientInterface.TransferSyntax.SyntaxGUID    = new Guid(0x8A885D04, 0x1CEB, 0x11C9, 0x9F, 0xE8, 0x08, 0x00, 0x2B, 0x10, 0x48, 0x60);
            rpcClientInterface.TransferSyntax.SyntaxVersion = new RPC_VERSION();
            rpcClientInterface.TransferSyntax.SyntaxVersion.MajorVersion = 2;
            rpcClientInterface.TransferSyntax.SyntaxVersion.MinorVersion = 0;
            rpcClientInterface.DispatchTable           = IntPtr.Zero;
            rpcClientInterface.RpcProtseqEndpointCount = 0;
            rpcClientInterface.RpcProtseqEndpoint      = IntPtr.Zero;
            rpcClientInterface.Reserved        = 0;
            rpcClientInterface.InterpreterInfo = IntPtr.Zero;
            rpcClientInterface.Flags           = 0x00000000;
            #endregion

            #region MIDL_STUB_DESC stubDesc
            // Following values are assigned according to midl.exe generated rpc stub code:
            //    static const MIDL_STUB_DESC type_pickle_StubDesc =
            //    {
            //    (void *)& type_pickle___RpcClientInterface,
            //    MIDL_user_allocate,
            //    MIDL_user_free,
            //    &ImplicitPicHandle,
            //    0,
            //    0,
            //    0,
            //    0,
            //    Picklt__MIDL_TypeFormatString.Format,
            //    1, /* -error bounds_check flag */
            //    0x50004, /* Ndr library version */
            //    0,
            //    0x70001f4, /* MIDL Version 7.0.500 */
            //    0,
            //    0,
            //    0,  /* notify & notify_flag routine table */
            //    0x1, /* MIDL flag */
            //    0, /* cs routines */
            //    0,   /* proxy/server info */
            //    0
            //    };
            // See summary of current class for details on how to generate rpc stub code.
            stubDesc = new MIDL_STUB_DESC();
            stubDesc.RpcInterfaceInformation = Marshal.AllocHGlobal(Marshal.SizeOf(rpcClientInterface));
            Marshal.StructureToPtr(rpcClientInterface, stubDesc.RpcInterfaceInformation, false);
            stubDesc.pfnAllocate                 = new PfnAllocate(MIDL_user_allocate);
            stubDesc.pfnFree                     = new PfnFree(MIDL_user_free);
            stubDesc.apfnNdrRundownRoutines      = IntPtr.Zero;
            stubDesc.aGenericBindingRoutinePairs = IntPtr.Zero;
            stubDesc.apfnExprEval                = IntPtr.Zero;
            stubDesc.aXmitQuintuple              = IntPtr.Zero;
            stubDesc.pFormatTypes                = Marshal.AllocHGlobal(midlTypeFormatString.Length);
            Marshal.Copy(typeFormatString, 0, stubDesc.pFormatTypes, typeFormatString.Length);
            stubDesc.fCheckBounds          = 1;         /* -error bounds_check flag */
            stubDesc.Version               = 0x50004;   /* Ndr library version */
            stubDesc.pMallocFreeStruct     = IntPtr.Zero;
            stubDesc.MIDLVersion           = 0x600016e; /* MIDL Version 6.0.366 */
            stubDesc.CommFaultOffsets      = IntPtr.Zero;
            stubDesc.aUserMarshalQuadruple = IntPtr.Zero;
            stubDesc.NotifyRoutineTable    = IntPtr.Zero; /* notify & notify_flag routine table */
            stubDesc.mFlags          = 0x1;               /* MIDL flag */
            stubDesc.CsRoutineTables = IntPtr.Zero;       /* cs routines */
            stubDesc.ProxyServerInfo = IntPtr.Zero;       /* proxy/server native */
            stubDesc.pExprInfo       = IntPtr.Zero;       /* Reserved5 */
            #endregion
        }