Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 6 of 6

C# Late Binding Application

This is a discussion on C# Late Binding Application within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hi, didn't find anything like that here but here some kinky different way to do things. Maybe some of you ...

  1. #1
    jasanite is offline Member Yellow Belt
    Join Date
    Jul 2007
    Posts
    45

    C# Late Binding Application

    Hi,
    didn't find anything like that here but here some kinky different way
    to do things. Maybe some of you can use it, but use it wise.

    using System.Reflection;

    Get MapPoint:
    object mapPoint = Activator.CreateInstance(Type.GetTypeFromProgID("M apPoint.Application.EU.13"));

    Now you can work with it, unless it's the right Id ^^

    Get a Property:
    object activeMap = mapPoint.GetType().InvokeMember("ActiveMap", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, mapPoint, new object[0]);

    Call a Method:
    object results = activeMap.GetType().InvokeMember("FindAddressResul ts", BindingFlags.InvokeMethod | BindingFlags.OptionalParamBinding, null, activeMap, new object[6] { "Musterweg", "Stuttgart", "", "", "", "Deutschland" });

    Set a Property:
    activeMap.GetType().InvokeMember("Saved", BindingFlags.SetProperty, null, activeMap, new object[1] { true });

    Let's get dirty

  2. #2
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: C# Late Binding Application

    Hi,

    Thanks for sharing. Can you come up with an idea where this can be interesting or even encouraged ?

  3. #3
    jasanite is offline Member Yellow Belt
    Join Date
    Jul 2007
    Posts
    45

    Re: C# Late Binding Application

    It's usefull if you just want to have data from MapPoint without
    the connection to your controls.
    You don't have to reference MapPoint in your project and it's
    quite direct an simple to programm.
    Bad Point: long instructions

    (Needed to display the Map on a Floating Panel so this was
    a dead end at that part, if some of you know how to connect
    it with a control just post it, i didn't had the time to test or
    search)

  4. #4
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: C# Late Binding Application

    hi,

    thanks for clarifying. I do not understand the reason completely. Can you enlighten some more ? This can be interesting to put on the FAQ.

  5. #5
    jasanite is offline Member Yellow Belt
    Join Date
    Jul 2007
    Posts
    45

    Re: C# Late Binding Application

    Hmm i'm no Pro so i do not know ^^
    ...
    I think you asked why i tried to Late Binded it ...
    Scenario:
    Want to use MapPoint if the Client has MP2006
    and don't even want to show him the options
    of using it if not. Like a feature.
    Now, if i reference it in the project (c# visual studio
    2005) an compile it and execute it on another
    pc that doesn't have mp2006, it crashs on start-up.
    This is as far as i understood the Problem.
    If i late binde it, and catch the problematic parts
    (when i make an instance of mp or call it) in try-catch
    blocks, i can prevent the application from crashing.

    The code above uses Late Binding and you don't
    have to visualize it, hang mp in a form, etc..
    You just need the Distance or DrivingTime, just call it
    with the functions above. But beware, long instuctions
    if you don't encapsule them your code will explode. ^^

    Btw. MapPoint ocx is a b****, had to enbedd it in a
    form to prevent it from closing dirty, like "save-popup"
    at different states of the closing-mainform, mp-crash
    at the end of my application ... just learned 1 thing
    from it, give it a form, hide it, use it, give the control
    back to the form before closing other forms and let
    the form kill the mp ocx .... confusing ...

    (just updated the segment info in my table after optimizing,
    directions list (of the route) didn't have the last waypoint
    of the route and other kinky ways of saving stuff.
    Needed a 2-while-algo to just get the distance an time
    between the waypoints ... not very clever done)

  6. #6
    MapAdmin is offline Senior Member Green Belt
    Join Date
    Sep 2007
    Posts
    106

    Re: C# Late Binding Application

    We published an article on Late Binding on MP2K Magazine --

    Richard Marsden shows how to call MapPoint from C# using late binding or dynamic invocation. Late binding has a number of advantages in certain scenarios including being about to support multiple type libraries.

    "There are a number of articles on MP2K Magazine about using MapPoint from a variety of different languages. Most if not all of these articles use early binding to reference the MapPoint COM objects, because this is usually the easiest way of working with COM and it tends to be safer due to compiler checking. Early binding is also slightly faster due to all the references being hard-coded. However there are times when late binding might be more appropriate. This article shows you how to call MapPoint from C# using late binding. Late binding is also known as "dynamic invocation".

    Calling MapPoint from C# with Late Binding - MapPoint Articles - MP2K Magazine


    Eric

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Application cannot call MP
    By joe1156 in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 05-24-2007, 08:29 AM
  2. Sample application in c#
    By alt-088 in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 09-16-2004, 04:35 PM
  3. Cant See Mappoint.Application from VB
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 04-15-2004, 11:15 AM
  4. Can a MapPoint control be conditionall loaded or late bound?
    By frankp in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 02-28-2004, 10:50 PM
  5. Pb with another application
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 12-17-2002, 04:53 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96