Geeks With Blogs

News



Add to Google

Tim Hibbard CEO for EnGraph software

This code will load the MapInfo.Application object into a listbox and display the sample US County data.  It assumes your form has a listbox called listBox1 and a "using System.Reflection;".  It also works in Vista!

string mapName = "C:\\Program Files\\MapInfo\\Professional\\DATA\\Map_Data\\Namerca\\USA\\Usa_Maps\\US_CNTY.TAB"; System.Type oType = System.Type.GetTypeFromProgID("MapInfo.Application"); object o = System.Activator.CreateInstance(oType); oType.InvokeMember("do", BindingFlags.InvokeMethod, null, o, new object[] { "Set Application Window " + listBox1.Handle }); oType.InvokeMember("do", BindingFlags.InvokeMethod, null, o, new object[] { "Set Next Document Parent " + listBox1.Handle + " Style 1" }); oType.InvokeMember("do", BindingFlags.InvokeMethod, null, o, new object[] { "Open Table \"" + mapName + "\"" }); oType.InvokeMember("do", BindingFlags.InvokeMethod, null, o, new object[] { "Map From \"US_CNTY\"" });

It's a little more painful than VB's CreateObject, but it works.

 

Technorati tags: , ,
Posted on Tuesday, January 23, 2007 12:03 PM .NET , Mapping , Vista | Back to top


Comments on this post: C# .NET code to load MapInfo

# re: C# .NET code to load MapInfo
Requesting Gravatar...
Let me read it carefully and i will feedback later
Left by Mohie on Jan 31, 2007 9:08 AM

# re: C# .NET code to load MapInfo
Requesting Gravatar...
Sounds good. I'm curious to see your feedback!
Left by Tim Hibbard on Jan 31, 2007 11:21 AM

# re: C# .NET code to load MapInfo
Requesting Gravatar...
What is BindingFlags?
Left by Hannah on Jul 18, 2007 4:25 PM

# re: C# .NET code to load MapInfo
Requesting Gravatar...
Necesito saber algo sobre el metodo setCallback de MapInfo
Left by Yosveni on Oct 25, 2007 10:16 AM

# re: VB .NET code to load MapInfo
Requesting Gravatar...
it's cool! can you help with the vb.net 2005? thanks
Left by RSVN_TOP on Jan 30, 2008 12:09 PM

# re: C# .NET code to load MapInfo
Requesting Gravatar...
Here is a more cleaner way of doing it.


MapInfo.MapInfoApplication _objMI = new MapInfo.MapInfoApplicationClass();

_objMI = (MapInfo.MapInfoApplication)Marshal.GetActiveObject("MapInfo.Application");

string mapName = "C:\\Program Files\\MapInfo\\Professional\\DATA\\Map_Data\\Namerca\\USA\\Usa_Maps\\US_CNTY.TAB";

string returnValue = _objMI.Eval("Set Application Window " + listBox1.Handle);

returnValue = _objMI.Eval("Set Next Document Parent " + listBox1.Handle + " Style 1");

returnValue = _objMI.Eval("Open Table \"" + mapName + "\"");

returnValue = _objMI.Eval("Map From \"US_CNTY\"");


Left by GIS Hoender on Jul 20, 2009 8:11 AM

# re: C# .NET code to load MapInfo
Requesting Gravatar...
me podrian mandar el codigo en .net .porfavor.
Left by angel on Jun 09, 2010 6:51 PM

# re: C# .NET code to load MapInfo
Requesting Gravatar...
how display ?
Left by quang on Oct 18, 2010 9:30 PM

# re: C# .NET code to load MapInfo
Requesting Gravatar...
Looks very good, and the cleaner version from comments it someones need, bijuterii argint
Left by Surrin on Aug 19, 2011 3:51 AM

# re: C# .NET code to load MapInfo
Requesting Gravatar...
i've tested this code. but it has error.
Retriving the COM class factory for component with CLSID {635EBCC4-0C52-4753-A6D7-D1D28A14FA0} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SEVER_EXEC_FAILURE)).
Have you an idea of this !
Left by studyfirst on Jan 21, 2015 2:49 AM

Your comment:
 (will show your gravatar)


Copyright © Tim Hibbard | Powered by: GeeksWithBlogs.net