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 5 of 5

MapPoint hates WM_COPYDATA

This is a discussion on MapPoint hates WM_COPYDATA within the MapPoint Desktop Discussion forums, part of the Map Forums category; I'm developing an app using MP as a TOleContainer in Delphi 5. This works great--I can manipulate just about everything ...

  1. #1
    aroberts is offline Junior Member Yellow Belt
    Join Date
    Nov 2007
    Posts
    12

    MapPoint hates WM_COPYDATA

    I'm developing an app using MP as a TOleContainer in Delphi 5. This works great--I can manipulate just about everything that I need to, programatically. I'm trying to receive parms (Lat & Lon) from a separate application using a WM_COPYDATA handler. This works great, too--I can receive the parms just fine. The problem occurs when I make a call to any MP functions from the message handler itself.

    Apparently, an external call from WM_COPYDATA handers are a no-no. I get a cryptic error (I think from MP) that essentially declares that it has no idea what happened.

    My (inelegant) workaround has been to use a TTimer and a 'message received' flag within the message handler in order to periodically check for new data (which I load from the message handler). Is there a better way to do this? Is there an "after WM_COPYDATA" kind of handler or other notification that someone could recommend? Thanks.

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

    Re: MapPoint hates WM_COPYDATA

    Hi,

    Should word if the custom message handler for WM_COPYDATA is executing in same thread context as where you have created MapPoint class.

    However a more elegant function instead of a Timer wich does the same thing is to use a second custom message handler and post a message to it. The custom message handler will have same effect as the TTimer event.

  3. #3
    aroberts is offline Junior Member Yellow Belt
    Join Date
    Nov 2007
    Posts
    12

    Re: MapPoint hates WM_COPYDATA

    Thanks, that is the kind of solution that I was hoping for. Could you advise with some specifics on how to do it? I'm guessing that I should place a SendMessage (or PostMessage) within the existing WMCOPYDATA handler, but how do I create the handler for that? Will it not call the same handler recursively--or is there a way to differentiate the senders?

    This is a bit new to me, so I apologize for asking what are probably some fundamental questions.

    Thanks again.

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

    Re: MapPoint hates WM_COPYDATA

    Hi,

    Not SendMessage but PostMessage. The difference is that SendMessage will block until the message handler is done and we don't want that. We want it to execute a while later outside the message handler for the copydata as you do with the Timer. Typically it will execute 1 time slice later (10 millisec).

    Here is little example. Compiled but not tested:

    Code:
    const
       WM_MYMESSAGE = WM_USER + 1;
    
    type
      TForm1 = class(TForm)
      private
        procedure WMCopyData(var Msg: TMessage); message WM_COPYDATA;
        procedure WMMyMessage(var Msg: TMessage); message WM_MYMESSAGE;
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    { TForm1 }
    
    procedure TForm1.WMCopyData(var Msg: TMessage);
    var
       CopyData: PCopyDataStruct;
    begin
       // Allocate memory for the struct and make a copy of it
       New(CopyData);
       Move(PCopyDataStruct(Msg.LParam)^, CopyData^, SizeOf(tagCOPYDATASTRUCT));
       PostMessage(Handle, WM_MYMESSAGE, 0, integer(CopyData));
    end;
    
    // This procedure is executed a little later when
    // the message pump for this window is entered
    procedure TForm1.WMMyMessage(var Msg: TMessage);
    var
       CopyData: PCopyDataStruct;
    begin
       CopyData := PCopyDataStruct(Msg.LParam);
       // Here you do the calls to mappoint or whatever
       // Free the allocated memory for the struct
       Dispose(CopyData);
    end;

  5. #5
    aroberts is offline Junior Member Yellow Belt
    Join Date
    Nov 2007
    Posts
    12

    Re: MapPoint hates WM_COPYDATA

    Perfect. Exactly what I needed--Thanks.

Thread Information

Users Browsing this Thread

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

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