Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void DisplayVideoCaptureDevicePropertyPage(IntPtr handle)
- {
- IBaseFilter device = CreateFilter(DirectShowLib.FilterCategory.VideoInputDevice, "myDeviceName");
- DisplayPropertyPage(device, handle);
- }
- #endregion
- #region private methods
- private IBaseFilter CreateFilter(Guid category, string friendlyname)
- {
- object source = null;
- Guid iid = typeof(IBaseFilter).GUID;
- foreach (DsDevice device in DsDevice.GetDevicesOfCat(category))
- {
- if (device.Name.CompareTo(friendlyname) == 0)
- {
- device.Mon.BindToObject(null, null, ref iid, out source);
- break;
- }
- }
- return (IBaseFilter)source;
- }
- private void DisplayPropertyPage(IBaseFilter dev, IntPtr handle)
- {
- //Get the ISpecifyPropertyPages for the filter
- ISpecifyPropertyPages pProp = dev as ISpecifyPropertyPages;
- int hr = 0;
- if (pProp == null)
- {
- //If the filter doesn't implement ISpecifyPropertyPages, try displaying IAMVfwCompressDialogs instead!
- IAMVfwCompressDialogs compressDialog = dev as IAMVfwCompressDialogs;
- if (compressDialog != null)
- {
- hr = compressDialog.ShowDialog(VfwCompressDialogs.Config, IntPtr.Zero);
- DsError.ThrowExceptionForHR(hr);
- }
- return;
- }
- //Get the name of the filter from the FilterInfo struct
- DirectShowLib.FilterInfo filterInfo;
- hr = dev.QueryFilterInfo(out filterInfo);
- DsError.ThrowExceptionForHR(hr);
- // Get the propertypages from the property bag
- DsCAUUID caGUID;
- hr = pProp.GetPages(out caGUID);
- DsError.ThrowExceptionForHR(hr);
- // Check for property pages on the output pin
- IPin pPin = DsFindPin.ByDirection(dev, PinDirection.Output, 0);
- ISpecifyPropertyPages pProp2 = pPin as ISpecifyPropertyPages;
- if (pProp2 != null)
- {
- DsCAUUID caGUID2;
- hr = pProp2.GetPages(out caGUID2);
- DsError.ThrowExceptionForHR(hr);
- if (caGUID2.cElems > 0)
- {
- int soGuid = Marshal.SizeOf(typeof(Guid));
- // Create a new buffer to hold all the GUIDs
- IntPtr p1 = Marshal.AllocCoTaskMem((caGUID.cElems + caGUID2.cElems) * soGuid);
- // Copy over the pages from the Filter
- for (int x = 0; x < caGUID.cElems * soGuid; x++)
- {
- Marshal.WriteByte(p1, x, Marshal.ReadByte(caGUID.pElems, x));
- }
- // Add the pages from the pin
- for (int x = 0; x < caGUID2.cElems * soGuid; x++)
- {
- Marshal.WriteByte(p1, x + (caGUID.cElems * soGuid), Marshal.ReadByte(caGUID2.pElems, x));
- }
- // Release the old memory
- Marshal.FreeCoTaskMem(caGUID.pElems);
- Marshal.FreeCoTaskMem(caGUID2.pElems);
- // Reset caGUID to include both
- caGUID.pElems = p1;
- caGUID.cElems += caGUID2.cElems;
- }
- }
- // Create and display the OlePropertyFrame
- object oDevice = (object)dev;
- hr = OleCreatePropertyFrame(handle, 0, 0, filterInfo.achName, 1, ref oDevice, caGUID.cElems, caGUID.pElems, 0, 0, IntPtr.Zero);
- DsError.ThrowExceptionForHR(hr);
- // Release COM objects
- Marshal.FreeCoTaskMem(caGUID.pElems);
- Marshal.ReleaseComObject(pProp);
- if (filterInfo.pGraph != null)
- {
- Marshal.ReleaseComObject(filterInfo.pGraph);
- }
- }
- [DllImport(@"oleaut32.dll")]
- public static extern int OleCreatePropertyFrame(
- IntPtr hwndOwner,
- int x,
- int y,
- [MarshalAs(UnmanagedType.LPWStr)] string lpszCaption,
- int cObjects,
- [MarshalAs(UnmanagedType.Interface, ArraySubType = UnmanagedType.IUnknown)]
- ref object ppUnk,
- int cPages,
- IntPtr lpPageClsID,
- int lcid,
- int dwReserved,
- IntPtr lpvReserved);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement