Option Infer On
Imports System
Imports System.Runtime.InteropServices
Imports System.Runtime.InteropServices.ComTypes
Imports System.Windows.Forms
Public Class Form1
Inherits Form
Implements SolidEdgeFramework.ISESPEvents
Private _application As SolidEdgeFramework.Application
Private _connectionPoint As IConnectionPoint
Private _cookie As Integer
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
' Connect to Solid Edge.
_application = DirectCast(Marshal.GetActiveObject("SolidEdge.Application"), SolidEdgeFramework.Application)
ConnectEvents()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs)
DisconnectEvents()
End Sub
Private Sub ConnectEvents()
' Get the event GUID.
Dim typeGuid = GetType(SolidEdgeFramework.ISESPEvents).GUID
' Get a reference to the IConnectionPointContainer.
Dim container As IConnectionPointContainer = DirectCast(_application, IConnectionPointContainer)
' Lookup the IConnectionPoint.
container.FindConnectionPoint(typeGuid, _connectionPoint)
' Advise the sink.
_connectionPoint.Advise(Me, _cookie)
End Sub
Private Sub DisconnectEvents()
' Unadvise the sink.
_connectionPoint.Unadvise(_cookie)
' Clear variables.
_cookie = 0
_connectionPoint = Nothing
End Sub
#Region "ISESPEvents"
Public Sub SESP_BeforeCPDDisplay(pCPDInitializer As Object, eCPDMode As SolidEdgeFramework.eCPDMode) Implements SolidEdgeFramework.ISESPEvents.SESP_BeforeCPDDisplay
End Sub
Public Sub SESP_IsPreCPDEventSupported(ByRef pvbPreCPDEventSupported As Boolean) Implements SolidEdgeFramework.ISESPEvents.SESP_IsPreCPDEventSupported
pvbPreCPDEventSupported = True
End Sub
Public Sub SESPPDM_OnFileOpenUI(ByRef bstrFilename As String) Implements SolidEdgeFramework.ISESPEvents.SESPPDM_OnFileOpenUI
End Sub
#End Region
End Class
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Windows.Forms;
public class Form1 : Form, SolidEdgeFramework.ISESPEvents
{
private SolidEdgeFramework.Application _application;
private IConnectionPoint _connectionPoint;
private int _cookie;
public Form1()
{
InitializeComponent();
SubscribeToEvents();
}
private void Form1_Load(object sender, EventArgs e)
{
// Connect to Solid Edge.
_application = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");
ConnectEvents();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DisconnectEvents();
}
private void ConnectEvents()
{
// Get the event GUID.
var typeGuid = typeof(SolidEdgeFramework.ISESPEvents).GUID;
// Get a reference to the IConnectionPointContainer.
IConnectionPointContainer container = (IConnectionPointContainer)_application;
// Lookup the IConnectionPoint.
container.FindConnectionPoint(ref typeGuid, out _connectionPoint);
// Advise the sink.
_connectionPoint.Advise(this, out _cookie);
}
private void DisconnectEvents()
{
// Unadvise the sink.
_connectionPoint.Unadvise(_cookie);
// Clear variables.
_cookie = 0;
_connectionPoint = null;
}
#region ISESPEvents
public void SESP_BeforeCPDDisplay(object pCPDInitializer, SolidEdgeFramework.eCPDMode eCPDMode)
{
}
public void SESP_IsPreCPDEventSupported(ref bool pvbPreCPDEventSupported)
{
pvbPreCPDEventSupported = true;
}
public void SESPPDM_OnFileOpenUI(ref string bstrFilename)
{
}
#endregion
private bool EventsSubscribed = false;
private void SubscribeToEvents()
{
if (EventsSubscribed)
return;
else
EventsSubscribed = true;
base.Load += Form1_Load;
}
}