我不确定你的 .dll 应该做什么,我猜它是一个表单,因为你需要你的 mapbasic 代码来响应按钮点击。
为了向 mapbasic 发送命令,您需要创建 Mapinfo 的 COM 对象的实例。
这是有关如何执行此操作的链接。我个人使用第二种方法。
所以在你创建类之后:
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