EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 5803|回复: 71
打印 上一主题 下一主题

用程序启动Inventor失败的原因和解决方法

[复制链接]

1514

主题

7465

帖子

1万

积分

admin

Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10

积分
12404

社区QQ达人

跳转到指定楼层
楼主
发表于 2014-1-14 10:22:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

有时候用 "CreateObject("Inventor.Application")"来启动Inventor会失败,但是随后再执行这个命令时Inventor又会成功启动,这是怎么回事?下面是我们的技术专家的解释以及解决办法:

Inventor starts up very slowly when none of its DLLs are in the system's file cache. Restarting the computer clears the file cache so that the first instantiation of Inventor takes a very long time to initialize. When Inventor is started via automation, it must call CoRegisterClassObject within two minutes of the process starting, or else COM assumes the process failed to start and raises a CO_E_SERVER_EXEC_FAILURE 0x80080005 exception in the calling program. This has the effect of killing the inventor.exe process providing the caller with a useless pointer/reference and potentially an unhandled exception. Subsequent attempts to start inventor.exe will use the DLLs in the file cache and the process generally starts much more quickly and does not time out


You can pre-load the libraries by running and exiting Inventor prior to running a utility program. This process is generally needed only one time after each computer restart; subsequent use of the utility programs will reuse the cached libraries loaded earlier in the Windows session. If you have multiple releases of Inventor installed, be sure to run and exit the Inventor release that matches the version number of the utility program you would like to run. Running and exiting a specific release of Inventor will set a value in the Windows registry so the utility programs can detect which installation is active.


An alternative solution is to launch Inventor as a local COM server: in this case the timeout can be up to three minutes and it is generally enough to allow the process to run. The following VB.NET sample shows how to accomplish this.


解决办法如下:


Imports Microsoft.Win32


Public Class clsLocalSrv


    Public Shared Function StartAsLocalServer(ByVal ProgId As String, _


                                               ByVal nMilliSeconds As Integer, _


                                               ByRef oApplication As Object) As Boolean



        Dim enUS As New Globalization.CultureInfo("en-US")


        Threading.Thread.CurrentThread.CurrentCulture = enUS



        Dim commandName As String = ""


        Dim arguments As String = ""



        Dim oRegKey As Microsoft.Win32.RegistryKey, oCls As Microsoft.Win32.RegistryKey


        Dim oVal As Object, sName As String, oDir As Object


        Try


            oCls = Registry.ClassesRoot


            oRegKey = oCls.OpenSubKey(ProgId + "//CLSID", False)


            oVal = oRegKey.GetValue("", Nothing)


            oRegKey = oCls.OpenSubKey("CLSID//" & oVal & "//LocalServer32", False)


            oDir = oRegKey.GetValue("", Nothing)



            oRegKey.Close()


            oCls.Close()


            sName = oDir



            Dim nIndex As Long


            nIndex = Microsoft.VisualBasic.InStrRev(sName, "/automation", , CompareMethod.Text)


            commandName = Microsoft.VisualBasic.Left(sName, nIndex - 1)


            arguments = Microsoft.VisualBasic.Right(sName, (sName.Length() - nIndex + 1))


        Catch ex As Exception


            MsgBox(ex.Message)


            Exit Function


        End Try


        ' Start the program


        Dim oProcess As Process = Process.Start(commandName, arguments)


        ' Loop until run out of time or get the process's object.


        Dim Start, Finish As Double


        Start = Microsoft.VisualBasic.DateAndTime.Timer


        Finish = Start + (nMilliSeconds / 1000)



        Do While Microsoft.VisualBasic.DateAndTime.Timer < Finish


            Try


                oApplication = System.Runtime.InteropServices.Marshal.GetActiveObject(ProgId)


                If Not oApplication Is Nothing Then


                    Return True


                End If


            Catch ex As Exception


                ' Keep trying until run out of time


            End Try


            System.Threading.Thread.Sleep(100)


        Loop


        ' Failed to get the running object, stop the process


        oProcess.Kill()

        Return False

    End Function

End Class


在你的程序里调用上面的方法:


If clsLocalSrv.StartAsLocalServer("Inventor.Application", 120000, m_inventorApp) = True Then


   '...

End If


如果你用的不是VB.NET,而是VB,那么替换的办法也许是用定时器(Timer)来替代上面的Thread,并用GetObject来替换上面的System.Runtime.InteropServices.Marshal.GetActiveObject来做类似的工作。

文章来源:http://blog.csdn.net/barbarahan

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 转播转播 分享分享 分享淘帖 支持支持 反对反对
工作时间:工作日的9:00-12:00/13:30-18:00,节假日不在线,请勿留言

14

主题

2892

帖子

2085

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
2085
推荐
发表于 2016-3-31 09:42:14 | 只看该作者
o(* ̄︶ ̄*)o 路过。。。~

31

主题

1019

帖子

1897

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1897
推荐
发表于 2014-3-7 11:58:29 | 只看该作者
路过!!!
不发表意见……

26

主题

722

帖子

-2205

积分

乞丐

积分
-2205
推荐
发表于 2014-2-18 12:19:40 | 只看该作者
路过!!!
不发表意见……

28

主题

763

帖子

1425

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1425
5F
发表于 2014-2-18 12:15:43 | 只看该作者
路过!!!
不发表意见……

6

主题

869

帖子

1359

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1359
7F
发表于 2014-2-18 12:29:43 | 只看该作者
(*^__^*) 嘻嘻……

13

主题

840

帖子

1580

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1580
9F
发表于 2014-2-19 15:00:22 | 只看该作者
路过!!!
不发表意见……
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|EaBIM网 ( 苏ICP备2020058923号-1  苏公网安备32011502011255号

GMT+8, 2024-11-23 11:47

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表