Exemple #1
0
        public static void TestRCWNonRoundTripUnique()
        {
            Console.WriteLine("Testing CCW uniqueness process");
            ComWrappers wrapper = new SimpleComWrapper();
            var         target  = new ComObject();
            var         comPtr  = wrapper.GetOrCreateComInterfaceForObject(target, CreateComInterfaceFlags.None);
            var         ifPtr   = wrapper.GetOrCreateObjectForComInstance(comPtr, CreateObjectFlags.UniqueInstance);

            if (ifPtr == target)
            {
                throw new Exception("RCW should not round-trip for unique instances");
            }
        }
Exemple #2
0
        public static void TestRCWCached()
        {
            Console.WriteLine("Testing RCW cache process");
            ComWrappers wrapper = new SimpleComWrapper();
            var         target  = new ComObject();
            var         comPtr  = wrapper.GetOrCreateComInterfaceForObject(target, CreateComInterfaceFlags.None);
            var         comPtr2 = wrapper.GetOrCreateComInterfaceForObject(target, CreateComInterfaceFlags.None);

            if (comPtr != comPtr2)
            {
                throw new Exception("RCW should round-trip");
            }
        }
        private static List<OpticalDriveInfo> GetOpticalDriveInfo()
        {
            var drives = new List<OpticalDriveInfo>();

            var discMasterType = Type.GetTypeFromProgID(
                PROGID_IMAPI2_DISC_MASTER2, true);

            var discRecorderType = Type.GetTypeFromProgID(
                PROGID_IMAPI2_DISC_RECORDER2, true);


            var flags = BindingFlags.Instance | BindingFlags.Public;

            using (var discMaster = new SimpleComWrapper(discMasterType))
            {
                foreach (var identifier in ((IEnumerable) discMaster.ComInstance))
                {
                    using (var discRecorder = new SimpleComWrapper(discRecorderType))
                    {

                        // oh dear god, hurry up c# 4.0!
                        discRecorderType.InvokeMember(
                            "InitializeDiscRecorder",
                            flags | BindingFlags.InvokeMethod,
                            null, discRecorder.ComInstance, new[] {identifier});

                        string mountPoint = String.Empty;
                        foreach (var volumePathName in discRecorder.GetPropertyValue<IEnumerable>("VolumePathNames"))
                        {
                            mountPoint = (string)volumePathName;
                            break;
                        }

                        drives.Add(new OpticalDriveInfo
                                       {
                                           MountPoint = mountPoint,
                                           VendorId = discRecorder.GetPropertyValue<string>("VendorId"),
                                           ProductId = discRecorder.GetPropertyValue<string>("ProductId"),
                                           ProductRevision = discRecorder.GetPropertyValue<string>("ProductRevision"),
                                           SupportedProfiles =
                                               GetSupportedProfiles(
                                               discRecorder.GetPropertyValue<IEnumerable>("SupportedProfiles"))
                                       });
                    }
                }
            }

            return drives;
        }
        private static List <OpticalDriveInfo> GetOpticalDriveInfo()
        {
            var drives = new List <OpticalDriveInfo>();

            var discMasterType = Type.GetTypeFromProgID(
                PROGID_IMAPI2_DISC_MASTER2, true);

            var discRecorderType = Type.GetTypeFromProgID(
                PROGID_IMAPI2_DISC_RECORDER2, true);


            var flags = BindingFlags.Instance | BindingFlags.Public;

            using (var discMaster = new SimpleComWrapper(discMasterType))
            {
                foreach (var identifier in ((IEnumerable)discMaster.ComInstance))
                {
                    using (var discRecorder = new SimpleComWrapper(discRecorderType))
                    {
                        // oh dear god, hurry up c# 4.0!
                        discRecorderType.InvokeMember(
                            "InitializeDiscRecorder",
                            flags | BindingFlags.InvokeMethod,
                            null, discRecorder.ComInstance, new[] { identifier });

                        string mountPoint = String.Empty;
                        foreach (var volumePathName in discRecorder.GetPropertyValue <IEnumerable>("VolumePathNames"))
                        {
                            mountPoint = (string)volumePathName;
                            break;
                        }

                        drives.Add(new OpticalDriveInfo
                        {
                            MountPoint        = mountPoint,
                            VendorId          = discRecorder.GetPropertyValue <string>("VendorId"),
                            ProductId         = discRecorder.GetPropertyValue <string>("ProductId"),
                            ProductRevision   = discRecorder.GetPropertyValue <string>("ProductRevision"),
                            SupportedProfiles =
                                GetSupportedProfiles(
                                    discRecorder.GetPropertyValue <IEnumerable>("SupportedProfiles"))
                        });
                    }
                }
            }

            return(drives);
        }