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

AddPushPin() throws exception in VC++

This is a discussion on AddPushPin() throws exception in VC++ within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hi, I have a problem adding pushpins to a map using MS VC ++ 6.0. This is my code: theApp.LockMapPointApp(); ...

  1. #1
    radboudp is offline Junior Member White Belt
    Join Date
    Jan 2005
    Posts
    1

    AddPushPin() throws exception in VC++

    Hi,

    I have a problem adding pushpins to a map using MS VC ++ 6.0. This is my code:

    theApp.LockMapPointApp();

    // Create a new pushpin object to represent the antenna:
    pPin = new CPushpin;

    // Open the MapPoint map...
    // theApp.GetMapPointApp() returns a MapPoint.Application object...
    theApp.GetMapPointApp().OpenMap( m_csMapPointFile, FALSE );

    // Find the location where the antenna needs to be placed:
    CLocation loc;
    loc = theApp.GetMapPointApp().GetActiveMap().GetLocation ( dblLatitude, dblLongitude, 0 );

    if ( bCenterOn )
    // Center on the newly added pin...
    loc.GoTo();

    try
    {
    CMap1 map = theApp.GetMapPointApp().GetActiveMap();

    // Add the pushpin and set the name (if any)...
    if ( ! csName.IsEmpty() )
    *pPin = map.AddPushpin( loc, csName );
    else
    *pPin = map.AddPushpin( loc, "<Nameless>" );
    }
    catch ( COleDispatchException *ex )
    {
    dwLastError = ::GetLastError();
    iErrNo = errno;

    ex->GetErrorMessage( szError, 1024 );
    theApp.Log( LOG_MAP_ERROR, m_iId, _T("MapPoint OleDispatchException while adding PushPin: %s"), szError );
    }

    // Save the pushpin reference instance
    ...

    // Do some settings...
    ...

    theApp.UnlockMapPointApp();

    --- End code ---

    It is the "*pPin = map.AddPushpin( loc, csName );" line of code that throws the exception.

    Any kind of help would be appreciated...

    Many thanks,
    Radboud

    PS: Another application using a MappointControl object works just fine...

  2. #2
    Winwaed's Avatar
    Winwaed is offline Mapping-Tools.com Black Belt
    Join Date
    Feb 2004
    Location
    Irving,Texas
    Posts
    1,859
    Blog Entries
    60
    I usually use MapPoint in C++ without MFC.

    I assume csName is an MFC CString?

    The problem might be because the COM interface is expecting its own flavour of string (eg. a BSTR), rather than a 'smart CString object'.

    I've just looked at my code (non-MFC, and using STL), and I pass an STL string to a MapPoint method by converting it to a (const char*). When receiving data (ie. querying a field) I have to go via VARIANTs.

    Note that your hard-coded string constants are also of type (const char*).


    Richard
    Winwaed Software Technology LLC
    http://www.winwaed.com
    See http://www.mapping-tools.com for MapPoint Tools

  3. #3
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137
    Instead of define pPin as a pointer and allocate an object then reassign *pPin as you did.
    ==================
    You would define

    Pushpin JustPin;

    JustPin = map.AddPushpin( loc, (LPCTSTR)csName );

    =====================


    Let me know if this helps.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. addpushpin - need help to get started
    By BWard in forum MapPoint Desktop Discussion
    Replies: 7
    Last Post: 12-19-2005, 03:15 PM
  2. AddPushPin
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 03-01-2004, 11:41 AM
  3. addPushpin
    By nringdahl in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 01-27-2004, 10:09 AM
  4. AddPushpin with more data than Loc and name possible?
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 5
    Last Post: 03-17-2003, 07:11 PM
  5. AddPushpin
    By Monique in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 08-20-2002, 02:26 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