繁体   English   中英

C#中的功能等效于Vb6中的CreateObject

[英]What's function in C# equivalent to CreateObject in Vb6

VB6代码:

Dim oApplication As SiebelHTMLApplication
Dim oBS As SiebelService
Dim oPSIn As SiebelPropertySet
Dim oPSOut As SiebelPropertySet
Dim sActivityId As String
Set oApplication = CreateObject("Siebel.Desktop_Integration_Application.1")
If oApplication.IsReady Then
    Set oBS = oApplication.GetService("Workflow Process Manager")

C#代码:-

SiebelHTMLApplication sApp = new SiebelHTMLApplication();
SiebelService sService = new SiebelService();
SiebelPropertySet sPsIn = new SiebelPropertySet();
SiebelPropertySet sPsOut = new SiebelPropertySet();

然后我尝试将VB代码的第6行转换为c#:

object instance = Activator.CreateInstance(Type.GetTypeFromProgID("Siebel.Desktop_Integration_Application.1"));

但我无法将实例对象转换为SiebelHTMLApplication:

sApp = (SiebelHTMLApplication)instance;

谁能建议我一个设置方法呢?

Type.GetTypeFromProgID创建com实例,但不创建Type对象。

尝试

object instance = Activator.CreateInstance(Type.GetType("Siebel.Desktop_Integration_Application, AssemblyName")); 

您必须将AssemblyName替换为包含Siebel.Desktop_Integration_Application描述的Assembly名称。

您始终可以导入Microsoft.VisualBasic,然后仅使用CreateObject

感谢Vasiliy,最后我通过从对象更改为类型得到了解决方案。 然后就可以了!

var siebelDeskType = Activator.CreateInstance(Type.GetTypeFromProgID("Siebel.Desktop_Integration_Application.1"));
            sApp = (SiebelHTMLApplication)siebelDeskType;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM