David

Sorry, an important omission in my earlier very sketchy post was the need to
register for COM in the .NET assembly (and, I don't know what's in your
LibPinvokelib.dll). 

Make sure you generate your own GUIds (there's a good reason for this extra
complexity, too). 

There was an explicit example in a MapInfo-L thread here, earlier this year,
where (as I recall, because I haven't searched and confirmed this) it was
remarked that it's important not to create forms within the callback
assembly (as you would expect - can interrupt the OLE process). 

Also VS2005 sometimes baulks at Debug runs - better to build, then run the
EXE separately I think. 

Sorry to be a bit vague, since I used VS2003 and callbacks for a few tests
with MI, about 12 months ago. 

I commonly use .NET with Manifold v6.5 (which is a GIS program that runs
with the .NET Framework v1.1 - v7.0 is .NET Framework v2.0). There aren't
such problems / intricacies involved with Manifold.

You're right - a nice article and code example for using callbacks with MI
is needed. 

Ian Thomas
GeoSciSoft - Perth, Australia

-----Original Message-----
From: David Hebblethwaite [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 01, 2006 8:31 AM
To: [EMAIL PROTECTED]; [email protected]
Subject: Re: [MI-L] Callbacks with VB.NET2005

IL Thomas,

Thanks very much for the information - it has enabled me to get everything 
working except that, while I can extract a value from a MapInfo table and 
display it with the MessageBox.Show function, I cant write to a textbox on 
my VB.NET form. The line that sets the textbox text value appears to do 
nothing - not even an error message (I have removed the Try..Catch code from

the snippet below).

I have included some code snippets below in the hope that you can clear up 
this last thing for me.

David Hebblethwaite


The VB.NET application is called  IntMap

START OF CODE SNIPPET

Public Delegate Sub pMenu(ByVal sCmd As String)

Public Delegate Sub pTool(ByVal sCmd As String)



Public Class clsCallbackWrap

    Declare Sub HandleMenuSelection Lib "..\LibPinvokelib.dll" (ByVal pM As 
pMenu, _

ByVal sCmd As String)

    Declare Sub HandleToolButton Lib "..\LibPinvokelib.dll" (ByVal pT As 
pTool, _

ByVal sCmd As String)

End Class   'clsCallbackWrap









Imports MapInfo



Public Class frmMain



    Public Shared pM As pMenu

    Public Shared pT As pTool



    Public Shared ctlResult As TextBox



    Private Sub frmMain_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

        Dim cCallback As New clsHandleMI



        pM = AddressOf cCallback.HandleMenuSelection

        pT = AddressOf cCallback.HandleToolButton



        gMI.SetCallback(cCallback)



        Dim sTable As String = "MITable"



        gMI.Do("Set Application Window " & Me.Handle.ToString)

        gMI.Do("Set Next Document Parent " & Me.pbxMap.Handle.ToString & " 
Style 1")

        gMI.Do("Open Table """ & sTable & """ Interactive")

        gMI.Do("Map From """ & sTable & """")



        <code to create MapperShortcut menu>



  <code to create custom tool buttons>



        ctlResult = Me.txtResult



COMMENT >     txtResult is a textbox on frmMain to view variable values 
extracted from the MapInfo Window. It is shared as the public object 
ctlResult



    End Sub



End Class   'frmMain













Imports MapInfo

Imports IntMap.frmMain



Public Class clsHandleMI



    Public Sub HandleMenuSelection(ByVal CommandInfoStr As String)

        'This routine determines which menu item was selected, then performs

the

        'appropriate action.



    <code for handling menu actions>



    End Sub





    Public Sub HandleToolButton(ByVal CommandInfoStr As String)

        'This method is called when the custom tools are used in the map 
window.

        Dim iTool As Integer

        Dim x As Double

        Dim y As Double



        'Strip off the 'MI: part of the string

        If Mid$(CommandInfoStr, 1, 3) = "MI:" Then

            CommandInfoStr = Mid$(CommandInfoStr, 4)

            '* determine which tool was used

            iTool = CInt(GetItem(CommandInfoStr, ",", CMD_INFO_TOOLBTN))

            Select Case iTool

                Case 2001

                    'The point info tool

                    x = CDbl(GetItem(CommandInfoStr, ",", CMD_INFO_X)) 
'Get x and y values

                    y = CDbl(GetItem(CommandInfoStr, ",", CMD_INFO_Y)) 
'from CommandInfo



                    frmMain.ctlResult.Text = x



            COMMENT > The line above fails to enter the value of x into the 
textbox on frmMain but the MessageBox.Show function will display it





            End Select

        End If



    End Sub





    Private Function GetItem(ByVal sStr As String, ByVal sDel As String, _

ByVal iItem As Integer) As String

        'sStr is string with items delimited by the sDel character

        'Returns the Item found at Position iItem in the String sStr

    End Function



End Class    'clsHandleMI



END OF CODE SNIPPET








----- Original Message ----- 
From: "SCISOFT" <[EMAIL PROTECTED]>
To: "'David Hebblethwaite'" <[EMAIL PROTECTED]>; 
<[email protected]>
Sent: Tuesday, May 30, 2006 11:55 PM
Subject: RE: [MI-L] Callbacks with VB.NET2005


> David
>
>
>
> This time, it's not MapInfo you should be blaming; it is the syntax in 
> .NET
> interop that you need to get on top of. If you have the MSDN Library, have

> a
> look at Pinvoke and COM, and search for Callbacks.
>
>
>
> There is a very simple example called "Callback Sample" (one place where 
> you
> can see it is on MSDN2 website,
> http://msdn2.microsoft.com/en-us/library/5zwkzwf4.aspx) which explains 
> what
> you need to do.
>
>
>
> Fortunately for VB6 people, the Declare syntax can be used (the 
> alternative
> [ DllImport(PathToSomeDLL)] is mandatory for C#, optional for VB.NET). I
> will paste in the code and article here, for benefit of others who might 
> be
> tempted to try the .NET way "sometime soon".
>
>
>
> Otherwise, it is much the same as you are used to in VB6.
>
>
>
> IL Thomas
> GeoSciSoft  - Perth, Australia
>
>  _____
>
> > From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of David
> Hebblethwaite
> Sent: Tuesday, May 30, 2006 2:17 PM
> To: [email protected]
> Subject: [MI-L] Callbacks with VB.NET2005
>
>
>
> I am trying to get an integrated mapping application working with Mapinfo
> 7.8 and VB.NET2005. I have created similar applications before with VB6 
> and
> MapInfo but I have been unable to get the callback function working with
> vb.NET. I have created a standard Windows project and a class containing 
> the
> methods by which MapInfo notifies the calling program. In the main form I
> create a public instance of the class and call MapInfo's SetCallBack 
> method
> with the instance as the argument. Although I can quite happily control
> MapInfo from the VB.NET program I get no response at all from actions in 
> the
> MapInfo window. I have tried to implement some of the ideas that have
> appeared in MI-L but with no success.  I know I am not the only one with
> this problem. Does anyone know of any rules/steps that will lead to a
> successful implementation of the callback function? I find it hard to
> believe that MapInfo would provide this method without some clear-cut way 
> of
> implementing it. Any advice would be appreciated.
>
>
>
> David Hebblethwaite
>
>
>
> 



-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.8.0/352 - Release Date: 30/05/2006

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

Reply via email to