Communication between VB6 and multiple instances of MapInfo

367 views
Skip to first unread message

mat

unread,
Jun 24, 2008, 9:14:41 AM6/24/08
to MapInfo-L
Hi Listers,

I'm hoping someone can help with a VB / MapInfo problem. I've tried
all the usual avanues and seem to find the answers for single
instances, or multiple instances of MSOffice application, but not
multiple instances of non-office applications such as MapInfo.

Basically I have a VB6 EXE that needs to be launched with each new
intance of MapInfo and then run processes only on that instance of
MapInfo. I set and object = GetObject(, "Mapinfo.Application") in VB
to communicate back with MapInfo once MapInfo launches the EXE. This
works perfectly for the fist instance of MapInfo, but doesn't work for
subsewuent instances. The EXE wants to always run on the first
intance of MapInfo as expected with the GetObject function.

Has anyone got any ideas how I can work around this?

Thanks for your help.

Glen

unread,
Jun 24, 2008, 10:02:50 AM6/24/08
to MapInfo-L
you need to create a new object for each new mapinfo call

mi1 = GetObject(, "Mapinfo.Application")
mi2 = GetObject(, "Mapinfo.Application")

etc

mat

unread,
Jun 24, 2008, 10:29:16 AM6/24/08
to MapInfo-L
Hi Glenn,

Thanks for the suggestion. As far as I know the VB GetObject function
always returns the fist mapinfo instance, hence the mi1 and mi2
objects below would be the same. Also, I have no idea how many
instances of MapInfo the end-user will run, hence woulsdn't be able to
setup an appropriate number of MI_Objects in the VB code anyway.

I also don't think I explained the problem very well. When the user
starts MapInfo, the VB EXE is run from the Startup.wor file. The EXE
runs the processes in that instance of MapInfo then finishes (it's not
memory resident), hence the EXE only needs to reference the specific
MapInfo instance that launched it.

I guess what I really need is the VB EXE to create/set an object
representing the current MapInfo application/instance. This seems
near impossible from what I've read / seen thus far. Any other ideas
what may work? I was also thinking somehow to do it with DDE....


Glen

unread,
Jun 24, 2008, 11:23:22 AM6/24/08
to MapInfo-L
I did not keep any of my VB6 code because it so outdated
but you can run as many instances of MapInfo as you have memory

Dim mi1, mi2 As Object


Sub Form_Load()
Set mi1 = CreateObject("MapInfo.application")
mi1.do "Set Application Window " & Form1.hWnd
mi1.do "Set Next Document Parent " & Form1.hWnd & " Style 1"
mi1.do "Open Table ""World"" Interactive Map From World"
mi1.RunMenuCommand 1702
mi1.do "Create Menu ""MapperShortcut"" ID 17 As ""(-"" "

Set mi2 = CreateObject("MapInfo.application")
mi2.do "Set Application Window " & Form2.hWnd
mi2.do "Set Next Document Parent " & Form2.hWnd & " Style 1"
mi2.do "Open Table ""World"" Interactive Map From World"
mi2.RunMenuCommand 1702
mi2.do "Create Menu ""MapperShortcut"" ID 17 As ""(-"" "

End Sub

try this it been a long time then do a crtl alt delet and see if 2
mapinfo.exe are running

Glen

unread,
Jun 24, 2008, 11:34:35 AM6/24/08
to MapInfo-L
but it easier just to use 1 instances of MapInfo and open lots of
windows / forms

mat

unread,
Jun 24, 2008, 7:55:18 PM6/24/08
to MapInfo-L
Hi Glen,

Thanks again for your help.

Unfortunately the example kind of does the opposite of what I need to
do. The example has VB launching multiple instances of MapInfo and
creating an object each time it launches MapInfo via the CreateObject
function. I have the opposite situation where MapInfo needs to launch
a VB EXE, so needs to use the GetObject function to return an object
representing that instance of MapInfo. Unfortunately though, the
users often have 4 or 5 MapInfo sessions running, so when each
additional MapInfo session is opened, and the same VB EXE is launched,
it will return an object for the first session opened. I can’t seem
to find a way of returning anything except that first instance of
MapInfo. Any other ideas?

Cheers,
Mat

Glen

unread,
Jun 25, 2008, 12:52:16 AM6/25/08
to MapInfo-L
object.hWnd [=long]

Remarks Returns the control window handle.
The Microsoft Windows operating environment identifies each window,
form and control in an application by assigning it a handle, or hWnd.
The hWnd property is used with Windows API calls. Many Windows
operating environment functions require the hWnd of the active window
as an argument.
Notes: Because the value of this property can change while a program
is running, never store the hWnd value in a variable.


you set a handle; then use it to force that window active; then call
object = GetObject(, "Mapinfo.Application")

each session will have it own handle

Gentreau

unread,
Jun 25, 2008, 4:35:45 AM6/25/08
to mapi...@googlegroups.com

Mat, why don't you approach it from the other direction?

Can't you modify the 'open' command for MapInfo on these users' computers
so that they actually launch your VB application, which then opens it's own
instance of MapInfo?

That way you have control over the assignment of handles.

Just a thought.

Gentreau.

mat

unread,
Jun 29, 2008, 3:00:29 AM6/29/08
to MapInfo-L
Hi Gentreau,

Excellent idea. It's not ideal for my application, but would work
perfectly.

Changing the Quick Launch, Desktop and Start-Menu, as well as the file
associations for WOR & TAB files is pushing the limits of my knowledge
with MapBasic/Windows API. Does anyone have any examples of how to
search out and modify the Open MapInfo shortcuts, and change the file
associations using MapBasic?

Thanks Gentreau.

Cheers
Mat
Reply all
Reply to author
Forward
0 new messages