MapPoint Forums

MapForums

Community of MapPoint and Bing Maps Users and Developers




Problem calling AddPolyline in C++

This is a discussion on Problem calling AddPolyline in C++ within the Development forums, part of the MapPoint Desktop Discussion category; I'm using Variants for calling MapPoint functions and I'm having all kind of problems when calling the AddPolyline function. Basically ...


Go Back   MapPoint Forums > Map Forums > MapPoint Desktop Discussion > Development

Today's Posts Twitter Feed Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-23-2008
Junior Member
White Belt
 
Join Date: Jul 2008
Posts: 3
Problem calling AddPolyline in C++

I'm using Variants for calling MapPoint functions and I'm having all kind of problems when calling the AddPolyline function.
Basically I create a SafeArray where I store all the locations (2 for this example)
and after that I call the AddPolyline function with that array. When I make that call the program crashes.

Anybody has any idea where it may be the problem?

Thanks

Code:
    Variant oMap;
    Variant oApp;

    OleContainer->Visible = false;

    OleContainer->DestroyObject();
    OleContainer->CreateObject("MapPoint.Map",false);
    oMap  = OleContainer->OleObject;
    oApp =  oMap.Exec (PropertyGet("Application"));


    SAFEARRAY *pSA;
    SAFEARRAYBOUND aDim[1];    // a one dimensional array
    aDim[0].lLbound= 0;
    aDim[0].cElements= 2;
    pSA= SafeArrayCreate(VT_VARIANT,1,aDim);  // create a 1D SafeArray of VARIANTS

    HRESULT hr= S_OK;
    if (pSA != NULL)
    {
      long aLong[1];
      for (long i= aDim[0].lLbound; i< (aDim[0].cElements + aDim[0].lLbound); i++)
      {
          Variant oloc = oMap.Exec ( Function("GetLocation") << 38.8186 << -77.1361 << 0.1  );
          aLong[0]= i;
          if (hr == SafeArrayPutElement(pSA, aLong, &oloc))
          {
               int a=5;
          }
      }
    }

    VARIANT v;
    VariantInit(&v);
    v.vt = VT_BYREF|VT_ARRAY;
//    v.pparray = &pSA;
    v.parray = pSA;

    Variant myShapes2 =  oMap.Exec(PropertyGet("Shapes"));
    myShapes2.Exec ( Function("AddPolyline") << v );

    OleContainer->Visible = true;
    OleContainer->DoVerb(ovShow);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 07-24-2008
Senior Member
Black Belt
 
Join Date: Nov 2004
Location: Belgium
Posts: 2,407
Re: Problem calling AddPolyline in C++

Hi,

Can you tell us what you mean by 'crash'? Do you have an error or exception error? What is the error or error message?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 07-24-2008
Junior Member
White Belt
 
Join Date: Jul 2008
Posts: 3
Re: Problem calling AddPolyline in C++

Quote:
Originally Posted by Wilfried View Post
Hi,

Can you tell us what you mean by 'crash'? Do you have an error or exception error? What is the error or error message?

Thanks for your reply.
I get an error that says 'The parameter is incorrect'
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 07-25-2008
Senior Member
Black Belt
 
Join Date: Nov 2004
Location: Belgium
Posts: 2,407
Re: Problem calling AddPolyline in C++

Hi,

I'm not sure. But you put the address of oLoc to the array (&oLoc), I'm not sure this is correct. Also can you test if oLoc is valid Location? You can do this for example by placing a pushpin with the same oLoc or so.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 08-04-2008
Junior Member
White Belt
 
Join Date: Apr 2006
Posts: 5
Re: Problem calling AddPolyline in C++

This is from one of my mapping integration applications:

Quote:
/*
Sweet Jesus this was a pain in the ass to get right.
MapPoint doesn't want a typical variant array of integers,
rather it wants a variant array of variant objects, with
each variant object holding an integer.

Without this indirection, MapPoint simply throws the
dreaded "The parameter is incorrect" error message.
*/
VARIANT larray_to_varray(long la[], long size = 5) {
#pragma warning(disable: 4267)
#pragma warning(disable: 4018)
COleSafeArray varArray;
DWORD elements[] = { size };
varArray.Create(VT_VARIANT, 1, elements);
for (long i = 0; i < size; i++) {
_variant_t v(la[i]);
varArray.PutElement(&i, &v);
}
return varArray.Detach();
}

Last edited by Eric Frost; 08-12-2008 at 02:02 PM.. Reason: remove offending smilie
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
addpolyline, calling, problem


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
How do I use AddPolyline method in Delphi stephenmillington Development 4 09-20-2007 12:52 PM
Addpolyline from a dataset micheln MapPoint Desktop Discussion 3 05-04-2007 06:49 AM
AddPolyLine (s) array problem FreddyD MapPoint Desktop Discussion 1 12-20-2006 12:45 PM
Shapes.AddPolyline is very slow tdaffin MapPoint Desktop Discussion 4 01-27-2006 07:08 AM
addpolyline Anonymous Wish List 2 04-25-2003 03:50 PM


All times are GMT -5. The time now is 10:56 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.0 RC3
MP2K Magazine
Visitor Map



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