Obtain specific/active instance of COM Object

159 views
Skip to first unread message

Sancarn

unread,
Mar 22, 2017, 9:09:00 AM3/22/17
to MapInfo-L
Hi All,

I'm trying to automate the front instance of MapInfo from another application. The easiest way to do this, pre .NET, is to connect to the COM object and use MapInfo.Do() / MapInfo.Eval() functions to execute commands. For example, in VB6/VBS:

Dim MapInfo As Object

Set MapInfo = GetObject(, "MapInfo.Application.x64")

MapInfo.Do "Print ""Hello World"""


Will print "Hello World" to the message window of the first opened instance of MapInfo 64-bit.

However my problem here is that the returned COM object is the first opened instance of MapInfo rather than the active instance of MapInfo. Is there any way to obtain the COM Object for the active, or any other, instance of MapInfo?

Peter Horsbøll Møller

unread,
Mar 22, 2017, 9:19:24 AM3/22/17
to mapi...@googlegroups.com

Are you launching your ”other application” from within the MapInfo Pro that you want it to “link” back to?

 

If yes, you might be able to send a reference to this MapInfo Pro to your application.

 

Peter Horsbøll Møller

Pitney Bowes

--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to
mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.




Sancarn

unread,
Mar 22, 2017, 9:26:10 AM3/22/17
to MapInfo-L
I've found this post asking a similar question:


It looks like it might not be possible without modifying all MapInfo shortcuts on the computer which seems a bit convoluted... It's possible though of course it would be nice if there was a direct method...

Sancarn

unread,
Mar 22, 2017, 9:54:14 AM3/22/17
to MapInfo-L
I can launch it from within MapInfo if that eliminates the problem! :) How would one send a reference to the MapInfo Pro application?

Peter Horsbøll Møller

unread,
Mar 22, 2017, 10:02:38 AM3/22/17
to mapi...@googlegroups.com

One of these attributes from the SystemInfo() function should do the trick:

 

SYS_INFO_MAPINFOWND

9

IntPtr*: a Windows HWND of the MapInfo Pro frame window, or zero on non-Windows platforms.

SYS_INFO_APPIDISPATCH

17

IntPtr*: the IDispatch OLE Automation pointer for the MapInfo application.

SYS_INFO_IMAPINFOAPPLICATION

20

Returns an instance of the MapInfo Pro application represented as a .NET Specific Variable. This variable type refers to an instance of IMAPINFOPRO, which is the base interface providing access to MapInfo Pro components in your Add-ins.

Sancarn

unread,
Mar 22, 2017, 1:26:31 PM3/22/17
to MapInfo-L
Ah right of course. The IDispatch... Thanks Peter!

Sancarn

unread,
Mar 24, 2017, 8:48:41 AM3/24/17
to MapInfo-L
Hi Peter,

Today I tried using the iDispatch however I cannot connect to the COM Object?

Are there any available examples of how to use IDispatch with VB/C#?

Thanks,

On Wednesday, March 22, 2017 at 1:09:00 PM UTC, Sancarn wrote:

Thomas Bacon

unread,
Mar 24, 2017, 9:28:56 AM3/24/17
to mapi...@googlegroups.com

You might find this thread useful: https://groups.google.com/forum/#!topic/mapinfo-l/eZ4P1DTikUk

 

Specifically, have a look at Cliff B’s answer.

 

HTH,

 

Tom

 

From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Sancarn


Sent: 24 March 2017 12:49
To: MapInfo-L <mapi...@googlegroups.com>

--

--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


______________________________________________________________________

Mouchel Limited I Registered in England No. 1686040 Registered Office: WSP House, 70 Chancery Lane, London, Wc2A 1AF Part of WSP Global Inc. Confidential This message, including any document or file attached, is intended only for the addressee and may contain privileged and/or confidential information. Any other person is strictly prohibited from reading, using, disclosing or copying this message. If you have received this message in error, please notify the sender and delete the message. Thank you.
______________________________________________________________________

Sancarn

unread,
Mar 24, 2017, 3:33:51 PM3/24/17
to MapInfo-L
Tom,

Thanks. Sadly I do not have access to the Marshal library/object... However I did find a way to get all active COM objects from the ROT (Running Objects Table - Stores all active COM objects). This involves interfacing with IRunningObjectTable interface

Fortunately for me the code had already been created by someone else. I believe it would be even easier in C# / VB.

This will be extremely powerful for me! So maybe it'll help others too :)

Thanks,

Cliff B

unread,
Apr 5, 2017, 11:44:49 PM4/5/17
to MapInfo-L
I'm actually revisiting this now in the x64 mapinfo.

The Dispatch ID is now a long not an int so I've had to send it as a string rather than integer.
However doing it this way I've only been able to get the DMapInfo which doesn't expose the new methods in IMapInfoPro such as creating unattached windows, etc.


The alternative is to pass the result of SystemInfo(SYS_INFO_IMAPINFOAPPLICATION) to .net as a Mapinfo.Types.IMapInfoPro. (you'll need to add a reference to MapInfo.Types.dll)

Sancarn

unread,
Apr 6, 2017, 3:02:04 AM4/6/17
to MapInfo-L
As far as I know a pointer to a COM object cannot be used in another process:


So such a system will only work if you are calling an MBX from within MapInfo itself. (Which is ideally what I was wanting to avoid, given that I am writing a large portion of the application outside MapInfo and i'd rather avoid multiple files)

So as said above the only option, if wanting to use it from a separate process, is to loop through IMonikers of the iRunningObjectTable. I will try to throw some .NET console application which will do this also :)
Reply all
Reply to author
Forward
0 new messages