call MapBasic from .dll .net

675 views
Skip to first unread message

dror reshef

unread,
Nov 1, 2009, 1:00:36 AM11/1/09
to MapInfo-L


i have a MapBasic mbx file that load a C# .net dll and call some
static methods in it

problem is i need to send information back to MapBasic

i know there is possibility of doing calling MapBasic from .net
like
http://woostuff.wordpress.com/2009/02/24/commands-to-a-mbx-program/

but i can't use

MapInfoApplicationClass mapinfoinstance = new MapInfoApplicationClass
();

i need to use the existing (runing) instance of mapInfo

the reason i (think) i need such a thing is that i have existing mbx
file that call a .net dll and i need to send back some parameters to
it

thanks, dror

Uffe Kousgaard

unread,
Nov 1, 2009, 2:18:42 AM11/1/09
to mapi...@googlegroups.com
Hi,

The example you have found is completely different. It is about sending
commands from a C# exe to MapInfo. That has been possible as long as C# has
existed. Known as Integrated mapping.

What you are trying to do is calling a C# dll from mapbasic. That is the new
option added in MI 9 or 9.5 (don't remember which one right now).

Define your static method in C#, so it returns a value and then define it
similarly in mapbasic as a function with a return value. The alternative is
defining the parameters as "byref", "var" or whatever it is called when the
parameters in the function call can be changed by the dll.

Regards
Uffe Kousgaard

dror reshef

unread,
Nov 1, 2009, 2:39:11 AM11/1/09
to MapInfo-L
Hi Uffe,

thanks but I'm already calling a C# dll from MapBasic, but i can't
just return parameters because i calling a .net dialog and i need to
pass parameters to the mapBasic when the user is filling a form and
hit save button.

However, thanks, you gave me an idea -
1 - user hit "save" in .net dialog
2 - .net store parameters in static variables
3 .net call Mapbasic using a dde ( i can't use this to transfer the
data since i need to pass Unicode data)
4. mapBasic call a function in .net which return a string parameter or
send byref parameter
5. .net send back the data in the function

quite clumsy but at list it could work (i hope)

Gentreau

unread,
Nov 1, 2009, 3:12:33 AM11/1/09
to mapi...@googlegroups.com

Can't you use a temporary file to exchange the data?
Dll writes to the file, mapbasic reads it then deletes it.

dror reshef

unread,
Nov 1, 2009, 4:43:57 AM11/1/09
to MapInfo-L
Hi Gentreau

i tried this approach (read and write to temp access table) but it's
unrelaibale way of communication, some times the .net didn't write a
row properly and some times the MapBasic didn't read the file. i had
failures in about 25% of the times!

Someone told me i should configure the tab file so it will read the
access in a remote way using ODBC but i don't know how to do that, and
i'm not sure it would have helped.

In any case, i solved my private problem using the bizarre approach i
wrote earlier about. but I would like to hear about more elegant ways
to communicate from .Net DLL to Mapbasic mbx (OLE , Unicode dde or
via access files)

Gentreau

unread,
Nov 1, 2009, 6:58:51 AM11/1/09
to mapi...@googlegroups.com

What I'm not clear on is why there is any difference between a .net dll and
the dll's which I use (written in C).
I have no problems in passing values back and forth between MB and the dll.
The same with the Windows native funtions in the system32 dlls.

Can you not just pass the dll a variable to fill and then read the value in
MB ?

The temp file solution, which I also use for some functions, writes to a
text file (normally csv), not a tab file.
MB then registers the file as a table. This is reliable in my experience, so
long as you control where the file is written.

Gentreau.

Glen

unread,
Nov 1, 2009, 9:36:06 AM11/1/09
to MapInfo-L
Gents

I Pass them BOTH ways with just a function call? I don't understand
the question?

function call (supplied data) AS Data type

smart...@gmail.com

unread,
Nov 1, 2009, 9:59:51 AM11/1/09
to MapInfo-L
I don't think I fully understand the issue, because to me,
it sounds like you could simply use by-reference arguments.
The fact that .Net is showing a dialog, and you want to return
information when the user clicks Save button, doesn't change that.

You could have a .Net method that returns a boolean to indicate
whether the user dismissed the dialog by clicking the Save button. If
and only if the user clicks Save, the .Net method would update the
values of the by-ref arguments. I would think that would solve the
problem, but again, I'm not sure I understand the question, because
the original question was vague -- "some parameters" is pretty
vague.

At any rate, I can't imagine DDE being necessary.
If you decide your .Net method needs to store some information in
static variables, then, that should work. But, to retrieve the
values, you could just add more static Getter methods that do nothing
but return that static information. No need to use DDE for that.

An alternative would be for your .Net method to control MapInfo, by
using MapInfo's Do and Eval methods. The Named Views sample app
demonstrates how to do this, and the .Net chapter in the MapBasic User
Guide describes how it works.

dror reshef

unread,
Nov 1, 2009, 11:56:41 AM11/1/09
to MapInfo-L
One important thing i failed to mention -my .net dialogs are models -
that is if you call a dialog you can't know when the user will hit
save button, and you can't use a function return info or a given byref
parameter to do that.

in the end used a getter function from MapBasic to .Net but i needed
to call this getter function from the .net + dde

standard Mapinfo do and eval only work for Mapinfo - not for MapBasic
(MBX file), if one want to activate methods of do or eval of MapBasic
he need to lunch a hole operation like described here:

http://woostuff.wordpress.com/2009/02/24/commands-to-a-mbx-program/

.net chapter say how to communicate from mapbasic to .net (call dll
methods) or get info from it using dde - not about ole / com
coomuncation from .net dll to MapBasic



On Nov 1, 4:59 pm, "smartgro...@gmail.com" <smartgro...@gmail.com>
wrote:

Gentreau

unread,
Nov 1, 2009, 6:29:07 PM11/1/09
to mapi...@googlegroups.com

Can you explain one thing.

Are you calling the .net dialog from within a MapBasic mbx ?
If so, why do you think that you cannot return variables back from the dll
to the mbx ?

This is not making sense to me or to others here.

Please explain clearly what you are trying to achieve.

dror reshef

unread,
Nov 2, 2009, 3:44:28 AM11/2/09
to MapInfo-L
yes i call the dialog from MapBasic

when you call a model dialog you get the parameters back when the
dialog close.
but mode-less dialog just stays there , after you called him, long
after the showdialog method had finished and returned to Mapbasic

the difference events in time are

for model dialog:
code call showdialog from MapBasic
user fill the dialog
user click save button
code return to MapBasic

so it's easy to return the data

for modeless dialog:
code call show dialog from Mapbasic
code return to MapBasic
user fill the dialog
user click save button

so you have to contact MapBasic to tell it that save was clicked and
that some data is awaiting it's retreval

Gentreau

unread,
Nov 2, 2009, 4:31:14 AM11/2/09
to mapi...@googlegroups.com

OK, now that makes it much clearer. (by the way the term is modal /
non-modal)

Have you looked at the help file entry for the RemoteMsgHandler procedure ?

----------------------------------------------------------------------------
---------
Purpose
A reserved procedure name, called when a remote application sends an execute
message.

Syntax
Declare Sub RemoteMsgHandler

Sub RemoteMsgHandler
statement_list
End Sub
statement_list is a list of statements to execute upon receiving an execute
message.
----------------------------------------------------------------------------
---------

Gentreau

unread,
Nov 2, 2009, 4:41:33 AM11/2/09
to mapi...@googlegroups.com

Interestingly the font of all knowledge (well Wikipedia anyway) says that
the terms are Modal and Modeless.

http://en.wikipedia.org/wiki/Modal_window

That's not how I learnt them, but then we were grateful to have 640k of RAM
and 2 floppy drives in them days :)

-----Original Message-----
From: Gentreau [mailto:goo...@gentreau.com]
Sent: Monday, November 02, 2009 10:31 AM
To: 'mapi...@googlegroups.com'
Subject: RE: [MI-L] Re: call MapBasic from .dll .net


OK, now that makes it much clearer. (by the way the term is modal /
non-modal)

Have you looked at the help file entry for the RemoteMsgHandler procedure ?

----------------------------------------------------------------------------
---------
Purpose
A reserved procedure name, called when a remote application sends an execute
message.

Syntax
Declare Sub RemoteMsgHandler

Sub RemoteMsgHandler
statement_list
End Sub
statement_list is a list of statements to execute upon receiving an execute
message.
----------------------------------------------------------------------------
---------

Reply all
Reply to author
Forward
0 new messages