问题描述
C#新手,想通过WebBrowser给IE做个壳。尝试通过IDocHostUIHandler.GetOptionKeypath()覆盖注册表设定的位置。从HKEY_CURRENT_USER\SOFTWARE\Microsoft\WindowsCurrentVersion\InternetSettings变为HKEY_CURRENT_USER\SOFTWARE\MyApp但是没有作用,浏览器还是从IE的注册表里读设置。麻烦大家给看看[return:MarshalAs(UnmanagedType.I4)][PreserveSig]intGetOptionKeyPath([Out]IntPtrpbstrKey,[In,MarshalAs(UnmanagedType.U4)]intdw);intNativeMethods.IDocHostUIHandler.GetOptionKeyPath(IntPtrpbstrKey,intdw){Debug.Print("IDocHostUIHandler.GetOptionKeyPath");stringkeypath="Software\MyApp"+Char.MinValue;//nullterminator+'';char[]arr=keypath.ToCharArray();pbstrKey=NativeMethods.CoTaskMemAlloc(newIntPtr(keypath.Length*sizeof(char));for(intctr=0;ctr<keypath.Length;ctr++){IntPtrnewptr=IntPtr.Add(pbstrKey,ctr*sizeof(char));Marshal.WriteInt16(newptr,arr[ctr]);//Console.Write("{0}",(char)Marshal.ReadIntPtr(newptr));}return0;//S_OK}
解决方案
解决方案二:
没有人知道吗,自己顶一下。试了好久都不行。目前只找到了C++的例子HRESULTCBrowserHost::GetOptionKeyPath(LPOLESTR*pchKey,DWORDdwReserved){HRESULThr;WCHAR*szKey=L"Software\MyCompany\MyApp";//cbLengthisthelengthofszKeyinbytes.size_tcbLength;hr=StringCbLengthW(szKey,1280,&cbLength);//TODO:Adderrorhandlingcodehere.if(pchKey){*pchKey=(LPOLESTR)CoTaskMemAlloc(cbLength+sizeof(WCHAR));if(*pchKey)hr=StringCbCopyW(*pchKey,cbLength+sizeof(WCHAR),szKey);}elsehr=E_INVALIDARG;returnhr;}