Ejemplo n.º 1
0
        private static IMalloc GetSHMalloc()
        {
            var ppMalloc = new IMalloc[1];

            SHGetMalloc(ppMalloc);
            return(ppMalloc[0]);
        }
Ejemplo n.º 2
0
        public static unsafe ItemIdList Create(IMalloc m, params byte[][] data)
        {
            //if (m == null)
            {
                //	throw new ArgumentNullException("m");
            }

            int len = ItemId.HeaderSize;             // terminator

            foreach (byte[] item in data)
            {
                len += item.Length + ItemId.HeaderSize;
            }

            IntPtr p = (m == null) ? Marshal.AllocCoTaskMem(len) : m.Alloc(len);

            if (p == IntPtr.Zero)
            {
                throw new OutOfMemoryException("Shell failed to allocate ITEMIDLIST");
            }

            IntPtr workingP = p;

            foreach (byte[] item in data)
            {
                *((ushort *)workingP) = checked ((ushort)(item.Length + ItemId.HeaderSize));
                workingP = (IntPtr)((int)workingP + ItemId.HeaderSize);
                Marshal.Copy(item, 0, workingP, item.Length);
                workingP = (IntPtr)((int)workingP + item.Length);
            }

            *((ushort *)workingP) = 0;

            return(new ItemIdList(p));
        }
Ejemplo n.º 3
0
            public static IMalloc SHGetMalloc()
            {
                var ppMalloc = new IMalloc[1];

                SHGetMalloc(ppMalloc);
                return(ppMalloc[0]);
            }
Ejemplo n.º 4
0
        protected override bool RunDialog(System.IntPtr hwndOwner)
        {
            string m_DisplayName = "";
            string sDisplay;
            IntPtr ptrRet;

            // Get IMalloc interface
            WindowsAPI.SHGetMalloc(out ptrRet);

            Type    mallocType = System.Type.GetType("IMalloc");
            IMalloc pMalloc    = ( IMalloc )Marshal.GetTypedObjectForIUnknown(ptrRet, mallocType);
            IntPtr  pidlRoot   = IntPtr.Zero;

            BROWSEINFO bi = new BROWSEINFO();

            bi.hwndOwner      = hwndOwner;
            bi.pidlRoot       = pidlRoot; //TODO: Root`s selection
            bi.pszDisplayName = new string( ' ', 256 );
            bi.lpszTitle      = Title;
            bi.ulFlags        = GetFlagsValue();
            bi.lParam         = 0;
            bi.lpfn           = new WindowsAPI.BrowseCallbackProc(this.HookProc);

            IntPtr pidlSelected;

            pidlSelected  = WindowsAPI.SHBrowseForFolder(ref bi);
            m_DisplayName = bi.pszDisplayName.ToString();

            // if display name is whitespace then return FAIL
            if (m_DisplayName.Trim() == string.Empty)
            {
                return(false);
            }

            IShellFolder isf = GetDesktopFolder();

            STRRET ptrDisplayName;

            isf.GetDisplayNameOf(pidlSelected,
                                 (uint)SHGNO.SHGDN_NORMAL | (uint)SHGNO.SHGDN_FORPARSING,
                                 out ptrDisplayName);

            WindowsAPI.StrRetToBSTR(ref ptrDisplayName, pidlRoot, out sDisplay);
            m_sFullName = sDisplay;

            if (pidlRoot != IntPtr.Zero)
            {
                pMalloc.Free(pidlRoot);
            }

            if (pidlSelected != IntPtr.Zero)
            {
                pMalloc.Free(pidlSelected);
            }

            Marshal.ReleaseComObject(isf);
            Marshal.ReleaseComObject(pMalloc);

            return(true);
        }
Ejemplo n.º 5
0
        static IMalloc GetSHMalloc()
        {
            var ppMalloc = new IMalloc[1];

            Shell32.SHGetMalloc(ppMalloc);
            return(ppMalloc[0]);
        }
Ejemplo n.º 6
0
        private static IMalloc GetSHMalloc()
        {
            IMalloc[] malloc = new IMalloc[1];

            Shell32.SHGetMalloc(malloc);

            return(malloc[0]);
        }
Ejemplo n.º 7
0
        internal Malloc(IMalloc m)
        {
            if (m == null)
            {
                throw new ArgumentNullException();
            }

            this.m = m;
        }
Ejemplo n.º 8
0
        private bool RunDialogDownlevel(IntPtr owner)
        {
            IntPtr rootItemIdList   = IntPtr.Zero;
            IntPtr resultItemIdList = IntPtr.Zero;

            if (NativeMethods.SHGetSpecialFolderLocation(owner, RootFolder, ref rootItemIdList) != 0)
            {
                if (NativeMethods.SHGetSpecialFolderLocation(owner, 0, ref rootItemIdList) != 0)
                {
                    throw new InvalidOperationException("Unable to retrieve the root folder.");
                }
            }
            try
            {
                NativeMethods.BROWSEINFO info = new NativeMethods.BROWSEINFO
                {
                    hwndOwner      = owner,
                    lpfn           = new NativeMethods.BrowseCallbackProc(BrowseCallbackProc),
                    lpszTitle      = Description,
                    pidlRoot       = rootItemIdList,
                    pszDisplayName = new string('\0', 260),
                    ulFlags        = NativeMethods.BrowseInfoFlags.NewDialogStyle | NativeMethods.BrowseInfoFlags.ReturnOnlyFsDirs
                };
                if (!ShowNewFolderButton)
                {
                    info.ulFlags |= NativeMethods.BrowseInfoFlags.NoNewFolderButton;
                }
                resultItemIdList = NativeMethods.SHBrowseForFolder(ref info);
                if (resultItemIdList != IntPtr.Zero)
                {
                    StringBuilder path = new StringBuilder(260);
                    NativeMethods.SHGetPathFromIDList(resultItemIdList, path);
                    SelectedPath = path.ToString();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            finally
            {
                if (rootItemIdList != null)
                {
                    IMalloc malloc = NativeMethods.SHGetMalloc();
                    malloc.Free(rootItemIdList);
                    Marshal.ReleaseComObject(malloc);
                }
                if (resultItemIdList != null)
                {
                    Marshal.FreeCoTaskMem(resultItemIdList);
                }
            }
        }
Ejemplo n.º 9
0
        public static IMalloc GetMalloc()
        {
            IntPtr ptrRet;

            ShellApi.SHGetMalloc(out ptrRet);

            Object  obj     = Marshal.GetTypedObjectForIUnknown(ptrRet, GetMallocType());
            IMalloc imalloc = (IMalloc)obj;

            return(imalloc);
        }
Ejemplo n.º 10
0
        //Helper routine to free memory allocated using shells malloc object
        internal static void SHMemFree(IntPtr ptr)
        {
            object shmalloc = null;

            if (SHGetMalloc(out shmalloc) == 0)
            {
                IMalloc malloc = (IMalloc)shmalloc;

                (malloc).Free(ptr);
            }
        }
Ejemplo n.º 11
0
 public void Dispose()
 {
     if (!disposed)
     {
         if (alloc != null)
         {
             Marshal.ReleaseComObject(alloc);
         }
         alloc = null;
         if (_thumbNail != null)
         {
             _thumbNail.Dispose();
         }
         disposed = true;
     }
 }
        public void Dispose()
        {
            if (!this.disposed)
            {
                if (this.alloc != null)
                {
                    Marshal.ReleaseComObject(this.alloc);
                }
                this.alloc = null;

                if (this.ThumbNail != null)
                {
                    this.ThumbNail.Dispose();
                }

                this.disposed = true;
            }
        }
        public void Dispose()
        {
            if (!disposed)
            {
                if (alloc != null)
                {
                    DirectShowUtil.ReleaseComObject(alloc);
                }
                alloc = null;

                if (thumbNail != null)
                {
                    thumbNail.Dispose();
                }

                disposed = true;
            }
        }
Ejemplo n.º 14
0
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            if (_alloc != null)
            {
                Marshal.ReleaseComObject(_alloc);
            }
            _alloc = null;
            if (ThumbNail != null)
            {
                ThumbNail.Dispose();
            }
            _disposed = true;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 指定した特殊フォルダのアイコンイメージを取得する
        /// </summary>
        /// <param name="targetFolder">アイコンイメージ取得対象の特殊フォルダを指すenum</param>
        /// <param name="size">
        /// 取得するアイコンのサイズ
        /// </param>
        /// <returns>取得されたアイコンをIconクラスで返す</returns>
        public static Icon GetSpecialFolderAssociatedImage(SpecialFolderID targetFolder, EIconSize size)
        {
            uint flags = Shell32Wrapper.SHGFI_ICON | Shell32Wrapper.SHGFI_PIDL;

            if (size == EIconSize.Small)
            {
                flags |= Shell32Wrapper.SHGFI_SMALLICON;
            }
            SHFILEINFO fileInfo = new SHFILEINFO();
            IntPtr     pidlRoot = IntPtr.Zero;

            try
            {
                // 特殊フォルダのpIDLを取得
                Shell32Wrapper.SHGetSpecialFolderLocation(IntPtr.Zero, (int)targetFolder, out pidlRoot);

                // アイコンの取得
                Shell32Wrapper.SHGetFileInfo(pidlRoot, 0, ref fileInfo, (uint)Marshal.SizeOf(fileInfo), flags);
                if (fileInfo.hIcon == IntPtr.Zero)
                {
                    return(null);
                }
                else
                {
                    var unmanagedIcon = Icon.FromHandle(fileInfo.hIcon);
                    return(new Icon(unmanagedIcon, unmanagedIcon.Size)); // unmanagedIconは破棄されるのでManagedで新しく作成する
                }
            }
            finally
            {
                if (fileInfo.hIcon != IntPtr.Zero)
                {
                    User32Wrapper.DestroyIcon(fileInfo.hIcon);
                }

                // pidlを解放する。
                if (pidlRoot != IntPtr.Zero)
                {
                    IMalloc malloc = GetSHMalloc();
                    malloc.Free(pidlRoot);
                }
            }
        }
Ejemplo n.º 16
0
        public void Dispose()
        {
            if (!this.disposed)
            {
                if (this.alloc != null)
                {
                    Marshal.ReleaseComObject(this.alloc);
                }

                this.alloc = null;

                if (this.thumbNail != null)
                {
                    this.thumbNail.Dispose();
                }

                this.disposed = true;
            }
        }
Ejemplo n.º 17
0
        public Bitmap LoadThumbnailFromImageFactory(string filename, Size requestedSize, bool onlyThumbnail)
        {
            if (!System.IO.Directory.Exists(filename) && !System.IO.File.Exists(filename))
            {
                return(null);
            }

            Bitmap bm1     = null;
            IntPtr hbitmap = IntPtr.Zero;
            SIZE   sz      = new SIZE(requestedSize.Width, requestedSize.Height);

            IShellFolder           desktop   = null;
            IntPtr                 pidlMain  = IntPtr.Zero;
            IShellItem             shellItem = null;
            IShellItemImageFactory ppsiShellItemImageFactory = null;

            try
            {
                Shell32.SHGetDesktopFolder(ref desktop);

                int cParsed   = 0;
                int pdwAttrib = 0;
                desktop.ParseDisplayName(IntPtr.Zero, IntPtr.Zero, filename, out cParsed, out pidlMain, out pdwAttrib);

                //Shell32.SHCreateItemFromIDList(pidlMain, uuidIShellItem, out shellItem);
                Shell32.SHCreateShellItem(IntPtr.Zero, null, pidlMain, out shellItem);

                ppsiShellItemImageFactory = (IShellItemImageFactory)shellItem;
                if (onlyThumbnail)
                {
                    ppsiShellItemImageFactory.GetImage(sz, SIIGBF.SIIGBF_BIGGERSIZEOK | SIIGBF.SIIGBF_THUMBNAILONLY, out hbitmap);
                }
                else
                {
                    ppsiShellItemImageFactory.GetImage(sz, SIIGBF.SIIGBF_BIGGERSIZEOK, out hbitmap);
                }

                bm1 = GetBitmapFromHbitmap(hbitmap);
            }
            catch (InvalidCastException)
            {
                Debug.Write("    Did not support IShellItemImageFactory\r\n");
            }
            catch (Exception e)
            {
                Debug.Write("    Exception extracting image from IShellItemImageFactory: " + e.Message + "\r\n");
            }
            finally
            {
                if (ppsiShellItemImageFactory != null)
                {
                    Marshal.ReleaseComObject(ppsiShellItemImageFactory);
                    ppsiShellItemImageFactory = null;
                }
                if (shellItem != null)
                {
                    Marshal.ReleaseComObject(shellItem);
                    shellItem = null;
                }
                if (pidlMain != IntPtr.Zero)
                {
                    Allocator.Free(pidlMain);
                    pidlMain = IntPtr.Zero;
                }
                if (desktop != null)
                {
                    Marshal.ReleaseComObject(desktop);
                    desktop = null;
                }
                if (_allocator != null)
                {
                    Marshal.ReleaseComObject(_allocator);
                    _allocator = null;
                }
            }

            return(bm1);
        }
Ejemplo n.º 18
0
 public static extern int CoGetMalloc(int dwReserved, out IMalloc pMalloc);
Ejemplo n.º 19
0
 public static IMalloc GetSHMalloc()
 {
     var ppMalloc = new IMalloc[1];
     SHGetMalloc(ppMalloc);
     return ppMalloc[0];
 }
Ejemplo n.º 20
0
 internal Malloc(IntPtr pMalloc)
 {
     m = (IMalloc)Marshal.GetObjectForIUnknown(pMalloc);
 }
Ejemplo n.º 21
0
 public static int SHGetMalloc(out IMalloc ppMalloc)
 {
     NotImplemented(MethodBase.GetCurrentMethod());
     ppMalloc = null;
     return(0);
 }
Ejemplo n.º 22
0
� � public static extern int SHGetMalloc(ref IMalloc pMalloc);
Ejemplo n.º 23
0
 public static IMalloc GetSHMalloc()
 {
     IMalloc[] ppMalloc = new IMalloc[1];
     SHGetMalloc(ppMalloc);
     return(ppMalloc[0]);
 }
Ejemplo n.º 24
0
        public void Dispose()
        {
            if (_disposed) return;

            if (_alloc != null)
            {
                Marshal.ReleaseComObject(_alloc);
            }
            _alloc = null;
            if (ThumbNail != null)
            {
                ThumbNail.Dispose();
            }
            _disposed = true;
        }
 public static int SHGetMalloc(out IMalloc[] ppMalloc)
 {
 }
Ejemplo n.º 26
0
        /// <summary></summary>
        protected override bool RunDialog(IntPtr hWndOwner)
        {
            IntPtr zero = IntPtr.Zero;
            bool   flag = false;

            Win32.SHGetSpecialFolderLocation(hWndOwner, (int)this.mRootFolder, ref zero);
            if (zero == IntPtr.Zero)
            {
                Win32.SHGetSpecialFolderLocation(hWndOwner, 0, ref zero);
                if (zero == IntPtr.Zero)
                {
                    throw new InvalidOperationException("No Root Folder.");
                }
            }

            BrowseInfoFlag flags = BrowseInfoFlag.NewUserInterface;

            if (!this.mShowNewFolderButton)
            {
                flags |= BrowseInfoFlag.NoNewFolderButton;
            }
            if (this.mIncludeFiles)
            {
                flags |= BrowseInfoFlag.BrowseEverything;
            }

            if (Control.CheckForIllegalCrossThreadCalls && (Application.OleRequired() != ApartmentState.STA))
            {
                throw new ThreadStateException("Thread Must Be STA.");
            }
            IntPtr pidl    = IntPtr.Zero;
            IntPtr hglobal = IntPtr.Zero;
            IntPtr pszPath = IntPtr.Zero;

            try
            {
                this.mCurrentCallback = new BrowseCallbackProc(this.FolderBrowserDialog_BrowseCallbackProc);
                hglobal = Marshal.AllocHGlobal((int)(260 * Marshal.SystemDefaultCharSize));
                pszPath = Marshal.AllocHGlobal((int)(260 * Marshal.SystemDefaultCharSize));

                BROWSEINFO lpbi = new BROWSEINFO();
                lpbi.pidlRoot       = zero;
                lpbi.hwndOwner      = hWndOwner;
                lpbi.pszDisplayName = hglobal;
                lpbi.lpszTitle      = this.mDescriptionText;
                lpbi.ulFlags        = (int)flags;
                lpbi.lpfn           = this.mCurrentCallback;
                lpbi.lParam         = IntPtr.Zero;
                lpbi.iImage         = 0;

                pidl = Win32.SHBrowseForFolder(lpbi);
                if (pidl != IntPtr.Zero)
                {
                    Win32.SHGetPathFromIDList(pidl, pszPath);
                    this.mSelectedPathNeedsCheck = true;
                    this.mSelectedPath           = Marshal.PtrToStringAuto(pszPath);
                    flag = true;
                }
            }
            finally
            {
                IMalloc sHMalloc = GetSHMalloc();
                sHMalloc.Free(zero);
                if (pidl != IntPtr.Zero)
                {
                    sHMalloc.Free(pidl);
                }
                if (pszPath != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(pszPath);
                }
                if (hglobal != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(hglobal);
                }
                this.mCurrentCallback = null;
            }
            return(flag);
        }
Ejemplo n.º 27
0
 internal extern static int SHGetMalloc(ref IMalloc ppMalloc);
Ejemplo n.º 28
0
 private static IMalloc GetSHMalloc()
 {
     IMalloc[] ppMalloc = new IMalloc[1];
     Win32.SHGetMalloc(ppMalloc);
     return(ppMalloc[0]);
 }
Ejemplo n.º 29
0
        public Bitmap LoadImageFromExtractIcon(string filename)
        {
            if (!System.IO.Directory.Exists(filename) && !System.IO.File.Exists(filename))
            {
                return(null);
            }

            Bitmap bm1     = null;
            IntPtr hbitmap = IntPtr.Zero;

            IShellFolder desktop     = null;
            IntPtr       pidlParent  = IntPtr.Zero;
            IShellFolder shellFolder = null;
            IUnknown     iunk        = null;
            IExtractIcon extractIcon = null;

            try
            {
                Debug.Write("Trying IExtractIcon\r\n");

                Shell32.SHGetDesktopFolder(ref desktop);

                int    cParsed   = 0;
                int    pdwAttrib = 0;
                string filePath  = filename;
                if (System.IO.File.Exists(filename))
                {
                    filePath = System.IO.Path.GetDirectoryName(filename);
                }
                desktop.ParseDisplayName(IntPtr.Zero, IntPtr.Zero, filePath, out cParsed, out pidlParent, out pdwAttrib);

                Guid uuidShellFolder = new Guid("000214E6-0000-0000-C000-000000000046");
                desktop.BindToObject(pidlParent, IntPtr.Zero, ref uuidShellFolder, out shellFolder);

                Guid uuidExtractIcon = new Guid("000214eb-0000-0000-c000-000000000046");
                iunk = GetUIObject(shellFolder, filename, uuidExtractIcon);

                if (iunk == null)
                {
                    Debug.Write("    IExtractIcon not supported\r\n");
                    return(null);
                }

                int hres = 0;
                extractIcon = (IExtractIcon)iunk;
                StringBuilder location  = new StringBuilder(260, 260);
                int           iconIndex = 0;
                GILFLAGS2     flags     = GILFLAGS2.GIL_None;
                hres = extractIcon.GetIconLocation(0, location, location.Capacity, out iconIndex, out flags);
                IntPtr iconLarge = IntPtr.Zero;
                IntPtr iconSmall = IntPtr.Zero;
                uint   iconSize  = (16 | (48 << 16));
                hres = extractIcon.Extract(location, iconIndex, out iconLarge, out iconSmall, iconSize);
                Icon ico = Icon.FromHandle(iconLarge);
                bm1 = ico.ToBitmap();
            }
            catch (Exception e)
            {
                Debug.Write("    Exception extracting image from IExtractIcon: " + e.Message + "\r\n");
            }
            finally
            {
                if (extractIcon != null)
                {
                    Marshal.ReleaseComObject(extractIcon);
                    extractIcon = null;
                }
                if (iunk != null)
                {
                    Marshal.ReleaseComObject(iunk);
                    iunk = null;
                }
                if (shellFolder != null)
                {
                    Marshal.ReleaseComObject(shellFolder);
                    shellFolder = null;
                }
                if (pidlParent != IntPtr.Zero)
                {
                    Allocator.Free(pidlParent);
                    pidlParent = IntPtr.Zero;
                }
                if (desktop != null)
                {
                    Marshal.ReleaseComObject(desktop);
                    desktop = null;
                }
                if (_allocator != null)
                {
                    Marshal.ReleaseComObject(_allocator);
                    _allocator = null;
                }
            }
            return(bm1);
        }
Ejemplo n.º 30
0
        public Bitmap LoadThumbnailFromExtractImage(string filename, Size requestedSize)
        {
            if (!System.IO.Directory.Exists(filename) && !System.IO.File.Exists(filename))
            {
                return(null);
            }

            Bitmap bm1     = null;
            IntPtr hbitmap = IntPtr.Zero;
            SIZE   sz      = new SIZE(requestedSize.Width, requestedSize.Height);

            IShellFolder  desktop      = null;
            IntPtr        pidlParent   = IntPtr.Zero;
            IShellFolder  shellFolder  = null;
            IUnknown      iunk         = null;
            IExtractImage extractImage = null;

            try
            {
                Debug.Write("Trying IExtractImage\r\n");

                Shell32.SHGetDesktopFolder(ref desktop);

                int    cParsed   = 0;
                int    pdwAttrib = 0;
                string filePath  = filename;
                if (System.IO.File.Exists(filename))
                {
                    filePath = System.IO.Path.GetDirectoryName(filename);
                }
                desktop.ParseDisplayName(IntPtr.Zero, IntPtr.Zero, filePath, out cParsed, out pidlParent, out pdwAttrib);

                Guid uuidShellFolder = new Guid("000214E6-0000-0000-C000-000000000046");
                desktop.BindToObject(pidlParent, IntPtr.Zero, ref uuidShellFolder, out shellFolder);

                Guid uuidExtractImage = new Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1");
                iunk = GetUIObject(shellFolder, filename, uuidExtractImage);

                if (iunk == null)
                {
                    Debug.Write("    IExtractImage not supported\r\n");
                    return(null);
                }

                extractImage = (IExtractImage)iunk;
                StringBuilder location = new StringBuilder(260, 260);
                int           priority = 0;
                EIEIFLAG      flags    = EIEIFLAG.IEIFLAG_ORIGSIZE;
                int           uFlags   = (int)flags;
                extractImage.GetLocation(location, location.Capacity, ref priority, ref sz, 32, ref uFlags);
                extractImage.Extract(out hbitmap);
                bm1 = GetBitmapFromHbitmap(hbitmap);
            }
            catch (Exception e)
            {
                Debug.Write("    Exception extracting image from IExtractImage: " + e.Message + "\r\n");
            }
            finally
            {
                if (extractImage != null)
                {
                    Marshal.ReleaseComObject(extractImage);
                    extractImage = null;
                }
                if (iunk != null)
                {
                    Marshal.ReleaseComObject(iunk);
                    iunk = null;
                }
                if (shellFolder != null)
                {
                    Marshal.ReleaseComObject(shellFolder);
                    shellFolder = null;
                }
                if (pidlParent != IntPtr.Zero)
                {
                    Allocator.Free(pidlParent);
                    pidlParent = IntPtr.Zero;
                }
                if (desktop != null)
                {
                    Marshal.ReleaseComObject(desktop);
                    desktop = null;
                }
                if (_allocator != null)
                {
                    Marshal.ReleaseComObject(_allocator);
                    _allocator = null;
                }
            }
            return(bm1);
        }
Ejemplo n.º 31
0
    public void Dispose()
    {
      if (!disposed)
      {
        if (alloc != null)
        {
          Marshal.ReleaseComObject(alloc);
        }
        alloc = null;

        if (thumbNail != null)
        {
          thumbNail.SafeDispose();
        }

        disposed = true;
      }
    }
Ejemplo n.º 32
0
 internal static extern int SHGetMalloc(ref IMalloc malloc);
Ejemplo n.º 33
0
			internal extern static int SHGetMalloc(out IMalloc ppMalloc);
Ejemplo n.º 34
0
 private static extern int SHGetMalloc( out IMalloc ppMalloc );
Ejemplo n.º 35
0
 internal extern static int SHGetMalloc(out IMalloc ppMalloc);
Ejemplo n.º 36
0
 public static void FreeMalloc(IMalloc malloc)
 {
     Marshal.ReleaseComObject(malloc);
 }
 private static IMalloc GetSHMalloc()
 {
     IMalloc[] array = new IMalloc[1];
     SHGetMalloc(array);
     return array[0];
 }
 public static extern int SHGetMalloc(out IMalloc ppMalloc);
Ejemplo n.º 39
0
 public static IMalloc GetShMalloc()
 {
     IMalloc[] ppMalloc = new IMalloc[1];
     ShellGetMalloc(ppMalloc);
     return ppMalloc[0];
 }
Ejemplo n.º 40
0
        protected override bool RunDialog(IntPtr hwndOwner)
        {
            bool result = false;

            IntPtr pidlRoot     = IntPtr.Zero,
                   pszPath      = IntPtr.Zero,
                   pidlSelected = IntPtr.Zero;

            SelectedPath = string.Empty;

            try
            {
                SHGetFolderLocation(hwndOwner, (int)Environment.SpecialFolder.Desktop, IntPtr.Zero, 0, out pidlRoot);

                var browseInfo = new BROWSEINFO
                {
                    HwndOwner   = hwndOwner,
                    Root        = pidlRoot,
                    DisplayName = new string(' ', 256),
                    Title       = Title,
                    Flags       = (uint)_dialogOptions,
                    LParam      = 0,
                    Callback    = HookProc
                };

                // Show dialog
                pidlSelected = SHBrowseForFolder(ref browseInfo);

                if (pidlSelected != IntPtr.Zero)
                {
                    result = true;

                    pszPath = Marshal.AllocHGlobal(260 * Marshal.SystemDefaultCharSize);
                    SHGetPathFromIDList(pidlSelected, pszPath);

                    SelectedPath = Marshal.PtrToStringAuto(pszPath);
                }
            }
            finally // release all unmanaged resources
            {
                IMalloc malloc = GetSHMalloc();

                if (pidlRoot != IntPtr.Zero)
                {
                    malloc.Free(pidlRoot);
                }

                if (pidlSelected != IntPtr.Zero)
                {
                    malloc.Free(pidlSelected);
                }

                if (pszPath != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(pszPath);
                }

                Marshal.ReleaseComObject(malloc);
            }

            return(result);
        }
Ejemplo n.º 41
0
 static IMalloc GetSHMalloc()
 {
     IMalloc[] ppMalloc = new IMalloc[1];
     SHGetMalloc(ppMalloc);
     return ppMalloc[0];
 }
Ejemplo n.º 42
0
		public void Dispose()
		{
			if (!disposed)
			{
				if (alloc != null)
				{
					DirectShowUtil.ReleaseComObject(alloc);
				}
				alloc = null;

				if (thumbNail != null)
				{
					thumbNail.Dispose();
				}

				disposed = true;
			}
		}
Ejemplo n.º 43
0
        /// <summary>
        /// When overridden in a derived class, specifies a common dialog box.
        /// </summary>
        /// <param name="hwndOwner">A value that represents the window handle of the owner window for the common dialog box.</param>
        /// <returns>
        /// true if the dialog box was successfully run; otherwise, false.
        /// </returns>
        protected override bool RunDialog(IntPtr hwndOwner)
        {
            IntPtr zero = IntPtr.Zero;
            bool   flag = false;

            SHGetSpecialFolderLocation(hwndOwner, (int)rootFolder, ref zero);
            if (zero == IntPtr.Zero)
            {
                SHGetSpecialFolderLocation(hwndOwner, 0, ref zero);
                if (zero == IntPtr.Zero)
                {
                    throw new InvalidOperationException(
                              "Folder Browser Dialog: no root folder");
                }
            }

            //int flags = 0x40;
            //if (!showNewFolderButton) flags += 0x200;

            if (Control.CheckForIllegalCrossThreadCalls && (Application.OleRequired() != ApartmentState.STA))
            {
                throw new ThreadStateException("Debugging exception only: Thread must be STA");
            }

            IntPtr pidl    = IntPtr.Zero;
            IntPtr hglobal = IntPtr.Zero;
            IntPtr pszPath = IntPtr.Zero;

            try
            {
                BROWSEINFO lpbi = new BROWSEINFO();
                hglobal             = Marshal.AllocHGlobal((int)(260 * Marshal.SystemDefaultCharSize));
                pszPath             = Marshal.AllocHGlobal((int)(260 * Marshal.SystemDefaultCharSize));
                callback            = new BrowseCallbackProc(FolderBrowserDialog_BrowseCallbackProc);
                lpbi.pidlRoot       = zero;
                lpbi.hwndOwner      = hwndOwner;
                lpbi.pszDisplayName = hglobal;
                lpbi.lpszTitle      = descriptionText;
                lpbi.ulFlags        = (int)flags;
                lpbi.lpfn           = callback;
                lpbi.lParam         = IntPtr.Zero;
                lpbi.iImage         = 0;
                pidl = SHBrowseForFolder(lpbi);
                if (pidl != IntPtr.Zero)
                {
                    SHGetPathFromIDList(pidl, pszPath);
                    selectedPathNeedsCheck = true;
                    selectedPath           = Marshal.PtrToStringAuto(pszPath);
                    flag = true;
                }
            }
            finally
            {
                IMalloc sHMalloc = GetSHMalloc();
                sHMalloc.Free(zero);
                if (pidl != IntPtr.Zero)
                {
                    sHMalloc.Free(pidl);
                }
                if (pszPath != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(pszPath);
                }
                if (hglobal != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(hglobal);
                }

                callback = null;
            }
            return(flag);
        }
Ejemplo n.º 44
0
 internal static extern int SHGetMalloc(out IMalloc ppMalloc);
 internal static extern int SHGetMalloc(out IMalloc ppMalloc);
Ejemplo n.º 46
0
 internal static extern int SHGetMalloc(ref IMalloc ppMalloc);
Ejemplo n.º 47
0
 public static extern int SHGetMalloc(out IMalloc ppMalloc);
 static IMalloc GetSHMalloc()
 {
     var ppMalloc = new IMalloc[1];
     Shell32.SHGetMalloc(ppMalloc);
     return ppMalloc[0];
 }