日期:2014-05-20  浏览次数:21078 次

IShellBrowser接口问题
准备用C#写一个类似资源管理器的控件,我参考了

Implementing   IShellBrowser   to   host   IShellView
http://www.codeproject.com/shell/explorer.asp

实现方法简介
1、窗体实现IShellBrowser接口,IShellBrowser.GetWindow返回了这个窗体的句柄
      IShellBrowser中的其他方法只是简单的返回-1;
2、调用IShellFolder.CreateViewObject,得到IShellView指针
3、调用IShellView.CreateViewWindow,创建显示子控件
4、view.UIActivate(SVUIA_ACTIVATE_FOCUS),显示改控件

运行后能在窗体上显示出来一个资源管理器的子窗口,   现在的问题是在这个窗口上操作有60%左右的几率会出现下面的错误
=========================================================================
System.AccessViolationException   was   unhandled
    Message= "Attempted   to   read   or   write   protected   memory.   This   is   often   an   indication   that   other   memory   is   corrupt. "
    Source= "System.Windows.Forms "
    StackTrace:
              at   System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&   msg)
              at   System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32   dwComponentID,   Int32   reason,   Int32   pvLoopData)
              at   System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32   reason,   ApplicationContext   context)
              at   System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32   reason,   ApplicationContext   context)
              at   System.Windows.Forms.Application.Run(Form   mainForm)
              at   TEST.Program.Main()   in   C:\Documents   and   Settings\Chenjian\桌面\TestBrowser\TEST\Program.cs:line   17
              at   System.AppDomain.nExecuteAssembly(Assembly   assembly,   String[]   args)
              at   System.AppDomain.ExecuteAssembly(String   assemblyFile,   Evidence   assemblySecurity,   String[]   args)
              at   Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
              at   System.Threading.ThreadHelper.ThreadStart_Context(Object   state)
              at   System.Threading.ExecutionContext.Run(ExecutionContext   executionContext,   ContextCallback   callback,   Object   state)
              at   System.Threading.ThreadHelper.ThreadStart()

=========================================================================


我怀疑我的IShellBrowser借口定义有问题
=========================================================================
        [StructLayout(LayoutKind.Sequential,   Pack   =   4)]
        public   struct   OLEMENUGROUPWIDTHS
        {
                [MarshalAs(UnmanagedType.ByValArray,   SizeConst   =   6)]
                public   int[]   width;
        }

[ComImport(),   Guid( "000214E2-0000-0000-C000-000000000046 "),   InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]