Exemplo n.º 1
0
 IEnumSTATPROPSTG.Next(
     UInt32 celt,
     STATPROPSTG rgelt,
     out UInt32 pceltFetched
     )
 {
     return(_unsafeEnumSTATPROPSTG.Next(
                celt,
                rgelt,
                out pceltFetched
                ));
 }
Exemplo n.º 2
0
            IEnumSTATPROPSTG.Next(
                UInt32 celt,
                STATPROPSTG rgelt,
                out UInt32 pceltFetched
                )
            {
                SecurityHelper.DemandCompoundFileIOPermission();

                return(_unsafeEnumSTATPROPSTG.Next(
                           celt,
                           rgelt,
                           out pceltFetched
                           ));
            }
Exemplo n.º 3
0
        private void LoadPropertySet(IPropertySetStorage propertySetStorage, Guid fmtid)
        {
            var guid = fmtid;
            var hr   = propertySetStorage.Open(ref guid, STGM.STGM_READ | STGM.STGM_SHARE_EXCLUSIVE, out var propertyStorage);

            if (hr == STG_E_FILENOTFOUND || hr == STG_E_ACCESSDENIED)
            {
                return;
            }

            if (hr != 0)
            {
                throw new Win32Exception((int)hr);
            }

            propertyStorage.Enum(out var es);
            if (es == null)
            {
                return;
            }

            try
            {
                var stg = new STATPROPSTG();
                int fetched;
                do
                {
                    hr = es.Next(1, ref stg, out fetched);
                    if (hr != 0 && hr != 1)
                    {
                        throw new Win32Exception((int)hr);
                    }

                    if (fetched == 1)
                    {
                        var name = GetPropertyName(fmtid, propertyStorage, stg);

                        var propsec = new PROPSPEC[]
                        {
                            new PROPSPEC
                            {
                                ulKind = stg.lpwstrName != null ? PRSPEC.PRSPEC_LPWSTR : PRSPEC.PRSPEC_PROPID,
                            },
                        };

                        var lpwstr = IntPtr.Zero;
                        if (stg.lpwstrName != null)
                        {
                            lpwstr = Marshal.StringToCoTaskMemUni(stg.lpwstrName);
                            propsec[0].union.lpwstr = lpwstr;
                        }
                        else
                        {
                            propsec[0].union.propid = stg.propid;
                        }

                        var vars = new PROPVARIANT[1];
                        vars[0] = new PROPVARIANT();
                        try
                        {
                            hr = propertyStorage.ReadMultiple(1, propsec, vars);
                            if (hr != 0)
                            {
                                throw new Win32Exception((int)hr);
                            }
                        }
                        finally
                        {
                            if (lpwstr != IntPtr.Zero)
                            {
                                Marshal.FreeCoTaskMem(lpwstr);
                            }
                        }

                        object value;
                        try
                        {
                            switch (vars[0].vt)
                            {
                            case VARTYPE.VT_BOOL:
                                value = vars[0].union.boolVal != 0 ? true : false;
                                break;

                            case VARTYPE.VT_BSTR:
                                value = Marshal.PtrToStringUni(vars[0].union.bstrVal);
                                break;

                            case VARTYPE.VT_CY:
                                value = decimal.FromOACurrency(vars[0].union.cyVal);
                                break;

                            case VARTYPE.VT_DATE:
                                value = DateTime.FromOADate(vars[0].union.date);
                                break;

                            case VARTYPE.VT_DECIMAL:
                                var dec = IntPtr.Zero;
                                Marshal.StructureToPtr(vars[0], dec, false);
                                value = Marshal.PtrToStructure(dec, typeof(decimal));
                                break;

                            case VARTYPE.VT_DISPATCH:
                                value = Marshal.GetObjectForIUnknown(vars[0].union.pdispVal);
                                break;

                            case VARTYPE.VT_ERROR:
                            case VARTYPE.VT_HRESULT:
                                value = vars[0].union.scode;
                                break;

                            case VARTYPE.VT_FILETIME:
                                value = DateTime.FromFileTime(vars[0].union.filetime);
                                break;

                            case VARTYPE.VT_I1:
                                value = vars[0].union.cVal;
                                break;

                            case VARTYPE.VT_I2:
                                value = vars[0].union.iVal;
                                break;

                            case VARTYPE.VT_I4:
                                value = vars[0].union.lVal;
                                break;

                            case VARTYPE.VT_I8:
                                value = vars[0].union.hVal;
                                break;

                            case VARTYPE.VT_INT:
                                value = vars[0].union.intVal;
                                break;

                            case VARTYPE.VT_LPSTR:
                                value = Marshal.PtrToStringAnsi(vars[0].union.pszVal);
                                break;

                            case VARTYPE.VT_LPWSTR:
                                value = Marshal.PtrToStringUni(vars[0].union.pwszVal);
                                break;

                            case VARTYPE.VT_R4:
                                value = vars[0].union.fltVal;
                                break;

                            case VARTYPE.VT_R8:
                                value = vars[0].union.dblVal;
                                break;

                            case VARTYPE.VT_UI1:
                                value = vars[0].union.bVal;
                                break;

                            case VARTYPE.VT_UI2:
                                value = vars[0].union.uiVal;
                                break;

                            case VARTYPE.VT_UI4:
                                value = vars[0].union.ulVal;
                                break;

                            case VARTYPE.VT_UI8:
                                value = vars[0].union.uhVal;
                                break;

                            case VARTYPE.VT_UINT:
                                value = vars[0].union.uintVal;
                                break;

                            case VARTYPE.VT_UNKNOWN:
                                value = Marshal.GetObjectForIUnknown(vars[0].union.punkVal);
                                break;

                            default:
                                value = null;
                                break;
                            }
                        }
                        finally
                        {
                            PropVariantClear(ref vars[0]);
                        }

                        var property = new CompoundProperty(fmtid, name, stg.propid)
                        {
                            Value   = value,
                            Changed = false,
                        };
                        Properties.InternalAdd(property);
                    }
                }while (fetched == 1);
            }
            finally
            {
                Marshal.ReleaseComObject(es);
            }
        }
