我有一个用于调用 C#.NET 方法的第三方应用程序的插件,我需要从调用应用程序中获取实例。
_MapInfoApplication = (MapInfo.MapInfoApplication) System.Runtime.InteropServices.Marshal.GetActiveObject("Mapinfo.application");
给我一个来自应用程序的活动实例,但如果有两个打开的应用程序实例我不知道我是否得到了正确的实例,有没有办法确定谁打电话?
使用该方法,使用from作为参数System.Runtime.InteropServices.Marshal.GetObjectForIUnknown
传递对象指针:IDispatchID
MapInfo
public static void MINote(int MIWindowID, string Message)
{
System.IntPtr MIDispatchPtr = new IntPtr(MIWindowID);
DMapInfo MIConnection = (DMapInfo)Marshal.GetObjectForIUnknown(MIDispatchPtr);
MIConnection.Do(String.Format("Note \"Note from CSharp: {0}\"",Message));
DMBApplications Applications = (DMBApplications) MIConnection.MBApplications;
foreach (DMapBasicApplication mbApp in Applications)
{
MIConnection.Do(String.Format("Note \"MB App. running in this MapInfo instance: {0}\"", mbApp.Name));
}
}