如何用C语言实现不同系统间的互操作性?

2026-04-29 02:412阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计446个文字,预计阅读时间需要2分钟。

如何用C语言实现不同系统间的互操作性?

我利用ActiveX接口创建了一个.NET用户控件。它运行良好。现在,我希望能够从ActiveX接口的属性包中读取和写入。我该怎么做?最简单的方法是使用客户端脚本将参数值传递给ActiveX。例如: xmlns=...

我用ActiveX接口创建了一个.NET用户控件.它运作良好.

现在,我希望能够从ActiveX接口的属性包中读取和写入.

如何用C语言实现不同系统间的互操作性?

我该怎么做?

最简单的方法是使用客户端脚本将参数值传递给ActiveX

<html xmlns="www.w3.org/1999/xhtml" > <head runat="server"> <title></title> <script language="javascript"> function Rundata(file) { var winCtrl = document.getElementById("YourActiveX"); winCtrl.Option1 = file; winCtrl.WriteToFile(); } </script> </head> <body> <form id="form1" runat="server"> <div> <object id="YourActiveX" classid="clsid:6b1bdf22-1c1d-774e-cd9d-1d1aaf7fd88f" width="300px" height="200px"> <param name="Option1" value="valuetoRetrieve1" /> </object> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Button runat="server" ID="Button1" OnClientClick="javascript:Rundata('valuetoRetrieve2');" /> </div> </form> </body> </html>

如果您无法使用客户端脚本,则可以尝试这种方式:

假设你想要读取一个参数,例如:

<object id="YourActiveX" classid="clsid:6b1bdf22-1c1d-774e-cd9d-1d1aaf7fd88f" width="300px" height="200px"> <param name="option1" value="valuetoRetrieve" /> </object>

您需要在项目中公开以下COM接口:

[ComImport] [Guid("55272A00-42CB-11CE-8135-00AA004BB851")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IPropertyBag { void Write([InAttribute] string propName, [InAttribute] ref Object ptrVar); void Read([InAttribute] string propName, out Object ptrVar, int errorLog); } [ComImport] [Guid("37D84F60-42CB-11CE-8135-00AA004BB851")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IPersistPropertyBag { [PreserveSig] void InitNew(); [PreserveSig] void Load(IPropertyBag propertyBag, int errorLog); [PreserveSig] void Save(IPropertyBag propertyBag, [InAttribute] bool clearDirty, [InAttribute] bool saveAllProperties); [PreserveSig] void GetClassID(out Guid classID); }

您的activeX控件应该实现这些接口.您需要实现一种方法:

void IPersistPropertyBag.Load(IPropertyBag propertyBag, int errorLog) { object value; propertyBag.Read("option1", out value, errorLog); string parameter = (string)value; }

瞧!参数应该等于“valuetoRetrieve”

标签:ActiveXProper

本文共计446个文字,预计阅读时间需要2分钟。

如何用C语言实现不同系统间的互操作性?

我利用ActiveX接口创建了一个.NET用户控件。它运行良好。现在,我希望能够从ActiveX接口的属性包中读取和写入。我该怎么做?最简单的方法是使用客户端脚本将参数值传递给ActiveX。例如: xmlns=...

我用ActiveX接口创建了一个.NET用户控件.它运作良好.

现在,我希望能够从ActiveX接口的属性包中读取和写入.

如何用C语言实现不同系统间的互操作性?

我该怎么做?

最简单的方法是使用客户端脚本将参数值传递给ActiveX

<html xmlns="www.w3.org/1999/xhtml" > <head runat="server"> <title></title> <script language="javascript"> function Rundata(file) { var winCtrl = document.getElementById("YourActiveX"); winCtrl.Option1 = file; winCtrl.WriteToFile(); } </script> </head> <body> <form id="form1" runat="server"> <div> <object id="YourActiveX" classid="clsid:6b1bdf22-1c1d-774e-cd9d-1d1aaf7fd88f" width="300px" height="200px"> <param name="Option1" value="valuetoRetrieve1" /> </object> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Button runat="server" ID="Button1" OnClientClick="javascript:Rundata('valuetoRetrieve2');" /> </div> </form> </body> </html>

如果您无法使用客户端脚本,则可以尝试这种方式:

假设你想要读取一个参数,例如:

<object id="YourActiveX" classid="clsid:6b1bdf22-1c1d-774e-cd9d-1d1aaf7fd88f" width="300px" height="200px"> <param name="option1" value="valuetoRetrieve" /> </object>

您需要在项目中公开以下COM接口:

[ComImport] [Guid("55272A00-42CB-11CE-8135-00AA004BB851")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IPropertyBag { void Write([InAttribute] string propName, [InAttribute] ref Object ptrVar); void Read([InAttribute] string propName, out Object ptrVar, int errorLog); } [ComImport] [Guid("37D84F60-42CB-11CE-8135-00AA004BB851")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IPersistPropertyBag { [PreserveSig] void InitNew(); [PreserveSig] void Load(IPropertyBag propertyBag, int errorLog); [PreserveSig] void Save(IPropertyBag propertyBag, [InAttribute] bool clearDirty, [InAttribute] bool saveAllProperties); [PreserveSig] void GetClassID(out Guid classID); }

您的activeX控件应该实现这些接口.您需要实现一种方法:

void IPersistPropertyBag.Load(IPropertyBag propertyBag, int errorLog) { object value; propertyBag.Read("option1", out value, errorLog); string parameter = (string)value; }

瞧!参数应该等于“valuetoRetrieve”

标签:ActiveXProper