You may still use the familiar CreateObject() method from the Visual Basic 6 days if you'd like. In Visual Basic .NET, CreateObject() simply calls Activator.CreateInstance. This is important to understand because CreateObject() is a language specific feature of Visual Basic .NET. No other .NET language has a comparable feature. The other .NET languages must rely on Activator.CreateInstance.
Starting Solid Edge from Visual Basic .NET |
Copy Code
|
Imports System.Runtime.InteropServices
Module Program
<STAThread()> _
Sub Main()
Dim objApplication As SolidEdgeFramework.Application = Nothing
Dim objType As Type = Nothing
Try
'Old VB6 Syntax
'objApp = CreateObject("SolidEdge.Application")
OleMessageFilter.Register()
' Get the type from the Solid Edge ProgID
objType = Type.GetTypeFromProgID("SolidEdge.Application")
' Start Solid Edge
objApplication = Activator.CreateInstance(objType)
' Make Solid Edge visible
objApplication.Visible = True
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
OleMessageFilter.Revoke()
End Try
End Sub
End Module |
Starting Solid Edge from C# |
Copy Code
|
using System;
using System.Runtime.InteropServices;
namespace SolidEdge.SDK
{
class Program
{
[STAThread]
static void Main(string[] args)
{
SolidEdgeFramework.Application application = null;
Type type = null;
try
{
OleMessageFilter.Register();
// Get the type from the Solid Edge ProgID
type = Type.GetTypeFromProgID("SolidEdge.Application");
// Start Solid Edge
application = (SolidEdgeFramework.Application)
Activator.CreateInstance(type);
// Make Solid Edge visible
application.Visible = true;
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
OleMessageFilter.Revoke();
}
}
}
} |
See Also