| | Eric Frost 03-26-2005, 05:13 PM MapPoint Automation with C/C++ - Part 1
This is the first of three articles by Sergey Kostrov on automating MapPoint Automation with C/C++ starting with a simple C/C++ application.
Read the full article here --
http://www.mp2kmag.com/a122--c-c++.automation.ole.mappoint.html
To post a comment or question click "Post Reply" Hans W 04-15-2005, 08:41 AM Thanks for the code sample. Why Microsoft does not do a C++ or MFC example baffles me. !
It would be great to get a code sample that allows true integration in my porgram. i.e. a map display within my UI.
Hans W Anonymous 04-23-2005, 08:46 PM Hans W wrote some time ago:
"...It would be great to get a code sample that allows true integration in my porgram. i.e. a map display within my UI..."
You can integrate MapPoint functionality in two different ways and it's not difficult:
- with ActiveX MapPoint control ( it can be used with VB, pure C++, MFC etc );
- or, if your application is using only MFC, and you want to use MapPoint automation, try to use CHtmlEditView class.
Best regards,
Sergey Anonymous 04-27-2005, 12:52 PM Thanks for the article.
It is on track for what I wanted to do.
But the problem I am having is that I can't get the code sample to run correctly. All works fine until the program exits (after the ConUninitialize()). At this time I get a trap in _Release() accessing m_pInterface. m_pInterface has a non-NULL value but appears to be invalid.
I believe it may be due to not having a myMapPtr->Release(), as well as other object releases.
I have tied this, but I have not found the right combination (if indeed this is the problem).
Any insights as to what is happening or how to diagnose this problem? Anonymous 05-12-2005, 12:37 PM My response is related with COM exception ( 0xC0000005 ) at the end of execution MapPoint test application described in article ( Part 1 )...
Unhandled exception 0xC0000005 "Access Violation" happens because:
- all your COM objects were released after g_pMapPoint->Quit() was executed;
- but, pointers to COM objects you worked with are still NOT NULL.
You can fix it in a very simple way:
...
myMapPtr->Saved = true;
try
{
if( g_pMapPoint != NULL )
{
g_pMapPoint->Quit();
}
}
catch( ... ){}
resultsPtr = NULL;
locAddressPtr = NULL;
pinAddressPtr = NULL;
myMapPtr = NULL;
g_pMapPoint = NULL;
CoUninitialize();
}
I tested it and everything is fine now.
Best regards,
Sergey Anonymous 05-12-2005, 12:40 PM Don't forget to add this statement: using namespace MapPoint...
So, it should look like:
#include "ComInterfaces.h"
using namespace MapPoint; // <<--
MapPoint::_ApplicationPtr g_pMapPoint = NULL;
void main(void)
{
CoInitialize(NULL);
...
}
Best regards,
Sergey rules 08-31-2005, 06:29 PM I receive this error while compiling the demo:
error C2664: 'FindAddressResults' : cannot convert parameter 6 from 'enum MapPoint::GeoCountry' to 'const class _variant_t &'
Reason: cannot convert from 'enum MapPoint::GeoCountry' to 'const class _variant_t'
No constructor could take the source type, or constructor overload resolution was ambiguous
I have european version so i load MPEU82.tlb instead of MPNA82.tlb, but i think this is not important.
Where can i find help about the methods i can call with mapPoint? I mean, how can i know how to use the FindAddressResults method or anyone else? Is there any documentation about using this API?
Thanks a lot rules 08-31-2005, 06:41 PM I want to make an application that gets a list of nearby places in text mode (given a long/lat position) and also gets an image map of that point. I know it must be very simple but i'm new on this and i don't know where to begin..
Thanks again! rules 08-31-2005, 08:20 PM I solved the problem mentioned above 'FindAddressResults' : cannot convert parameter 6 from 'enum MapPoint::GeoCountry' to 'const class _variant_t &' by removing the geoCountryDefault argument in the example code leaving the code like this:
FindResultsPtr resultsPtr = myMapPtr->FindAddressResults
(
“400 Coronado Dr”, “Denton”, "", “TX”, “76209”
);
So now it compiles, but when i hit the "Build MapPointApp.exe" option in Microsoft Visual c++ 6, it gives me lots of errors
Linking...
MapPointApp.obj : error LNK2001: unresolved external symbol "public: long __thiscall MapPoint::_Application::Quit(void)" (?Quit@_Application@MapPoint@@QAEJXZ)
MapPointApp.obj : error LNK2001: unresolved external symbol "public: void __thiscall MapPoint::_Map::PutSaved(short)" (?PutSaved@_Map@MapPoint@@QAEXF@Z)
MapPointApp.obj : error LNK2001: unresolved external symbol "public: long __thiscall MapPoint::Pushpin::Delete(void)" (?Delete@Pushpin@MapPoint@@QAEJXZ)
MapPointApp.obj : error LNK2001: unresolved external symbol "public: long __thiscall MapPoint::_Map::SaveAs(class _bstr_t,enum MapPoint::GeoSaveFormat,short)" (?SaveAs@_Map@MapPoint@@QAEJV_bstr_t@@W4GeoSaveFor mat@2@F@Z)
MapPointApp.obj : error LNK2001: unresolved external symbol "public: long __thiscall MapPoint::_Map::ZoomIn(void)" (?ZoomIn@_Map@MapPoint@@QAEJXZ)
MapPointApp.obj : error LNK2001: unresolved external symbol "public: long __thiscall MapPoint::Location::GoTo(void)" (?GoTo@Location@MapPoint@@QAEJXZ)
MapPointApp.obj : error LNK2001: unresolved external symbol "public: void __thiscall MapPoint::Pushpin::PutHighlight(short)" (?PutHighlight@Pushpin@MapPoint@@QAEXF@Z)
MapPointApp.obj : error LNK2001: unresolved external symbol "public: void __thiscall MapPoint::Pushpin::PutBalloonState(enum MapPoint::GeoBalloonState)" (?PutBalloonState@Pushpin@MapPoint@@QAEXW4GeoBallo onState@2@@Z)
MapPointApp.obj : error LNK2001: unresolved external symbol "public: void __thiscall MapPoint::Pushpin::PutSymbol(short)" (?PutSymbol@Pushpin@MapPoint@@QAEXF@Z)
MapPointApp.obj : error LNK2001: unresolved external symbol "public: class _com_ptr_t<class _com_IIID<struct MapPoint::Pushpin,&struct __s_GUID _GUID_34b0f619_37e1_4c76_a6da_69bf75a5d3de> > __thiscall MapPoint::_Map::AddPushpin(struct MapPoint::Loca
tion *,class _bstr_t)" (?AddPushpin@_Map@MapPoint@@QAE?AV?$_com_ptr_t@V?$ _com_IIID@UPushpin@MapPoint@@$1?_GUID_34b0f619_37e 1_4c76_a6da_69bf75a5d3de@@3U__s_GUID@@A@@@@PAULoca tion@2@V_bstr_t@@@Z)
MapPointApp.obj : error LNK2001: unresolved external symbol "public: class _com_ptr_t<class _com_IIID<struct IDispatch,&struct __s_GUID _GUID_00020400_0000_0000_c000_000000000046> > __thiscall MapPoint::FindResults::GetItem(struct tagVARIANT *)" (?G
etItem@FindResults@MapPoint@@QAE?AV?$_com_ptr_t@V? $_com_IIID@UIDispatch@@$1?_GUID_00020400_0000_0000 _c000_000000000046@@3U__s_GUID@@A@@@@PAUtagVARIANT @@@Z)
MapPointApp.obj : error LNK2001: unresolved external symbol "public: class _com_ptr_t<class _com_IIID<struct MapPoint::FindResults,&struct __s_GUID _GUID_188084cf_db96_482b_97a6_2571df9bef81> > __thiscall MapPoint::_Map::FindAddressResults(class _bs
tr_t,class _bstr_t,class _bstr_t,class _bstr_t,class _bstr_t,class _variant_t const &)" (?FindAddressResults@_Map@MapPoint@@QAE?AV?$_com_p tr_t@V?$_com_IIID@UFindResults@MapPoint@@$1?_GUID_ 188084cf_db96_482b_97a6_2571df9bef81@@3U__s_GUID@@ A@@@@V_bstr
_t@@0000ABV_variant_t@@@Z)
MapPointApp.obj : error LNK2001: unresolved external symbol "public: class _com_ptr_t<class _com_IIID<struct MapPoint::_Map,&struct __s_GUID _GUID_90b167c0_923d_4b65_aee2_66938491c916> > __thiscall MapPoint::_Application::GetActiveMap(void)" (?GetAc
tiveMap@_Application@MapPoint@@QAE?AV?$_com_ptr_t@ V?$_com_IIID@U_Map@MapPoint@@$1?_GUID_90b167c0_923 d_4b65_aee2_66938491c916@@3U__s_GUID@@A@@@@XZ)
MapPointApp.obj : error LNK2001: unresolved external symbol "public: void __thiscall MapPoint::_Application::PutUnits(enum MapPoint::GeoUnits)" (?PutUnits@_Application@MapPoint@@QAEXW4GeoUnits@2 @@Z)
MapPointApp.obj : error LNK2001: unresolved external symbol "public: void __thiscall MapPoint::_Application::PutCaption(class _bstr_t)" (?PutCaption@_Application@MapPoint@@QAEXV_bstr_t@@ @Z)
MapPointApp.obj : error LNK2001: unresolved external symbol "public: void __thiscall MapPoint::_Application::PutWindowState(enum MapPoint::GeoWindowState)" (?PutWindowState@_Application@MapPoint@@QAEXW4GeoW indowState@2@@Z)
MapPointApp.obj : error LNK2001: unresolved external symbol "public: void __thiscall MapPoint::_Application::PutVisible(short)" (?PutVisible@_Application@MapPoint@@QAEXF@Z)
Debug/MapPointApp.exe : fatal error LNK1120: 17 unresolved externals
Error executing link.exe.
MapPointApp.exe - 18 error(s), 0 warning(s)
Please, can anyone help me? I know if i get this code to work i could do my own but damn Murphy's Law, DAMN IT!! frankliu 09-12-2005, 02:45 PM Hi, Sergey,
I tried to integrate your example to my CDialog derived class, but always get compiling error like this:
...\source\debug\mpna82.tli(16) : error C2653: '_Application' : is not a class or namespace name
Any idea what's going on with my application?
I alsoe tried to insert a MapPointControl OCX object into my class, but it crashed when I tried to call the OpenMap() method.
Appreciate your help.
Frank edlogic 09-15-2006, 10:01 AM i was getting errors on all of the params for FindAddressResults - it wanted _bstr_t instead of strings and a _variant_t instead of int
to fix the FindAddressResults problem i did this ->
_bstr_t bstrStreet("400 Coronado Dr");
_bstr_t bstrCity("Denton");
_bstr_t bstrOtherCity("400 Coronado Dr");
_bstr_t bstrRegion("TX");
_bstr_t bstrPostalCode("76209");
VARIANT vtGeoCountryDefault;
VariantInit( &vtGeoCountryDefault );
V_VT(&vtGeoCountryDefault) = VT_I4;
V_I4(&vtGeoCountryDefault) = geoCountryDefault;
FindResultsPtr resultsPtr = myMapPtr->FindAddressResults
(
bstrStreet, bstrCity, bstrOtherCity, bstrRegion, bstrPostalCode, &vtGeoCountryDefault
); | |