【问题标题】:Integrating Mapinfo and .NET C#集成 Mapinfo 和 .NET C#
【发布时间】:2018-11-24 00:12:30
【问题描述】:

我正在 MapBasic 中开发一个调用 .NET 程序集库中的方法的应用程序

这就是我在 MapBasice 环境中声明该方法的方式。

Declare Method showMainWindow Class "mynamespace.AldebaranInterface" Lib "Aldebaran.dll" ()

Sub ShowWindow
    Call showMainWindow()
End Sub

Sub formEventHandler
    'Reacting to some button click. I need to call this Sub from somewhere in mynamespace.AldebaranInterface
End Sub

我需要的是从我的 .NET C# 代码中回调 MapBasic 应用程序中的一些 Sub 或 Funcion。假设当用户单击我的 .NET 表单中的某个按钮时执行 MapBasic 代码的某些部分。

有没有办法做到这一点?如果是这样的话。我怎样才能实现它? 任何帮助将不胜感激。

【问题讨论】:

  • 也许在方法 showMainWindow 中使用返回值,并基于此返回值在 MBX 中调用您的函数。当然,这不是真正的“事件处理”,但它可能足以满足您的需求。除非“showMainWindow”显示模态表单,否则它应该可以工作。

标签: c# .net mapinfo map-basic


【解决方案1】:

我不确定你的 .dll 应该做什么,我猜它是一个表单,因为你需要你的 mapbasic 代码来响应按钮点击。

为了向 mapbasic 发送命令,您需要创建 Mapinfo 的 COM 对象的实例。 Here 是有关如何操作的链接。我个人使用second的方式。

所以在你创建类之后:

public class Mapinfo
{
   private object mapinfoinstance;
   public Mapinfo(object mapinfo)
   {
     this. mapinfoinstance = mapinfo;
   }

   public static Mapinfo CreateInstance()
   {
        Type mapinfotype = Type.GetTypeFromProgID("Mapinfo.Application");
        object instance = Activator.CreateInstance(mapinfotype);
        return new Mapinfo(instance);
    }

    public void Do(string command)
    {
          parameter[0] = command;
          mapinfoType.InvokeMember("Do",
                    BindingFlags.InvokeMethod,
                    null, instance, parameter);
     }

     public string Eval(string command)
     {
         parameter[0] = command;
         return (string)mapinfoType.InvokeMember("Eval", BindingFlags.InvokeMethod,
                             null,instance,parameter);
      }
}

,需要添加按钮点击事件:

appMapInfo = Mapinfo.CreateInstance();

//It's good idea to pass this path string from your MapBasic code
//as method parameter in your .dll 
string appMapInfoFilePath = @"D:\YourMBXPath\YourMBX.MBX";

//argumet you want to pass to MapBasic code
string argForMapBasic = ...;    

string runCommand;
string subCommand;

subCommand = "dim i_chan_num as integer i_chan_num = DDEInitiate(\"\"MapInfo\"\",\"\"" + appMapInfoFilePath + "\"\")";
subCommand = subCommand + " DDEExecute i_chan_num, \"\"" + argForMapBasic + "\"\"  DDETerminate i_chan_num";
runCommand = String.Format("Run Command \"{0}\"", subCommand);
appMapInfo.Do(runCommand);

现在在 MapBasic 端,您应该创建 Sub RemoteMsgHandler(MapBasic 参考:保留的过程名称,在远程应用程序发送执行消息时调用。

Sub RemoteMsgHandler 

    Dim command as String 

    'command - string passed from your C# code (string argForMapBasic)
    command = CommandInfo(CMD_INFO_MSG) 

    'pass a command to your procedure
    Call yourProcedure(command)

End Sub 

【讨论】:

  • 我要测试你的解决方案。几天后你会收到我的消息。谢谢。
猜你喜欢
  • 1970-01-01
  • 2020-09-18
  • 2012-06-21
  • 2010-12-19
  • 1970-01-01
  • 2016-06-07
  • 1970-01-01
  • 2011-01-23
  • 1970-01-01
相关资源
最近更新 更多