Exemplo n.º 4
0
        private static string GetPropertyName(Guid fmtid, IPropertyStorage propertyStorage, STATPROPSTG stg)
        {
            if (!string.IsNullOrEmpty(stg.lpwstrName))
            {
                return(stg.lpwstrName);
            }

            var propids = new uint[1];

            propids[0] = stg.propid;
            var names = new string[1];

            names[0] = null;
            var hr = propertyStorage.ReadPropertyNames(1, propids, names);

            if (hr == 0)
            {
                return(names[0]);
            }

            foreach (var kp in CompoundProperty.KnownProperties)
            {
                if (kp.FormatId == fmtid && kp.Id == stg.propid)
                {
                    return(kp.Name);
                }
            }
            return(null);
        }
Exemplo n.º 5
0
            IEnumSTATPROPSTG.Next(
                UInt32 celt,
                STATPROPSTG rgelt,
                out UInt32 pceltFetched
                )
            {
                SecurityHelper.DemandCompoundFileIOPermission();

                return _unsafeEnumSTATPROPSTG.Next(
                    celt,
                    rgelt,
                    out pceltFetched
                    );
            }
 internal Property(STATPROPSTG statpropstg, object value)
 {
     _statpropstg = statpropstg;
     _value = value;
 }
Exemplo n.º 7
0
        public static SonyCamera[] FindCameras()
        {
            Dictionary <string, SonyCamera> cameras = new Dictionary <string, SonyCamera>();

            if (deviceManager == null)
            {
                deviceManager = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("a1f4e726-8cf1-11d1-bf92-0060081ed811"))) as IWiaDevMgr;
            }
            if (deviceManager == null)
            {
                return(new SonyCamera[0]);
            }

            IEnumWIA_DEV_INFO deviceInfo;

            if (Success(deviceManager.EnumDeviceInfo(Defs.WIA_DEVINFO_ENUM_LOCAL, out deviceInfo)) &&
                Success(deviceInfo.Reset()))
            {
                IWiaPropertyStorage propertyStorage;
                uint numFetchedStorage = 0;
                while (Success(deviceInfo.Next(1, out propertyStorage, ref numFetchedStorage)) && numFetchedStorage > 0)
                {
                    IEnumSTATPROPSTG propsEnumerator;
                    if (Success(propertyStorage.Enum(out propsEnumerator)) &&
                        Success(propsEnumerator.Reset()))
                    {
                        bool   knownName         = false;
                        bool   knownManufacturer = false;
                        string deviceId          = null;
                        string deviceName        = null;

                        uint          numFetchedProps;
                        STATPROPSTG[] props = new STATPROPSTG[1];
                        while (Success(propsEnumerator.Next(1, props, out numFetchedProps)) && numFetchedProps > 0)
                        {
                            for (int i = 0; i < numFetchedProps; i++)
                            {
                                STATPROPSTG prop = props[i];
                                switch (prop.lpwstrName)
                                {
                                case "Manufacturer":
                                    switch (GetPropertyValue(propertyStorage, prop.propid))
                                    {
                                    case "Sony Corporation":
                                        knownManufacturer = true;
                                        break;
                                    }
                                    break;

                                case "Name":
                                    deviceName = GetPropertyValue(propertyStorage, prop.propid);
                                    if (SonyCamera.SupportedCameras.Contains(deviceName))
                                    {
                                        knownName = true;
                                    }
                                    break;

                                case "Unique Device ID":
                                    deviceId = GetPropertyValue(propertyStorage, prop.propid);
                                    break;
                                }
                                //Console.WriteLine(prop.lpwstrName + " " + GetPropertyValue(propertyStorage, prop.propid));
                            }
                        }

                        if (!string.IsNullOrEmpty(deviceId) && knownManufacturer && knownName)
                        {
                            cameras[deviceId] = new SonyCamera(deviceId, deviceName);
                        }
                    }
                }
            }

            return(cameras.Values.ToArray());
        }