Imports SolidEdgeFramework
Imports System.Runtime.InteropServices
Public Class Form1
Private objApplication As SolidEdgeFramework.Application
Private WithEvents objAppWindowEvents As SolidEdgeFramework.ISEApplicationWindowEvents_Event
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
OleMessageFilter.Register()
' Connect to a running instance of Solid Edge
objApplication = Marshal.GetActiveObject("SolidEdge.Application")
' Get a reference to the application events
objAppWindowEvents = objApplication.ApplicationV8AfterDocumentOpenEvent
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If Not (objAppWindowEvents Is Nothing) Then
Marshal.ReleaseComObject(objAppWindowEvents)
objAppWindowEvents = Nothing
End If
If Not (objApplication Is Nothing) Then
Marshal.ReleaseComObject(objApplication)
objApplication = Nothing
End If
OleMessageFilter.Revoke()
End Sub
End Class