gpt4 book ai didi

c# - 如何从ActiveX或DLL调用Javascript函数

转载 作者:行者123 更新时间:2023-11-28 03:41:16 25 4
gpt4 key购买 nike

我发现了类似的问题how to call java script function from activex or dll in c#但这并不能为我提供解决方案
http://msdn.microsoft.com/en-us/library/ms171712.aspx
从托管在Internet Explorer中的用户控件访问DOM
创建用户控件类的自定义派生类。有关详细信息,请参见如何:编写复合控件。
将以下代码放入用户控件的加载事件处理程序中:

    HtmlDocument doc = null;

private void UserControl1_Load(object sender, EventArgs e)
{
if (this.Site != null)
{
doc = (HtmlDocument)this.Site.GetService(typeof(HtmlDocument));
}
}

很遗憾,我仍然无法在类中获取DOM对象。我已尝试查看在这个站点中获取的内容,因此我将其放在了一个消息框中
   MessageBox.Show(this.Site.ToString());

我觉得很奇怪
System.Windows.Forms.Control+AxSourcingSite

请帮帮我。。

最佳答案

下面是一个从active x调用js函数的示例:

Type typeIOleObject = "activity control object".GetType().GetInterface("IOleObject", true);  
object oleClientSite = typeIOleObject.InvokeMember("GetClientSite",
BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.Public,
null,
control,
null);

IOleClientSite oleClientSiteoleClientSite2 = oleClientSite as IOleClientSite;
IOleContainer pObj;
oleClientSite2.GetContainer(out pObj);

//get Script set from page
IHTMLDocument2 pDoc2 = (IHTMLDocument2)pObj;
IHTMLWindow2 win2 = (IHTMLWindow2)pDoc2.parentWindow;
//string code="";
win2.execScript(code, "javascript");
if (returnType == null)
[ComImport, Guid("00000118-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleClientSite
{
void SaveObject();
void GetMoniker(uint dwAssign, uint dwWhichMoniker, object ppmk);
void GetContainer(out IOleContainer ppContainer);
void ShowObject();
void OnShowWindow(bool fShow);
void RequestNewObjectLayout();
}
[ComImport, Guid("0000011B-0000-0000-C000-000000000046"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleContainer
{
void EnumObjects([In, MarshalAs(UnmanagedType.U4)] int grfFlags,
[Out, MarshalAs(UnmanagedType.LPArray)] object[] ppenum);
void ParseDisplayName([In, MarshalAs(UnmanagedType.Interface)] object pbc,
[In, MarshalAs(UnmanagedType.BStr)] string pszDisplayName,
[Out, MarshalAs(UnmanagedType.LPArray)] int[] pchEaten,
[Out, MarshalAs(UnmanagedType.LPArray)] object[] ppmkOut);
void LockContainer([In, MarshalAs(UnmanagedType.I4)] int fLock);
}

关于c# - 如何从ActiveX或DLL调用Javascript函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10816749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com