How to get the elevation value through the IDSPATCH interface

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

Hello @zcwbnu

I’d like to help you with this. I’m first just reviewing your code.

Your IDispatch code appears to be using the IImage interface. This is what is returned by the m_map->get_Image(handle) method.

However, it looks like your code for comparison is using the IGrid interface. So should you instead be using IGrid interface in your IDispatch code? Note that the ID for the Value method in the IGrid interface is 2.

Also, do you have the source code for MapWinGIS. In the source is the IDL file, from which you can easily see the ID’s of the various methods.

We’ll talk more.

Regards,
Jerry.

Hello @jerryfaust
Thank you very much for helping me solve the problem!
I use get_ GetObject function instead of get_ Image function, but still returns the image interface. I found that there was no get_ Grid interface, how can I get igrid interface?

Hello again.

Looking at the IImage interface, I notice that it has an OpenAsGrid method. Below is the method as defined in the IDL file.

[id(83), helpstring("method OpenAsGrid")] HRESULT OpenAsGrid([out, retval] IGrid** retVal);

See if that helps.

Jerry.

Thank you for your help. The problem has been solved