I got the IDISPATCH interface of the elevation image and found that the Value attribute ID is 13, but the elevation result is always -1. Below is my code:
LPDISPATCH lpDispatch = m_map->get_Image(handle);
UINT count;
lpDispatch->GetTypeInfoCount(&count); //count = 1
DISPID ValueID[3];
BSTR ValueName[3];
ValueName[0] = SysAllocString(L"Value"); //
ValueName[1] = SysAllocString(L"row");
ValueName[2] = SysAllocString(L"col");
lpDispatch->GetIDsOfNames(
IID_NULL, //
ValueName, //
3, //
LOCALE_SYSTEM_DEFAULT,
ValueID); //DISPID is {13,0,1}
CComVariant m_result;
CComVariant m_param[2];
int height = -99;
m_param[0].vt = VT_I4;
m_param[0].iVal = 800;
m_param[1].vt = VT_I4;
m_param[1].iVal = 800;
DISPPARAMS dispparamsNoArgs = { m_param, NULL,2, 0 };
HRESULT rs = lpDispatch->Invoke(ValueID[0], //DISPID is 13
IID_NULL, //
GetUserDefaultLCID(),
DISPATCH_PROPERTYGET, //
&dispparamsNoArgs, //
&m_result, //
NULL, //
NULL); //
if (SUCCEEDED(rs))
{
m_height = m_result.intVal; //m_height always -1
}
The invoke function returns OK, but the elevation value is wrong.
The correct elevation can be obtained by the following method, but I can only use the IDSPATCH interface
IGridPtr img;
if (img->Open((_bstr_t)path, GridDataType::LongDataType, false, GridFileType::GeoTiff,NULL))
{
layerHandle = m_WinMap.AddLayer(img, true);
}
int h = img->Value[800][800]; //correct