Hello Christian (list), You answered my previous question on callbacks, so I hope you don't find it rude that I ask you one more.
I have the callback up and running and manage to get the "click" event in MapInfo into a msgbox. I am also able to show the statustext on the statusbar. However, When I store the returnd X and Y coordinates from the callback in a variable and call another form with it, my newly opened form hangs. I have been searching myself a roundtrip in the world of threading, invoke and marshalling, but I cannot get it running. Any ideas of how I can make the callback function end up in the same thread as my main application? Kind regards, Milo van der Linden -----Oorspronkelijk bericht----- Van: AVD-ICT Milo van der Linden [mailto:[EMAIL PROTECTED] Verzonden: woensdag 1 maart 2006 11:35 Aan: 'Christian Singer'; '[email protected]' Onderwerp: SUM: [MI-L] Callback in vb.net Thank you Christian! What you described did the trick. At first I still received errors, but when I did the class library - Windows aplication switch, everything worked just fine! I appreciate the solution, thanks again! Milo van der Linden -----Oorspronkelijk bericht----- Van: Christian Singer [mailto:[EMAIL PROTECTED] Verzonden: dinsdag 28 februari 2006 10:57 Aan: [email protected] CC: [EMAIL PROTECTED] Onderwerp: Re: [MI-L] Callback in vb.net At 13:23 24.02.2006 +0100, Milo van der Linden wrote: >Hello list. > >I created a nice integrated mapping solution in vb.net, with this I can >- Open a workspace >- Zoom in/Zoom out >- Resize my Mapwindow > >What you need to do in VS 2005 is: >1. Add a picturebox to a form >2. Dock this picturebox to the form > >And then implement the following sample code to the form ... >I am now at the point where I want to responde to a mouse click in my >Mapwindow for this I try to use a callback: > >Mycallback is a class I created. However, with no change I can get this >class to respond to SetStatusText and WindowChanged > >Is there anybody that knows if there are some things I am ovelooking? > Even though I'm not quite sure as to what the problem exactly is with your callback function (was not included in your sample code), here is the complete code for a very simple Visual Basic .NET app, using two MI OLE callback functions (receiving status text and custom tool input event notification): Form1 contains the map window (PictureBox, "pbMap") and a text box ("tbStatus"), displaying the contents of the status line. ''''''''''''' Begin of VBN code ''''''''''''''''''''''''''''''''''' Public Class Form1 ' The MapInfo OLE object: Private mi As Object ' The object implementing the COM/OLE2 automation server as ' the target of the callbacks originating from the MI OLE object: Private comServObj As New ComClass1 ' A shared object reference to the status text control for ' later access within the status text callback function: Public Shared tbStatObj As Object Public Sub New() ' Initialize main form (built with VS Form Designer): InitializeComponent() ' Save persistent (shared) obj ref to status text control: tbStatObj = Me.tbStatus ' Create and configure the MI COM object, open a map etc.: mi = CType(CreateObject("MapInfo.Application"), MapInfo.DMapInfo) mi.do("Set Application Window " & CType(Me.pbMap.Handle, String)) mi.do("Set Next Document Parent " & CType(Me.pbMap.Handle, String) _ & " Style 1") mi.do("Open Table ""c:\maps\world.tab"" Interactive Map From World") mi.Do("Set Map Display Position") mi.Do("Create Buttonpad ""SelectGeneric"" As Toolbutton ID 785 " _ & "DrawMode 34 Cursor 134 Calling OLE ""SelectGeneric""") mi.Do("Run Menu Command ID 785") mi.SetCallback(comServObj) End Sub End Class ' Register this class as a COM/OLE2 class: <ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _ Public Class ComClass1 ' Unique IDs for this COM app interface: Public Const ClassId As String = "9CC9946D-C1E4-4f42-9E8C-C4693BD04577" Public Const InterfaceId As String = "CC6697F7-968D-47dc-9B5B-84DEF8FD5D6B" Public Const EventsId As String = "2A765F7E-E628-4427-A730-A695543EDB79" Public Sub New() MyBase.New() End Sub ' Callback function receiving the contents of the MapInfo status line, ' when changed: Public Sub SetStatusText(ByVal strStatus As String) ' Show status line text in text box: CType(Form1.tbStatObj, Control).Text = strStatus End Sub ' Callback function for notification of user input events ' generated by the custom tool (ID 785, see above): Public Sub SelectGeneric(ByVal str As String) MessageBox.Show("A user input event occurred with the parameters:" _ & vbCrLf & str, "MI Custom Tool Callback") End Sub End Class ''''''''''''' End of VBN code ''''''''''''''''''''''''''''''''''' This has been tested with Visual Studio 2005 / .NET Framework 2.0 However, this application does not run properly in debugging mode (started with F5), so must be started either from outside the VS environment or with Ctrl-F5. In the 'Project settings ...' > 'Compile options' you have to activate the 'Register for COM Interop' option. Unfortunately, this option is disabled for standard Windows programs, so you might have to switch to the project type 'class library' first, then set this option, and then again change the project type to 'Windows EXE'. Regards, Christian Singer Ing.-Büro Christian Singer Singerhoffstr. 14 44225 Dortmund Germany E-mail: [EMAIL PROTECTED] WWW : www.icsinger.de Phone : +49 231 791464 Fax : +49 231 791460 _______________________________________________ MapInfo-L mailing list [email protected] http://www.directionsmag.com/mailman/listinfo/mapinfo-l
