Embedded MapInfo Callbacks in C#

2,499 views
Skip to first unread message

littlecharva

unread,
Jan 3, 2007, 11:01:04 AM1/3/07
to MapInfo-L
Hi everyone,

I'm hoping someone might be able to point me in the right direction
with this.

I'm using C# and the .NET framework, but WITHOUT MapXtreme or whatever
it's called. I've managed to work out how to do the equivilant of
CreateObject("MapInfo.Application") in C#, and I have my app working
perfectly, the only thing I can't do is get Callbacks to work.

I've created a new class with a WindowContentsChanged(int intVal)
method and I've instantiated the class and handed it to
MapInfo.SetCallBack, but I just get an exception when I run it.

I guess my callback class needs to have something else in it (something
to do with OLE?), but I don't know where to start. I've tried
searching google for "c# ole server", but nothing helpful comes up.

Any ideas?

Littlecharva

SCISOFT

unread,
Jan 4, 2007, 5:55:23 AM1/4/07
to mapi...@googlegroups.com
Littlecharva

This was discussed a while back. Try this MapInfo-L archive URL -
http://www.directionsmedia.net/pipermail/mapinfo-l/2006-May/002382.html

As an aside, I don't know if the MapInfo-L archives are guaranteed to be
preserved )on DirectionsMag or elsewhere).

IL Thomas
GeoSciSoft - Perth, Australia


Hi everyone,

Any ideas?

Littlecharva


--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.16.3/614 - Release Date: 2/01/2007
2:58 PM

littlecharva

unread,
Jan 4, 2007, 6:34:43 AM1/4/07
to MapInfo-L
Hi Thomas,

Thanks for the reply, though the linked article is in VB.NET, and while
it's usually a straightforward task to convert VB to C#, this is one of
the areas where it has me baffled, especially since the linked article
seems to make use of a LibPinvokelib.dll, which doesn't appear on my
system.

Does anyone have any C# examples, or can give me a little more
information on what I'm supposed to be doing? Is there a .NET class I
can inherit from? Do I need to use delegates? Interfaces?

Thanks again,
Littlecharva

SCISOFT

unread,
Jan 4, 2007, 6:56:59 AM1/4/07
to mapi...@googlegroups.com
Littlecharva

There is very little difference between C# and VB.NET - if you really want
to, you can use a conversion routine for VB.NET to C# (or vice versa). There
are many (for free, online or downloadable).

I suggest that you read the URL that I quoted to you, then go to the parent
thread and read all 4 or 5 postings (my conversation with Mr Hebblethwaite).


Then go to the referenced thread from ?February/March 2006 which teases out
all of the requirements for a successful .NET and COM and MapInfo
conversation, and although that is using the VB.NET language, it will give
you everything that you need to know.

Look for these keywords and people -

"Callback in vb.net" (subject)
Milo van der Linden
Christian Singer*

* Christian Singer has provided some important notes on what is needed for
this to be successful.

Please read all of the van der Linder / Singer correspondence, else you are
unlikely to understand what the code is about.

IL Thomas
GeoSciSoft - Perth, Australia

-----Original Message-----
From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On
Behalf Of littlecharva

littlecharva

unread,
Jan 4, 2007, 9:34:09 AM1/4/07
to MapInfo-L
Hi IL Thomas,

I looked at the MSDN article you recommended and by using it with
David's code I came up with the following:

public delegate void pWindowContentsChanged(int intValue);

public class CallbackWrap
{
[DllImport("..\\LIB\\PinvokeLib.dll")]
public static extern void
WindowContentsChanged(pWindowContentsChanged cb, int intValue);
}


class MICallbacks
{
public void WindowContentsChanged(int intID)
{
Console.WriteLine("Callback Sucessful");
}
}

... And added the following to the Form_Load of my main form:

objMICallbacks = new MICallbacks();
pWindowContentsChanged objCB = new
pWindowContentsChanged(objMICallbacks.WindowContentsChanged);
objMapInfo.SetCallback(objMICallbacks);

Which didn't work, so I hunted down the other article you mentioned and
saw that Christian Singer used a ComClass, so after googling that for a
while I discovered that VB has a wizard available to create one,
whereas C# doesn't. I tracked down how to create one in C# and used
the GUIDs provided in Christian's post and came up with this:

