Global Navigation Bar

MapInfo Products Knowledge Base


Product: MapX
Version: 3.x/4.x
Platform: All Win32 Platforms
Category: C++

Summary:
Finding Dispatch ID's for object properties in MapX using C/C++.

Question:
How can the DISPID (dispatch ID's) be determined for certain properties in C? For example, the FindFeature Object has no explicit DISPID for it's CenterX and Y properties.

Answer:

The FindFeature object is derived from the feature object in C++. But since OleAutomation does not have the concept of inheritance, the type library doesn't really know that the inherited properties and methods are there. IDispatch method GetIDsOfNames() can be used to retrieve them.

Below is what is done in the C++ wrapper classes for MapX. It is possible to just execute the code once to determine the dispatch id, and then hard code the dispatch id in the future. In this case, it was decided to look it up each time in case it changes in the future. From the mapx.cpp file that is in the MapX cpp sample:

double CMapXFindFeature::GetCenterX()
{
double result;
 DISPID dispid;
 HRESULT hr;
 CString cx = "CenterX";
 BSTR szMember = cx.AllocSysString();
 hr = m_lpDispatch->GetIDsOfNames(IID_NULL, (OLECHAR FAR*FAR*)&szMember, 1,
   0, &dispid);
::SysFreeString(szMember);
GetProperty(dispid, VT_R8, (void*)&result);
return result;
}


double CMapXFindFeature::GetCenterY()
{
double result;
 DISPID dispid;
 HRESULT hr;
 CString cx = "CenterY";
 BSTR szMember = cx.AllocSysString();
 hr = m_lpDispatch->GetIDsOfNames(IID_NULL, (OLECHAR FAR*FAR*)&szMember, 1,
   0, &dispid);
::SysFreeString(szMember);
GetProperty(dispid, VT_R8, (void*)&result);
return result;
}

Attached is list from Development
dispIDS.pdf

Last Modified: 11/08/1999 06:45:56 PM
Global Navigation Bar