Ejemplo n.º 1
0
        public int GetData(ref FormatEtc pFormatEtc, ref StgMedium pMedium)
        {
            ushort cf = (ushort)pFormatEtc.Format;

            if (cf == s_cfMultiSelect)
            {
                BinaryWriter writer = CreateBinaryWriter();

                // MMC expects a SMMCObjectTypes struct. Don't bother creating the struct and serializing it,
                // just write the fields:
                // 1) count of GUIDs.
                // 2) array of node GUIDs.

                writer.Write(1);
                writer.Write(m_node.Guid.ToByteArray());

                // Allocate HGlobal memory.

                pMedium.Global = Marshal.AllocHGlobal(new IntPtr(writer.BaseStream.Length));
                Debug.Assert(pMedium.Global != IntPtr.Zero, "pMedium.Global != IntPtr.Zero");

                // Write the memory stream to the HGlobal memory.

                try
                {
                    WriteMemoryStreamToHGlobal(writer, pMedium.Global);
                }
                catch
                {
                    // An error occurred, so free the memory we allocated.

                    Marshal.FreeHGlobal(pMedium.Global);
                    throw;
                }

                return(Constants.Win32.HResults.S_OK);
            }
            else
            {
                return(Constants.Win32.HResults.E_NOTIMPL);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Send data to MMC in a stream depending on what is requested
        /// </summary>
        public void GetDataHere(ref FormatEtc pFormatEtc, ref StgMedium pMedium)
        {
            const char unknownString = '\0';             // Send this value if we don't know what string to send.

            try
            {
                ushort cf = (ushort)pFormatEtc.Format;

                BinaryWriter writer = CreateBinaryWriter();

                if (cf == s_displayName)
                {
                    writer.Write(m_node.DisplayName.ToCharArray());
                }
                else if (cf == s_SZNodeType)
                {
                    writer.Write(unknownString);
                }
                else if (cf == s_nodeType)
                {
                    writer.Write(m_node.Guid.ToByteArray());
                }
                else if (cf == s_snapinClsid)
                {
                    writer.Write(m_node.Snapin.Guid.ToByteArray());
                }

                // Write the memory stream to the HGlobal memory.

                WriteMemoryStreamToHGlobal(writer, pMedium.Global);
            }
            catch (System.Exception e)
            {
                new ExceptionDialog(e, "The following exception has occurred in the snap-in:").ShowDialog(m_node.Snapin);
            }
        }