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
| using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
namespace Test {
/// <inheritdoc />
public class Test {
[DllImport("ole32.dll")]
private static extern int CreateItemMoniker([MarshalAs(UnmanagedType.LPWStr)] string lpszDelim, [MarshalAs(UnmanagedType.LPWStr)] string lpszItem, out IMoniker ppmk);
[DllImport("ole32.dll")]
private static extern int GetRunningObjectTable(uint reserved, out IRunningObjectTable pprot);
private object GetFromProcess(int processId) {
CreateItemMoniker(null, $"SolidWorks_PID_{processId}", out IMoniker moniker);
GetRunningObjectTable(0, out IRunningObjectTable runningObjectTable);
int result = runningObjectTable.GetObject(moniker, out object obj);
return obj;
}
}
} |
Partager