using System;
using System.Runtime.InteropServices;

namespace MapInfoTest
{
[Guid("2A765F7E-E628-4427-A730-A695543EDB79"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch) ]
public interface MIEventInterface
{
}

[Guid("CC6697F7-968D-47dc-9B5B-84DEF8FD5D6B"),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface MIComInterface
{
[DispId(1)]
void WindowContentsChanged(int intID);
}

[Guid("9CC9946D-C1E4-4f42-9E8C-C4693BD04577"),
ProgId("MapInfoTest.MICallbacks"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(MIEventInterface))]
public class MICallbacks : MIComInterface
{

public MICallbacks()
: base()
{
}

public void WindowContentsChanged(int intID)
{
Console.WriteLine("Yeah Baby!");
}
}
}

Then using the following in my Form_Load:

objMICallbacks = new MICallbacks();
objMapInfo.SetCallback(objMICallbacks);

Which causes the same error I've been getting all along:

TargetInvocationException: Exception has been thrown by the
target of an invocation.

So I've followed both of your suggestions to the best of my ability,
but still can't get anywhere; can you see where I'm going wrong?

Littlecharva

littlecharva

unread,
Jan 5, 2007, 9:53:24 AM1/5/07
to MapInfo-L
I've cracked it!

Use the second example of code in my post above (the ComClass one),
then in VS2005 go to Project -> myProject Properties. Under the
Application tab, click the "Assembly Information..." button and in the
next dialog make sure there is a tick in the "Make Assembly COM
Visible" box.

One bloody tick box!!!

Thanks again IL Thomas, I wouldn't have got there without your help. I
hope this thread helps someone else down the line.

Littlecharva

nicholas....@mainroads.qld.gov.au

unread,
Jan 7, 2007, 6:23:44 PM1/7/07
to mapi...@googlegroups.com
Is there any advantage to running MapInfo on a dual-processor machine?

Is MapInfo threaded?

Regards,
Nick Lawrence


************************************************************
Opinions contained in this e-mail do not necessarily reflect
the opinions of the Queensland Department of Main Roads,
Queensland Transport or Maritime Safety Queensland, or
endorsed organisations utilising the same infrastructure.
If you have received this electronic mail message in error,
please immediately notify the sender and delete the message
from your computer.
************************************************************

Ian Tidy

unread,
Jan 7, 2007, 6:59:15 PM1/7/07
to mapi...@googlegroups.com
Nick,

I have a dual processor machine, and MapInfo doesn't generally use the
second processor. It does not appear to threaded. However some tools
external to MapInfo Pro do use the extra processor. The same thing
applies with Hyper threading, I have turned it off because MapInfo
doesn't use it and it adds extra overheads. I have just purchased a
Core Duo 2 laptop and this is no different to my workstation.

This is probably one area where MapInfo could make performance gains to
MapInfo Pro.

Cheers Ian
______________________
Ian Tidy
GIS Administrator
Works Asset Department
Napier City Council
mailto:ia...@napier.govt.nz
http://www.napier.govt.nz

-----Original Message-----
From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On

Is MapInfo threaded?

Regards,
Nick Lawrence


######################################################################

This e-mail message has been scanned and cleared by MailMarshal

######################################################################
######################################################################
Attention:
This e-mail message and accompanying data may contain information that
is confidential and subject to legal privilege. Any information
provided is given in good faith. However unless specifically stated to
the contrary, Napier City Council accepts no liability for the
content of this e-mail or for the consequences of any action taken on
the basis of the information provided, unless that information is
subsequently confirmed in writing. If you are not the intended recipient,
you are notified that any use, dissemination, distribution or copying
of this message or data is prohibited. If you received this e-mail
message in error, please notify us immediately and erase all copies
of this message and attachments. Thank you.

Trey Pattillo

unread,
Jan 7, 2007, 8:29:38 PM1/7/07
to mapi...@googlegroups.com
none that I know of as far as MI is concerned, only uses one processor

but you other apps will not suffer and move in/out of the duals
I run SimplyMEPIS Linux with VMware running Win2ksp4 and MI6.5 just fine
on a AMX XP 4200+, 2gig dual channel ram, dual 320gig SATA3 drives with
on board nVidia 6800 graphics set for 128mem
[2gig is the key for using VMware otherwise 1gig is fine]

nicholas....@mainroads.qld.gov.au

unread,
Jan 9, 2007, 9:28:02 PM1/9/07
to mapi...@googlegroups.com
How can I make Google Maps or Google Earth into a layer inside MapInfo?

I looked at "Link Utility for Google Earth" but that one puts mapinfo data
into google
earth, while I want to go the other way, ie put google earth data into
mapinfo.

Arne Scherrenberg

unread,
Jan 9, 2007, 9:38:03 PM1/9/07
to mapi...@googlegroups.com
I asked this question a while back, before MI 8.5, and at that point
it wasn't possible with basic MI. But since the new version, I
discovered that it is possible to import .gml files, but haven't had a
chance to test it. But if you want to try then save the GE file as
.gml, and then try importing (tab/import) as gml file in MI! Please
let me know if it works.

Cheers,

Arne

On 10/01/07, nicholas....@mainroads.qld.gov.au

Ian Tidy

unread,
Jan 9, 2007, 9:50:09 PM1/9/07
to mapi...@googlegroups.com
Arne / Nick,

Be careful with GML, there are several versions and MapInfo Pro doesn't
support them all.

Cheers Ian

-----Original Message-----
From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On
Behalf Of Arne Scherrenberg
Sent: Wednesday, 10 January 2007 3:38 p.m.
To: mapi...@googlegroups.com

Cheers,

Arne

######################################################################

Driver, Greg 9434

unread,
Jan 10, 2007, 4:43:07 AM1/10/07
to mapi...@googlegroups.com
Nick,

FME will do the conversion from KML to Tab files. I think you can
download a time-limited version to try out, if you don't have it.

Greg Driver

System Administrator
Applications Support
ICT
NOT PROTECTIVELY MARKED

Uffe Kousgaard

unread,
Jan 10, 2007, 4:58:11 AM1/10/07
to mapi...@googlegroups.com
I'm almost sure Nick Lawrence is interested in bringing in the satellite
images from Google Earth and not the vector layers on top of it (KML files).
Only option seem to be a simple non-georeferenced jpg export.

Regards
Uffe Kousgaard

Lars I. Nielsen (GisPro)

unread,
Jan 10, 2007, 6:14:27 AM1/10/07
to mapi...@googlegroups.com
Does anyone know, whether Google Earth is using the satellite imagery
from Google Maps, or if it's two different data set ?

Best regards / Med venlig hilsen
Lars I. Nielsen
GisPro

Tim Rideout

unread,
Jan 10, 2007, 6:48:39 AM1/10/07
to mapi...@googlegroups.com

I have asked about this as well.

At InterGeo in Muenchen in October both ESRI and Bentley Systems were
demonstrating Google Earth being used as a background image within their GIS
system. So if they can do it then it should also be possible somehow in
MapInfo. Does Google provide the imagery in the form of a WMS feed, for
example?

If you need satellite imagery in the short term then you could open up
Global Explorer, I think it is called, within MapInfo by going to the
File>Open Web Mapping Service command. Select it from the list of available
servers. It has complete imagery and some air photos too (e.g. for the USA).
You just have to put up with a diagonal copyright statement plastered on the
image every so often, but I guess that goes away if you sign up for the paid
for version. Anyway, I have used it to get the alignment of the new Lhasa
railway in Tibet, for example.

There is a whole issue here about the terms of use, though. Google is only
for non-commercial use. So much of the things we might want to do with a
Google Earth image are a copyright violation of the image owner. In the
longer term these images are expensive to create and somebody somewhere has
to pay for them, otherwise they will not be created. Neither Google nor
Microsoft are paying their suppliers anywhere near the full cost of the
imagery, so we are all relying on commercial users continuing to buy
imagery, and effectively subsidise Google so we can then get free private
use of it.


Regards

Tim

Dr Tim Rideout
Director

Half Price SkyView Posters at
http://xyzmaps.com/acatalog/skyview_posters.html

Visit XYZ at the International Map Trade Show, Salzburg Feb 23-24th 2007 and
the Cape Town Book Fair 16-19th June 2007.

The XYZ Digital Map Company
Unit 9 Phase 2 Hardengreen Business Park
Dalhousie Road
Dalkeith Scotland EH22 3NX

Tel +44 131 454 0426

Fax +44 131 454 0443

Mobile + 44 7766 825937

E-mail tim.r...@xyzmaps.com

Evan MacDougall

unread,
Jan 10, 2007, 10:22:54 AM1/10/07
to mapi...@googlegroups.com
What your looking for is Google's keyhole product. This provides the
georeferenced Google Earth satellite images as a background layer to
MapInfo.

http://www.keyhole.com/body.php?h=products&t=keyhole2LT

Our company looked into licensing this product, but it was too expensive
for our small budget.

If you're looking for free satellite images for MapInfo, use MapInfo
Pro's WMS Map Servers (MI Pro 8.5).

GlobeXplorer Map Server
Microsoft Terraserver Map Server

Those are two of the WMS servers that provide satellite images for free
to MapInfo and I'm sure a few of the other servers provide them for
other areas as well.

-Evan MacDougall
GIS Supervisor
"Gentlemen, we may not make history tomorrow, but we shall certainly
change the geography."

nicholas....@mainroads.qld.gov.au

unread,
Jan 10, 2007, 5:34:12 PM1/10/07
to mapi...@googlegroups.com
>> How can I make Google Maps or Google Earth into a layer inside MapInfo?
>
>> I looked at "Link Utility for Google Earth" but that one puts mapinfo
>> data into google earth, while I want to go the other way, ie put google
>> earth data into mapinfo.
>
>> Regards,
>> Nick Lawrence

> I'm almost sure Nick Lawrence is interested in bringing in the satellite


> images from Google Earth and not the vector layers on top of it (KML
files).
> Only option seem to be a simple non-georeferenced jpg export.

> Regards
> Uffe Kousgaard

Yes, I want to bring in the satellite images from either google earth or
google maps and display them as a non-editable background raster layer
inside mapinfo. I want a live link so that as I zoom and pan, the
google earth/google maps layer updates itself appropriately.

nicholas....@mainroads.qld.gov.au

unread,
Jan 14, 2007, 9:10:40 PM1/14/07
to mapi...@googlegroups.com
Does there exist an on-line resource for the anatomy of the .tab file?

Specifically I want to create a .tab file that prints a message in the
message window and nothing else.

nick

Lars I. Nielsen (GisPro)

unread,
Jan 15, 2007, 2:09:56 AM1/15/07
to nicholas....@mainroads.qld.gov.au, mapi...@googlegroups.com
Hi Nicholas,

Does it need to be a tab ?

A small workspace file (= a macro) would be a better container:

!Workspace
!Version 300
!Charset WindowsLatin1
Print "This is a message"

Programmatically you execute it this way:

Run Application "....\message1.wor"

Best regards / Med venlig hilsen
Lars I. Nielsen
GisPro


Peter Horsbøll Møller

unread,
Jan 15, 2007, 2:29:23 AM1/15/07
to mapi...@googlegroups.com
Hi,
 
You can do the exact same thing with a tab file.
 
- Create a text file with the extension .tab.
- Write these lines into the file:
 
!table
!version 300
!charset WindowsLatin1
 
Print "This is a table!"
 
- Save the file.
- When you open the file, it will write "This is a table!" in your message window

Peter Horsbøll Møller
GIS Developer, MTM
Geographical Information & IT
 
COWI A/S
Odensevej 95
DK-5260 Odense S.
Denmark
 
Tel     +45 6311 4900
Direct  +45 6311 4908
Mob     +45 5156 1045
Fax     +45 6311 4949
E-mail  p...@cowi.dk
http://www.cowi.dk/gis

 


From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Lars I. Nielsen (GisPro)
Sent: Monday, January 15, 2007 8:10 AM
To: nicholas....@mainroads.qld.gov.au
Cc: mapi...@googlegroups.com
Subject: [MI-L] Re: anatomy of a .tab file

David Reid

unread,
Jan 15, 2007, 3:05:15 AM1/15/07
to mapi...@googlegroups.com
Speaking of printing Message Windows... How does one "clear" the message window of all previous listings?
 
Example:
 
ClearMessageWindow
Print "New Clean Message Window"
 
David


From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Peter Horsbøll Møller
Sent: Monday, January 15, 2007 1:29 AM
To: mapi...@googlegroups.com

--
No virus found in this incoming message.
Checked by AVG Free Edition.

Version: 7.5.432 / Virus Database: 268.16.7/620 - Release Date: 1/8/2007 4:12 PM


--
No virus found in this outgoing message.


Checked by AVG Free Edition.

Version: 7.5.432 / Virus Database: 268.16.7/620 - Release Date: 1/8/2007 4:12 PM

Uffe Kousgaard

unread,
Jan 15, 2007, 3:16:17 AM1/15/07
to mapinfo-l
That is

print chr$(12)

Regards
Uffe

----- Original Message -----
From: David Reid
To: mapi...@googlegroups.com
Sent: Monday, January 15, 2007 9:05 AM
Subject: [MI-L] Re: anatomy of a .tab file

David Reid

unread,
Jan 15, 2007, 3:22:51 AM1/15/07
to mapi...@googlegroups.com
PERFECT!!! Thanks Uffe. I thought I'd seen something on the List long ago
about this but I failed to save it to my local "help files".

Regards,
David

-----Original Message-----
From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On

Behalf Of Uffe Kousgaard
Sent: Monday, January 15, 2007 2:16 AM
To: mapinfo-l
Subject: [MI-L] Re: anatomy of a .tab file


That is

print chr$(12)

Regards
Uffe

----- Original Message -----
From: David Reid
To: mapi...@googlegroups.com
Sent: Monday, January 15, 2007 9:05 AM
Subject: [MI-L] Re: anatomy of a .tab file


Speaking of printing Message Windows... How does one "clear" the message
window of all previous listings?

Example:

ClearMessageWindow
Print "New Clean Message Window"

David


Apenisa Vaniqi

unread,
Apr 11, 2016, 2:21:53 AM4/11/16
to MapInfo-L, nicholas....@mainroads.qld.gov.au
Nick, have you managed to Google Earth into a layer inside MapInfor?......I am trying to do the same, however i am not able to do it

Kind Regards

Apenisa

Juan Berroa

unread,
Apr 11, 2016, 7:00:16 PM4/11/16
to mapi...@googlegroups.com
http://mapperg.com/  does the trick, for an anual subscription.

Juan Pablo Berroa

 



Date: Sun, 10 Apr 2016 19:45:58 -0700
From: anva...@gmail.com
To: mapi...@googlegroups.com
CC: nicholas....@mainroads.qld.gov.au


Subject: [MI-L] Re: Google Maps / Google Earth as a layer in MapInfo

Nick, have you managed to Google Earth into a layer inside MapInfor?......I am trying to do the same, however i am not able to do it

Kind Regards

Apenisa

On Wednesday, January 10, 2007 at 3:28:02 PM UTC+13, nicholas....@mainroads.qld.gov.au wrote:

How can I make Google Maps or Google Earth into a layer inside MapInfo?I looked at "Link Utility for Google Earth" but that one puts mapinfo data


into google
earth, while I want to go the other way, ie put google earth data into
mapinfo.
Regards,
Nick Lawrence

************************************************************
Opinions contained in this e-mail do not necessarily reflect
the opinions of the Queensland Department of Main Roads,
Queensland Transport or Maritime Safety Queensland, or
endorsed organisations utilising the same infrastructure.
If you have received this electronic mail message in error,
please immediately notify the sender and delete the message
from your computer.
************************************************************





--
--
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.

Ben

unread,
Apr 11, 2016, 7:16:49 PM4/11/16
to MapInfo-L
Many thanks Juan, will give it a try

Ben

unread,
Apr 11, 2016, 10:48:53 PM4/11/16
to MapInfo-L
any free download available?


On Tuesday, April 12, 2016 at 11:00:16 AM UTC+12, JuanBerroa wrote:

Ed

unread,
Apr 12, 2016, 4:05:41 AM4/12/16
to MapInfo-L
Hi,

Its not specifically the Google maps raster layer or the satellite imagery, but loading Basemaps add on gives some really good layers. I find the ESRI world imagery satellite photos of better resolution than Google's in some locations in Ireland (less cloud cover, etc).


You can edit the XML to add extra Basemaps and also remove the legend from the maps.

I enclose a sample of some of the maps of a building area of Dublin, Ireland.
Great tool, big kudos to the developer of it!

regards
Ed 
basemaps sample.jpg
Reply all
Reply to author
Forward
0 new messages