简体   繁体   English

无法使用C#创建Activex对象

[英]can not create activex object using C#

I am deploying a C# application on client machine. 我正在客户端计算机上部署C#应用程序。 The Application need to access code from another program, so it can scrap text from the screen of another application. 该应用程序需要访问另一个程序的代码,因此它可以从另一个应用程序的屏幕上抓取文本。 It is running fine on the development machine but on the client machine it is throwing an error "ActiveX Component cannot create Object" this is where i am getting the error from! 它在开发计算机上运行良好,但在客户端计算机上抛出错误“ ActiveX组件无法创建对象”,这是我从中得到错误的地方!

    private ExtraSession objExtraSession;
    private ExtraSessions objExtraSessions;
    private ExtraScreen objExtraScreen;
    private ExtraArea objExtraArea;
    private ExtraSystem objExtraSystem;
    protected void sessionInitializer()
    {
        try
        {
            objExtraSystem = (ExtraSystem) Microsoft.VisualBasic.Interaction.CreateObject("Extra.system");

            if (objExtraSystem == null)
            {
                MessageBox.Show("Could not create system");
                return;
            }
            objExtraSessions = objExtraSystem.Sessions;

            if (objExtraSessions == null)
            {
                MessageBox.Show("Could not create sessions");
                return;
            }
            if (!System.IO.File.Exists("C:\\Users\\" + userid + "\\Documents\\Attachmate\\EXTRA!\\Sessions\\SAS.edp"))
            {
                MessageBox.Show("File does not exist");
                return;
            }

            objExtraSession = (ExtraSession) Microsoft.VisualBasic.Interaction.GetObject("C:\\Users\\"+ userid + "\\Documents\\Attachmate\\EXTRA!\\Sessions\\SAS.edp");

            if (objExtraSession == null)
            {
                MessageBox.Show("Could not create session");
                return;
            }

            if (objExtraSession.Visible == 0)
            {
                objExtraSession.Visible = 1;
            }

            objExtraScreen = objExtraSession.Screen;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.StackTrace, "Failed to initialize Attachmate sessions");
        }
    }

The error is generated from objExtraSession = (ExtraSession) Microsoft.VisualBasic.Interaction.GetObject("C:\\Users\\"+ userid + "\\Documents\\Attachmate\\EXTRA!\\Sessions\\SAS.edp"); 从objExtraSession =(ExtraSession)Microsoft.VisualBasic.Interaction.GetObject(“ C:\\ Users \\” + userid +“ \\ Documents \\ Attachmate \\ EXTRA!\\ Sessions \\ SAS.edp”)生成错误;

Am I missing some step. 我错过了一些步骤吗? Please help me out. 请帮帮我。 Thanks in advance. 提前致谢。

The most likely explanation is that your development machine has the ActiveX control installed, but the client machine does not. 最可能的解释是您的开发计算机已安装ActiveX控件,而客户端计算机未安装。 Read the deployment documentation for the control and do what is says is required to deploy to the client machine. 阅读控件的部署文档,并执行将其部署到客户端计算机所需的操作。

感谢您的所有答复... GetObject方法正在创建一个未注册其activex组件的对象...我通过找到相应的* .ocx文件并在该文件上调用Regsvr32来解决了此问题...

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

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