示例#1
0
        private static IShellItem CreateFolderShellItem(string path)
        {
            IShellItem shellItem;

            path = Path.GetFullPath(path);
            if (FileSystem.DoesPathExist(path))
            {
                shellItem = CreateShellItem(path);
            }
            else
            {
                using (var bindCtxReleaser = new ComReleaser <IBindCtx>(NativeMethods.CreateBindCtx()))
                {
                    IBindCtx bindCtx = bindCtxReleaser.ComObject;
                    bindCtx.RegisterObjectParam
                    (
                        NativeMethods.STR_FILE_SYS_BIND_DATA,
                        CreateFolderIfDoesntExistsFileSystemBindData
                    );

                    shellItem = CreateShellItem(path, bindCtx);
                }
            }

            return(shellItem);
        }
示例#2
0
 void CreateBindCtx(out IBindCtx pbc)
 {
     System.Runtime.InteropServices.ComTypes.BIND_OPTS bo = new System.Runtime.InteropServices.ComTypes.BIND_OPTS() {
         cbStruct = Marshal.SizeOf(typeof(System.Runtime.InteropServices.ComTypes.BIND_OPTS)),
         dwTickCountDeadline = 0,
         grfFlags = 0,
         grfMode = STGM_CREATE
     };
     try {
         PInvoke.CreateBindCtx(0, out pbc);
         pbc.SetBindOptions(ref bo);
         pbc.RegisterObjectParam(STR_FILE_SYS_BIND_DATA, (IFileSystemBindData)this);
     }
     catch {
         pbc = null;
         throw;
     }
 }