Integrated Mapping and VB.NET

597 views
Skip to first unread message

Phil

unread,
Apr 3, 2012, 4:45:51 AM4/3/12
to MapInfo-L
Hi all,

I have a vb.net application that uses MapInfo integrated mapping and
that ive upgraded from vb6. Everything works fine until I enforce
Option Strict on the code, which generates dozens of errors ("Option
Strict On disallows late binding") for each MapBasic call (MapInfo.Do,
MapInfo.RunMenuCommand, MapInfo.Eval etc) where MapInfo is the MapInfo
object created.

The MapInfo variable has to be declared as an Object, and I know this
is what is causing the problems, but I have no idea how to fix it, I
must be initialising it wrong.

I'm using the following statements:

Dim MapInfo as Object
MapInfo = CreateObject("MapInfo.application")

Does anyone have any ideas?...I would prefer to keep Option Strict on
for good coding practice.

Thanks...

Evil "G"

unread,
Apr 3, 2012, 6:44:50 AM4/3/12
to mapi...@googlegroups.com

 <DllImport("User32", CharSet:=CharSet.Auto, ExactSpelling:=True)> _

    Friend Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndParent As IntPtr) As IntPtr

    End Function

   ''Sets window attributes

    <DllImport("USER32.DLL")> _

   Public Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer

    End Function

   'Gets window attributes

    <DllImport("USER32.DLL")> _

    Public Shared Function GetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer

    End Function

    'assorted constants needed

    Public Shared GWL_STYLE As Integer = -16

    Public Shared WS_CHILD As Integer = &H40000000

    'child window

    Public Shared WS_BORDER As Integer = &H800000

   'window with border

    Public Shared WS_DLGFRAME As Integer = &H400000

    'window with double border but no title

    Public Shared WS_CAPTION As Integer = WS_BORDER Or WS_DLGFRAME

    'window with a title bar

    Public Shared WS_MAXIMIZE As Integer = &H1000000

        Public mapinfo As MapInfo.MapInfoApplication

    Private Sub MapWindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        mapinfo = New MapInfo.MapInfoApplication

        Dim handle As String = mapinfo.Eval("SystemInfo(9)")

        Dim oldhandle As New IntPtr(Convert.ToInt32(handle))

         mapinfo.Visible = True

        ' SetParent(oldhandle, Me.Panel1.Handle)

        SetParent(oldhandle, Me.ToolStripContainer1.ContentPanel.Handle)

        mapinfo.Do("Set Window 1011 Max")

     End Sub

 

Nick

unread,
Apr 3, 2012, 10:35:43 AM4/3/12
to MapInfo-L
Phil,

You should first include a reference to the MapInfo OLE Automation
Library.

I then declare my mapinfo professional instance with this code in
VB.net:

Dim miapp As New MapInfo.MapInfoApplication

That should do the trick.

Phil

unread,
Apr 4, 2012, 8:37:10 PM4/4/12
to MapInfo-L
Thanks guys,

Adding the reference helped expose all the methods, which is much
better than using createobject (which still works). My problem was
that I needed the mapinfo object to have global scope and was unsure
how to set this, as when you declare this Public with createobject it
generates the late binding errors in Option Strict.

Achieved this by:

Public MIApp As MapInfo.MapInfoApplication

and then by setting

MIApp = New MapInfo.MapInfoApplication

at the local level and all works fine in Option Strict

Thanks,
Phil
Reply all
Reply to author
Forward
0 new messages