使用ActiveX在C# [英] Use ActiveX in C#

查看:123
本文介绍了使用ActiveX在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JavaScript这样的代码:

I have a javascript code like this:

  o = new ActiveXObject("ASDFsome.Application");
  utilites = WScript.CreateObject("ASDF.Utilites.UTF.Converter")
  utilites.Convert(outFile, xmlProp.xml)

现在我要重写它的C#代码。我应该如何使用的ActiveXObject在网?

Now I want to rewrite it in C# code. How should I use ActiveXObject in Net?

推荐答案

这是不小的一部分,为什么的动态的关键字加入到C#版本4:

This is in no small part why the dynamic keyword was added to C# version 4:

dynamic utilites = Activator.CreateInstance(Type.GetTypeFromProgID("ASDF.Utilites.UTF.Converter"));
utilites.Convert(outFile, xmlProp.xml);

如果你被困在随后使用VB.NET类库的早期版本是最好的办法。它直接支持在你的脚本代码使用的CreateObject()函数。

If you're stuck on an earlier version then using a VB.NET class library is the best approach. It directly supports the CreateObject() function as used in your scripting code.

最后但并非最不重要的,不像你已经使用脚本语言,C#和VB。 .NET支持早期绑定。这开始通过向类型库的引用,项目+添加引用并使用COM选项卡或浏览选项卡中选择那些包含类型库的.tlb或.dll文件。您可能没有之一,如果该组件的设计是永远只从后期绑定脚本语言使用。我们不能以其他方式帮助你找到正确的类型库,供应商或作者就知道了。

Last but not least, unlike the scripting language you've been using, both C# and VB.NET support early binding. That starts by adding a reference to the type library, Project + Add Reference and use either the COM tab or the Browse tab to pick the .tlb or .dll file that contains the type library. You might not have one if the component was designed to be only ever used from late binding scripting languages. We can't otherwise help you find the proper type library, the vendor or author would know.

真的最后但并非最不重要的,这闻起来像一个知道一个实用程序如何读取UTF-8编码的XML文件。这已经在System.Xml命名空间.NET真的很好的支持。

Really last but not least, this smells like a utility that knows how to read a utf-8 encoded XML file. That's already really well supported in .NET with the System.Xml namespace.

这篇关于使用ActiveX在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