本文介绍了有人可以用等效的C ++代码帮助我吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! [ClassInterface(ClassInterfaceType.None),ComVisible(true),Guid(8a194578-81ea-4850-9911-13ba2d71efbd)] public class BrowserHelperObject:IObjectWithSite { private WebBrowser webBrowser; 私有HTMLDocument文档; public static string BHOKEYNAME =Software \\Microsoft \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ public void OnDocumentComplete(object pDisp,ref object URL) { this.document =(HTMLDocument)this.webBrowser.Document; Marshal.ReleaseComObject(this.document); } [ComRegisterFunction] public static void RegisterBHO(Type type) { RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BrowserHelperObject.BHOKEYNAME,RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl); if(registryKey == null) { registryKey = Registry.LocalMachine.CreateSubKey(BrowserHelperObject.BHOKEYNAME); } string guid = type.GUID.ToString(B); RegistryKey ourKey = registryKey.OpenSubKey(guid,true); if(ourKey == null) { ourKey = registryKey.CreateSubKey(guid); } ourKey.SetValue(IEAddinApplied,1,RegistryValueKind.DWord); registryKey.Close(); ourKey.Close(); } [ComUnregisterFunction] public static void UnregisterBHO(类型类型) { RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BrowserHelperObject.BHOKEYNAME,RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl); string guid = type.GUID.ToString(B); if(registryKey!= null) { registryKey.DeleteSubKey(guid,false); } } public int SetSite(对象站点) { if(site!= null) { this.webBrowser = (web浏览器)的网站; this.webBrowser.DocumentComplete + = new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); } else { this.webBrowser.DocumentComplete - = new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); Marshal.ReleaseComObject(this.document); this.webBrowser = null; } 返回0; } public int GetSite(ref Guid guid,out IntPtr ppvSite) { IntPtr punk = Marshal.GetIUnknownForObject(this.webBrowser); int hr = Marshal.QueryInterface(punk,ref guid,out ppvSite); Marshal.Release(朋克); 返回小时; } 我的尝试: 我遇到的问题是 OnDocumentComplete 方法和这部分代码 if(site!= null) { this.webBrowser =(WebBrowser)site; this.webBrowser.DocumentComplete + = new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); } else { this.webBrowser.DocumentComplete - = new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); Marshal.ReleaseComObject(this.document); this.webBrowser = null; } 另外我想在C ++ Project 解决方案 只需将它们添加到项目设置中(链接器 - 输入 - 附加依赖项)或使用 comment(C / C ++)|在一个源文件中指定它们。 Microsoft Docs [ ^ ]: #pragma comment(lib,shdocvw.lib) #pragma comment(lib,mshtml.lib) [ClassInterface(ClassInterfaceType.None), ComVisible(true), Guid("8a194578-81ea-4850-9911-13ba2d71efbd")] public class BrowserHelperObject : IObjectWithSite { private WebBrowser webBrowser; private HTMLDocument document; public static string BHOKEYNAME = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects"; public void OnDocumentComplete(object pDisp, ref object URL) { this.document = (HTMLDocument)this.webBrowser.Document; Marshal.ReleaseComObject(this.document); } [ComRegisterFunction] public static void RegisterBHO(Type type) { RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BrowserHelperObject.BHOKEYNAME, RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl); if (registryKey == null) { registryKey = Registry.LocalMachine.CreateSubKey(BrowserHelperObject.BHOKEYNAME); } string guid = type.GUID.ToString("B"); RegistryKey ourKey = registryKey.OpenSubKey(guid, true); if (ourKey == null) { ourKey = registryKey.CreateSubKey(guid); } ourKey.SetValue("IEAddinApplied", 1, RegistryValueKind.DWord); registryKey.Close(); ourKey.Close(); } [ComUnregisterFunction] public static void UnregisterBHO(Type type) { RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BrowserHelperObject.BHOKEYNAME, RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl); string guid = type.GUID.ToString("B"); if (registryKey != null) { registryKey.DeleteSubKey(guid, false); } } public int SetSite(object site) { if (site != null) { this.webBrowser = (WebBrowser)site; this.webBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); } else { this.webBrowser.DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); Marshal.ReleaseComObject(this.document); this.webBrowser = null; } return 0; } public int GetSite(ref Guid guid, out IntPtr ppvSite) { IntPtr punk = Marshal.GetIUnknownForObject(this.webBrowser); int hr = Marshal.QueryInterface(punk, ref guid, out ppvSite); Marshal.Release(punk); return hr; }What I have tried:The problem I'm facing is with OnDocumentComplete Method and with this part of code if (site != null) { this.webBrowser = (WebBrowser)site; this.webBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); } else { this.webBrowser.DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); Marshal.ReleaseComObject(this.document); this.webBrowser = null; }Also I want to reference shdocvw.dll and mshtml.dll in C++ Project 解决方案 Just add them to the project settings (Linker - Input - Additional Dependencies) or specify them in one source file using comment (C/C++) | Microsoft Docs[^] :#pragma comment(lib, "shdocvw.lib")#pragma comment(lib, "mshtml.lib") 这篇关于有人可以用等效的C ++代码帮助我吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-07 03:01