Integrating Mapinfo and .NET C#
I'm developing an app in MapBasic that calls methods in a .NET assembly library
This is how I Declare the method in my MapBasice enviroment.
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
What I need is to callback some Sub or Funcion in my MapBasic application from my .NET C# code. Let's say execute some portion of MapBasic code when the user clicks some button that is in my .NET form.
Is there a way to do that? If so. How can I achieve it?
Any Help would be highly appreciated.
c# .net mapinfo map-basic
add a comment |
I'm developing an app in MapBasic that calls methods in a .NET assembly library
This is how I Declare the method in my MapBasice enviroment.
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
What I need is to callback some Sub or Funcion in my MapBasic application from my .NET C# code. Let's say execute some portion of MapBasic code when the user clicks some button that is in my .NET form.
Is there a way to do that? If so. How can I achieve it?
Any Help would be highly appreciated.
c# .net mapinfo map-basic
Perhaps use a return value in method showMainWindow and based on this return value call your function in MBX. Of course this is no real "event Handling" but it may be sufficient for your needs. Unless "showMainWindow" shows a modal form it should work.
– Wernfried Domscheit
Nov 27 '18 at 15:50
add a comment |
I'm developing an app in MapBasic that calls methods in a .NET assembly library
This is how I Declare the method in my MapBasice enviroment.
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
What I need is to callback some Sub or Funcion in my MapBasic application from my .NET C# code. Let's say execute some portion of MapBasic code when the user clicks some button that is in my .NET form.
Is there a way to do that? If so. How can I achieve it?
Any Help would be highly appreciated.
c# .net mapinfo map-basic
I'm developing an app in MapBasic that calls methods in a .NET assembly library
This is how I Declare the method in my MapBasice enviroment.
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
What I need is to callback some Sub or Funcion in my MapBasic application from my .NET C# code. Let's say execute some portion of MapBasic code when the user clicks some button that is in my .NET form.
Is there a way to do that? If so. How can I achieve it?
Any Help would be highly appreciated.
c# .net mapinfo map-basic
c# .net mapinfo map-basic
asked Nov 24 '18 at 0:12
mdevmdev
181413
181413
Perhaps use a return value in method showMainWindow and based on this return value call your function in MBX. Of course this is no real "event Handling" but it may be sufficient for your needs. Unless "showMainWindow" shows a modal form it should work.
– Wernfried Domscheit
Nov 27 '18 at 15:50
add a comment |
Perhaps use a return value in method showMainWindow and based on this return value call your function in MBX. Of course this is no real "event Handling" but it may be sufficient for your needs. Unless "showMainWindow" shows a modal form it should work.
– Wernfried Domscheit
Nov 27 '18 at 15:50
Perhaps use a return value in method showMainWindow and based on this return value call your function in MBX. Of course this is no real "event Handling" but it may be sufficient for your needs. Unless "showMainWindow" shows a modal form it should work.
– Wernfried Domscheit
Nov 27 '18 at 15:50
Perhaps use a return value in method showMainWindow and based on this return value call your function in MBX. Of course this is no real "event Handling" but it may be sufficient for your needs. Unless "showMainWindow" shows a modal form it should work.
– Wernfried Domscheit
Nov 27 '18 at 15:50
add a comment |
1 Answer
1
active
oldest
votes
I'm not sure what is your .dll is supposed to do, I guess it's a form, since you need your mapbasic code to react to button click.
In order to send command to mapbasic you need to create instance of Mapinfo’s COM object.
Here is the link on how to do it. I personally use second approach.
So after you create class:
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);
}
}
, you need to add button clicked event:
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:YourMBXPathYourMBX.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);
Now on MapBasic side, you should create Sub RemoteMsgHandler (MapBasic Reference: A reserved procedure name, called when a remote application sends an execute message.)
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
I'm gonna test your solution. You will hear from me in a few days. Thank you.
– mdev
Dec 4 '18 at 3:31
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454116%2fintegrating-mapinfo-and-net-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm not sure what is your .dll is supposed to do, I guess it's a form, since you need your mapbasic code to react to button click.
In order to send command to mapbasic you need to create instance of Mapinfo’s COM object.
Here is the link on how to do it. I personally use second approach.
So after you create class:
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);
}
}
, you need to add button clicked event:
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:YourMBXPathYourMBX.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);
Now on MapBasic side, you should create Sub RemoteMsgHandler (MapBasic Reference: A reserved procedure name, called when a remote application sends an execute message.)
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
I'm gonna test your solution. You will hear from me in a few days. Thank you.
– mdev
Dec 4 '18 at 3:31
add a comment |
I'm not sure what is your .dll is supposed to do, I guess it's a form, since you need your mapbasic code to react to button click.
In order to send command to mapbasic you need to create instance of Mapinfo’s COM object.
Here is the link on how to do it. I personally use second approach.
So after you create class:
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);
}
}
, you need to add button clicked event:
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:YourMBXPathYourMBX.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);
Now on MapBasic side, you should create Sub RemoteMsgHandler (MapBasic Reference: A reserved procedure name, called when a remote application sends an execute message.)
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
I'm gonna test your solution. You will hear from me in a few days. Thank you.
– mdev
Dec 4 '18 at 3:31
add a comment |
I'm not sure what is your .dll is supposed to do, I guess it's a form, since you need your mapbasic code to react to button click.
In order to send command to mapbasic you need to create instance of Mapinfo’s COM object.
Here is the link on how to do it. I personally use second approach.
So after you create class:
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);
}
}
, you need to add button clicked event:
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:YourMBXPathYourMBX.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);
Now on MapBasic side, you should create Sub RemoteMsgHandler (MapBasic Reference: A reserved procedure name, called when a remote application sends an execute message.)
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
I'm not sure what is your .dll is supposed to do, I guess it's a form, since you need your mapbasic code to react to button click.
In order to send command to mapbasic you need to create instance of Mapinfo’s COM object.
Here is the link on how to do it. I personally use second approach.
So after you create class:
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);
}
}
, you need to add button clicked event:
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:YourMBXPathYourMBX.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);
Now on MapBasic side, you should create Sub RemoteMsgHandler (MapBasic Reference: A reserved procedure name, called when a remote application sends an execute message.)
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
answered Nov 27 '18 at 13:15
Kevin MaloneKevin Malone
1
1
I'm gonna test your solution. You will hear from me in a few days. Thank you.
– mdev
Dec 4 '18 at 3:31
add a comment |
I'm gonna test your solution. You will hear from me in a few days. Thank you.
– mdev
Dec 4 '18 at 3:31
I'm gonna test your solution. You will hear from me in a few days. Thank you.
– mdev
Dec 4 '18 at 3:31
I'm gonna test your solution. You will hear from me in a few days. Thank you.
– mdev
Dec 4 '18 at 3:31
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454116%2fintegrating-mapinfo-and-net-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Perhaps use a return value in method showMainWindow and based on this return value call your function in MBX. Of course this is no real "event Handling" but it may be sufficient for your needs. Unless "showMainWindow" shows a modal form it should work.
– Wernfried Domscheit
Nov 27 '18 at 15:50