slw7310 发表于 2015-9-23 19:18:15

64位系统下vs2008如何 捕捉到ROT中CAD运行的进程?

请各位大侠帮忙:

' 启动某个版本的AutoCAD
    Public Function LaunchAutoCAD(ByVal progId As String, ByVal exePath As String, ByVal parentWndHandle As IntPtr) As AcadApplication
      Try
            ' 使用System.Diagnostics命名空间的类,实现AutoCAD的带参数启动
            Dim psi As New ProcessStartInfo(exePath, "")
            Dim pr As Process = Process.Start(psi)
            ' 等待AutoCAD准备好,貌似不用等CAD启动完成
            pr.WaitForInputIdle()
                While pr.MainWindowHandle = IntPtr.Zero
                System.Threading.Thread.Sleep(2000)
                pr.Refresh()
            End While
            m_appWin = pr.MainWindowHandle


            ' 使用COM方法连接到进程
            ' 无限循环直到捕捉到AutoCAD进程
            ' 如果不检查超时,或者让用户结束操作,就会有点危险
            Dim acadApp As AcadApplication = Nothing
            While acadApp Is Nothing
                Try
                  acadApp = DirectCast(System.Runtime.InteropServices.Marshal.GetActiveObject(progId), AcadApplication)
                  Thread.Sleep(1000)
                Catch ex As Exception
                   ' 让应用程序检查自身的消息队列,以防用于取消操作或者退出
                  Console.WriteLine(ex.Message)
                  Application.DoEvents()
                End Try
            End While

            ' Put it into this form
            SetParent(m_appWin, parentWndHandle)
            ' Remove border and whatnot
            SetWindowLong(m_appWin, GWL_STYLE, WS_VISIBLE)
            acadApp.Visible = True
          Return acadApp
      Catch ex As Exception
            MessageBox.Show("Cannot create or attach to AutoCAD object: " + ex.Message)
            Return Nothing
      End Try
    End Function

以上代码是 启动一个CAD ,并检查并捕捉到 CAD进程。
在vs2008XP32系统中调试时是可以捕捉到并且能够正确返回acadApp的,
但在VS2008 win? 64位系统中调试时却不可以捕捉到,返回acadApp=Nothing,从而陷入 While 的死循环,直到出错!

高人帮忙,如何解决呢!?
盼回复!!
谢谢各位!!



slw7310 发表于 2015-9-24 12:31:24

别让帖子沉了! 请各位帮忙!!
页: [1]
查看完整版本: 64位系统下vs2008如何 捕捉到ROT中CAD运行的进程?