I am trying to use either the express edition of VB.net or C#.net to control MapInfo 7.0. I don’t have any problems connecting to MapInfo and sending commands but get an error as soon as I use the SetCallback method. I have previously used VB6 for integrated mapping and remember having to choose an ActiveX project instead of a typical Windows application. Is there some sort of similar issue with VB.net? I have seen this problem discussed previously but still couldn’t get it to work…

 

Here is a small code sample in VB.

Public Class MI

    Private myMapInfo As new MapInfo.DMapInfo

    Public WithEvents MICB As New MICallBack

 

    Public Sub New()

        With myMapInfo

            .Visible = True

            .SetCallback(MICB) A first chance exception of type 'System.InvalidCastException' occurred in mscorlib.dll” occurs here

        End With

    End Sub

 

    Public Sub DoCommand(ByVal CommandString As String)

        Try

            myMapInfo.Do(CommandString)

        Catch ex As Exception

            'Do something with error here

        End Try

    End Sub

    Public Function EvalCommand(ByVal CommandString As String) As String

        Try

            Dim strResult As String = myMapInfo.Eval(CommandString)

            Return strResult

        Catch ex As Exception

            Return "ERROR"

        End Try

    End Function

 

    Protected Overrides Sub Finalize()

        MICB = Nothing

        myMapInfo = Nothing

        MyBase.Finalize()

    End Sub

End Class

 

Public Class MICallBack

    Public Event WindowChanged()

    Public Event StatusTextChanged()

    Public Event NewMenuCommand()

    Public Event NewToolButtonCommand()

 

    Public Sub WindowContentsChanged(ByVal WinID As UInt32)

        MsgBox(WinID.ToString)

    End Sub

    Public Sub SetStatusText(ByVal StatusText As String)

        MsgBox(StatusText)

    End Sub

    Public Sub MenuCommand(ByVal CmdStr As String)

        MsgBox(CmdStr)

    End Sub

    Public Sub ToolButtonCommand(ByVal CmdStr As String)

        MsgBox(CmdStr)

    End Sub

End Class

 

I have a button that runs this code (for test purposes):

        Dim myMI As New MI

        myMI.DoCommand("Print 1")

 

I would really appreciate it if anybody could help me out with this.

 

Cheers, Dean

 

 

 

 

 

Dean McGowan

GIS Ingenjör

Teknik & Service

Upplands Väsby kommun

[EMAIL PROTECTED]

 

Tel. 08-590 97563

Mobil 073-910 4563

 

_______________________________________________
MapInfo-L mailing list
[email protected]
http://www.directionsmag.com/mailman/listinfo/mapinfo-l

Reply via email to