-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolidEdgeAppHelper.cs
More file actions
147 lines (129 loc) · 4 KB
/
SolidEdgeAppHelper.cs
File metadata and controls
147 lines (129 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Runtime.InteropServices;
using System.Threading;
namespace SolidEdgeTopLevelAsmOpener
{
using SolidEdge.Framework.Interop;
#region OleMessageFilter
internal class OleMessageFilter : IOleMessageFilter
{
public static void Register()
{
IOleMessageFilter newFilter = new OleMessageFilter();
IOleMessageFilter oldFilter = null;
if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
CoRegisterMessageFilter(newFilter, out oldFilter);
else
throw new COMException(
"Unable to register message filter because the current thread apartment state is not STA.");
}
public static void Revoke()
{
IOleMessageFilter oldFilter = null;
CoRegisterMessageFilter(null, out oldFilter);
}
int IOleMessageFilter.HandleInComingCall(
int dwCallType,
IntPtr hTaskCaller,
int dwTickCount,
IntPtr lpInterfaceInfo)
{
return (int)SERVERCALL.SERVERCALL_ISHANDLED;
}
int IOleMessageFilter.RetryRejectedCall(
IntPtr hTaskCallee,
int dwTickCount,
int dwRejectType)
{
if (dwRejectType == (int)SERVERCALL.SERVERCALL_RETRYLATER) return 99;
return -1;
}
int IOleMessageFilter.MessagePending(
IntPtr hTaskCallee,
int dwTickCount,
int dwPendingType)
{
return (int)PENDINGMSG.PENDINGMSG_WAITDEFPROCESS;
}
[DllImport("Ole32.dll")]
private static extern int CoRegisterMessageFilter(
IOleMessageFilter newFilter,
out IOleMessageFilter oldFilter);
}
internal enum SERVERCALL
{
SERVERCALL_ISHANDLED = 0,
SERVERCALL_REJECTED = 1,
SERVERCALL_RETRYLATER = 2
}
internal enum PENDINGMSG
{
PENDINGMSG_CANCELCALL = 0,
PENDINGMSG_WAITNOPROCESS = 1,
PENDINGMSG_WAITDEFPROCESS = 2
}
[ComImport()]
[Guid("00000016-0000-0000-C000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IOleMessageFilter
{
[PreserveSig]
int HandleInComingCall(
int dwCallType,
IntPtr hTaskCaller,
int dwTickCount,
IntPtr lpInterfaceInfo);
[PreserveSig]
int RetryRejectedCall(
IntPtr hTaskCallee,
int dwTickCount,
int dwRejectType);
[PreserveSig]
int MessagePending(
IntPtr hTaskCallee,
int dwTickCount,
int dwPendingType);
}
#endregion
public static class SEAppHelper
{
internal static bool SEIsRunningForeground(out Application SEApp)
{
try
{
SEApp = (Application)Marshal.GetActiveObject("SolidEdge.Application");
SEApp.DisplayAlerts = true;
SEApp.ResumeMRU();
SEApp.DelayCompute = false;
SEApp.Interactive = true;
SEApp.ScreenUpdating = true;
SEApp.Visible = true;
return true;
}
catch (Exception)
{
SEApp = null;
return false;
}
}
internal static Application SEStart()
{
try
{
var appType = Type.GetTypeFromProgID("SolidEdge.Application");
var SEApp = (Application)Activator.CreateInstance(appType);
SEApp.DisplayAlerts = true;
SEApp.ResumeMRU();
SEApp.DelayCompute = false;
SEApp.Interactive = true;
SEApp.ScreenUpdating = true;
SEApp.Visible = true;
return SEApp;
}
catch (Exception)
{
return null;
}
}
}
}