Я не уверен, что должен делать ваш .dll, думаю, это форма, так как вам нужен ваш код mapbasic, чтобы реагировать на нажатие кнопки.
Для того, чтобы отправить команду на mapbasic, вынеобходимо создать экземпляр COM-объекта Mapinfo. Здесь - ссылка о том, как это сделать.Я лично использую второй подход.
Итак, после создания класса:
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