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

萧闫子 发表于 2014-1-14 10:22:23

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

有时候用 "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 FunctionEnd 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

妮可 发表于 2016-3-31 09:42:14

o(* ̄︶ ̄*)o 路过。。。~

月の月 发表于 2014-3-7 11:58:29

路过!!!
不发表意见……

烈火ivk 发表于 2014-2-18 12:19:40

路过!!!
不发表意见……

一梦千寻 发表于 2014-2-18 12:15:43

路过!!!
不发表意见……

AK47 发表于 2014-2-18 12:22:18

顶!!!!!!!!!!

大头佬 发表于 2014-2-18 12:29:43

(*^__^*) 嘻嘻……

江枫 发表于 2014-2-18 13:31:35

顶!!!!!!!!!!

leowave 发表于 2014-2-19 15:00:22

路过!!!
不发表意见……

烈火ivk 发表于 2014-2-21 14:46:10

顶!!!!!!!!!!

飞天舞 发表于 2014-2-22 20:17:31

顶!!!!!!!!!!

车奴 发表于 2014-2-25 10:37:41

顶!!!!!!!!!!!!!!!!!!!!!!!!!

欧宝 发表于 2014-2-25 10:40:30

顶!!!!!!!!!!

中华! 发表于 2014-2-28 11:53:39

顶!!!!!!!!!!

乖乖仔 发表于 2014-3-5 15:37:51

顶起来…………

矮矮 发表于 2014-3-5 15:40:30

顶!!!!!!!!!!
页: [1] 2 3 4 5
查看完整版本: 用程序启动Inventor失败的原因和解决方法