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

VC++, OnSelectionChange and LDISPATCH

This is a discussion on VC++, OnSelectionChange and LDISPATCH within the MapPoint Desktop Discussion forums, part of the Map Forums category; VC++ 6.0 MP 2006 ActiveX/COM Hello here I am again, I've a poblem. In OnSelectionChange message, I want to turn ...

  1. #1
    VC_Man is offline Member Green Belt
    Join Date
    Nov 2006
    Posts
    93

    VC++, OnSelectionChange and LDISPATCH

    VC++ 6.0
    MP 2006
    ActiveX/COM

    Hello here I am again,

    I've a poblem. In OnSelectionChange message, I want to turn on/off the balloon of a selected pushpin.
    I managed to get the pushpin object this way:
    Code:
    void CDigiLocDlg::OnSelectionChangeControlMap(LPDISPATCH pNewSelection, LPDISPATCH pOldSelection)
    {
         CPushpin MyPushpin( pNewSelection );
         MyPushpin.SetBalloonState( 0 or 2 );
    }
    To know wether it is a pushpin I've created and saved it in my own DataSet, I check the name of the DataSet by using MyPushpin.
    (Just create a DataSet out of MyPushpin and call DataSet's memberfunction GetName() ). If its name is not "Map", than it's a pushpin of one of my DataSets. If it is "Map" than it's not my pushpin, or shape or something else, but it's an object of Mappoint's map.

    Everything looks fine, but the problem is releasing the pushpin. I've tried MyPushpin.ReleaseDispatch(), Detach or wathever, however I still get that Acces Violation, which means something writes data in a forbidden memory part. I really don't know how to solve that. If somebody can say that ReleaseDispatch is the right one for sure. Than I can check somewhere else.

    I hope somebody with good VC++ and COM skills can help me.
    Thank you.

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

    Re: VC++, OnSelectionChange and LDISPATCH

    Hi,

    Possible pNewSelection is not a pushpin ? To make sure of it I should do an extra check. I dont know VC++ but you sure have something like:

    if (pNewSelection is Pushpin)
    if (Pushpin pp = pNewSelection as Pushpin)

    To check the type of the object. Doing a typecast like you do:
    CPushpin MyPushpin( pNewSelection );
    then the compiler will tread the object as it is a Pushpin no matter if it is something else. So calling a method or property could get you into forbidden memory. Typecast is a good thing but responcability is for the programmer.

  3. #3
    VC_Man is offline Member Green Belt
    Join Date
    Nov 2006
    Posts
    93

    Re: VC++, OnSelectionChange and LDISPATCH

    Hi Wilfried,

    Thank you for your response.
    First, the code below is not a typecasting.
    CPushpin MyPushpin( pNewSelection );
    I've checked the code of Mappoint, and CPushpin has 3 constructors and one of them is: CPushpin::CPushpin( LPDISPATCH lpDispatch );
    Than it automatically attach the pushpin COM to MyPushpin.

    You are right if there is another type of object which is not CPushpin than I'll run into troubles. But pNewSelection has some memberfunctin which also shows the ID of the selected object (ID: Pushpin, Shape etc...). So pNewSelection is not the same as CPushpin, pNewSelection is a pure COM-object with memberfunctions like Invoke, AddRef, Release...

    But to use it you need to attach it with a CPushpin object, or CShape object or whatever.

    I've solved the problem I had, you simply do:
    Code:
    CPushpin pushpin;
    pushpin.AttacheDispatch(pNewSelection);
    //Do something with it
    //And than release it:
    pNewSelection = pushpin.DetachDispatch();
    Perhaps I need to write an article about that for VC++, because MS don't really care about C++.

  4. #4
    VC_Man is offline Member Green Belt
    Join Date
    Nov 2006
    Posts
    93

    Re: VC++, OnSelectionChange and LDISPATCH

    VC++ 6.0
    Mappoint2006

    Hello guys,

    I still have an exception problem of Mappoint.
    I have used only MapControl, which I get it when I import Mappoint as a COM in VisualStudio (with VC++ 6.0 ). I start up and do nothing with it, than close my app. Again exception from MAppoint arise with exit code 20 (0x14).

    I really don't know how to solve that, so if someone with good C++ and COM skills can help me, than I'll buy you a drink

    Please help me.

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

    Re: VC++, OnSelectionChange and LDISPATCH

    Hi,

    Thanks for feedback. The article is a good idea
    Sorry have no idea about the last problem

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VC++ OnSelectionChange event
    By MP2KUser2 in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 10-13-2004, 02:24 PM
  2. OnSelectionChange VC++
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 05-05-2004, 03:00 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