# How to get the elevation value through the IDSPATCH interface

**URL:** <https://mapwindow.discourse.group/t/how-to-get-the-elevation-value-through-the-idspatch-interface/853>\
**Category:** MapWinGIS\
**Created:** [January 1, 2021, 2:03am UTC](https://mapwindow.discourse.group/t/how-to-get-the-elevation-value-through-the-idspatch-interface/853 "2021-01-01T02:03:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zcwbnu](https://avatars.discourse-cdn.com/v4/letter/z/3da27b/32.png) [@zcwbnu](https://mapwindow.discourse.group/u/zcwbnu)\
**Post date:** [January 1, 2021, 2:03am UTC](https://mapwindow.discourse.group/t/how-to-get-the-elevation-value-through-the-idspatch-interface/853/1 "2021-01-01T02:03:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [January 2, 2021, 7:36am UTC](https://mapwindow.discourse.group/t/how-to-get-the-elevation-value-through-the-idspatch-interface/853/2 "2021-01-02T07:36:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zcwbnu](https://avatars.discourse-cdn.com/v4/letter/z/3da27b/32.png) [@zcwbnu](https://mapwindow.discourse.group/u/zcwbnu)\
**Post date:** [January 3, 2021, 7:09am UTC](https://mapwindow.discourse.group/t/how-to-get-the-elevation-value-through-the-idspatch-interface/853/3 "2021-01-03T07:09:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [January 3, 2021, 7:48am UTC](https://mapwindow.discourse.group/t/how-to-get-the-elevation-value-through-the-idspatch-interface/853/4 "2021-01-03T07:48:45Z")

</div>

Hello again.

Looking at the `IImage interface`, I notice that it has an [OpenAsGrid method](https://www.mapwindow.org/documentation/mapwingis4.9/group __image__ grid__render.html#ga2db8c86e2962a8a2a1fdcd73deb73bf5). 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.

---

<div class="post-metadata">

**Author:** ![zcwbnu](https://avatars.discourse-cdn.com/v4/letter/z/3da27b/32.png) [@zcwbnu](https://mapwindow.discourse.group/u/zcwbnu)\
**Post date:** [January 14, 2021, 12:27pm UTC](https://mapwindow.discourse.group/t/how-to-get-the-elevation-value-through-the-idspatch-interface/853/5 "2021-01-14T12:27:35Z")

</div>

Thank you for your help. The problem has been solved

---

<div class="post-metadata">

**Author:** ![pmeems](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/pmeems/32/9_2.png) [@pmeems](https://mapwindow.discourse.group/u/pmeems)\
**Post date:** [January 10, 2022, 3:28pm UTC](https://mapwindow.discourse.group/t/how-to-get-the-elevation-value-through-the-idspatch-interface/853/6 "2022-01-10T15:28:19Z")

</div>


