# Windows .NET SDK - IVideoSettingsContext Events

**URL:** <https://devforum.zoom.us/t/windows-net-sdk-ivideosettingscontext-events/2797>\
**Category:** Windows\
**Created:** [December 21, 2018, 7:11am UTC](https://devforum.zoom.us/t/windows-net-sdk-ivideosettingscontext-events/2797 "2018-12-21T07:11:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cfrost](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/cfrost/32/152_2.png) [@cfrost](https://devforum.zoom.us/u/cfrost)\
**Post date:** [December 21, 2018, 7:11am UTC](https://devforum.zoom.us/t/windows-net-sdk-ivideosettingscontext-events/2797/1 "2018-12-21T07:11:16Z")

</div>

I’m having trouble getting the event to fire in the IVideoSettingContext wrapper. This is my implementation:

```
// video_setting_context_wrap.h
class ISettingServiceWrap;
IVideoSettingContext* InitIVideoSettingContextFunc(IVideoSettingContextEvent* pEvent, ISettingServiceWrap* pOwner);
void UninitIVideoSettingContextFunc(IVideoSettingContext* obj);
BEGIN_CLASS_DEFINE_WITHCALLBACK(IVideoSettingContext, IVideoSettingContextEvent)
NORMAL_CLASS(IVideoSettingContext)
INIT_UNINIT_WITHEVENT_AND_OWNSERVICE(IVideoSettingContext, ISettingServiceWrap)

// function definitions omitted for brevity

CallBack_FUNC_1(onComputerCamDeviceChanged, IList*, pNewCameraList)

END_CLASS_DEFINE(IVideoSettingContext)
END_ZOOM_SDK_NAMESPACE

// video_setting_context_wrap.cpp
IVideoSettingContext* InitIVideoSettingContextFunc(IVideoSettingContextEvent* pEvent, ISettingServiceWrap* pOwner)
{
	if (pOwner && pOwner->GetSDKObj())
	{
		ZOOM_SDK_NAMESPACE::IVideoSettingContext* pObj = pOwner->GetSDKObj()->GetVideoSettings();
		if (pObj)
		{
			// the following returns SDKERR_SUCCESS
			pObj->SetVideoDeviceEvent(pEvent);
		}

		return pObj;
	}

	return NULL;
}

void UninitIVideoSettingContextFunc(IVideoSettingContext* pObj)
{
	if (pObj)
	{
		pObj->SetVideoDeviceEvent(NULL);
	}
}
```

I originally asked this question via email and received this response, which I have some questions about:

From the snippet code, we assume that Lenovo is using the same macro\_define.h as we do. The most possible reason that the callback event is not fired is that they didn’t wrap the class IVideoSettingContext in a right way. This class should be wrapped in another way. Here is the code snippet for how to wrap IVideoSettingContext. The code also works for IAudioSettingContext.

1. Make sure to have following codes at the beginning of the video\_setting\_context\_wrap.h. ( Note that we can not use the macro INIT\_UNINIT\_WITHEVENT\_AND\_OWNSERVICE here)

```
class ISettingServiceWrap;
IVideoSettingContext* InitIVideoSettingContextFunc(IVideoSettingContextEvent* pEvent, ISettingServiceWrap* pOwner);
void UninitIVideoSettingContextFunc(ISettingServiceWrap* obj);
BEGIN_CLASS_DEFINE_WITHCALLBACK(IVideoSettingContext, IVideoSettingContextEvent)
NORMAL_CLASS(IVideoSettingContext)
void Init(ISettingServiceWrap* pOwner) {m_obj = InitIVideoSettingContextFunc(this, pOwner);};
void Uninit(ISettingServiceWrap* pOwner) {UninitIVideoSettingContextFunc(pOwner);m_obj=NULL;};
```

1. Make sure to implement the function InitIVideoSettingContextFunc() in video\_setting\_context\_wrap.cpp

```
IVideoSettingContext* InitIVideoSettingContextFunc(IVideoSettingContextEvent* pEvent, ISettingServiceWrap* pOwner)
{
	if (pOwner && pOwner->GetSDKObj())
	{
		pOwner->SetVideoDeviceEvent(pEvent);
		ZOOM_SDK_NAMESPACE::IVideoSettingContext* pObj = pOwner->GetSDKObj()->GetVideoSettings();

		return pObj;
	}

	return NULL;
}

void UninitIVideoSettingContextFunc(ISettingServiceWrap* pOwner)
{
	if (pOwner)
	{
		pOwner->SetEvent(NULL);
	}
}
```

In the InitIVideoSettingContextFunc function, you’re calling pOwner-\>SetVideoDeviceEvent(pEvent). In this case pOwner is a pointer to ISettingServiceWrap, which doesn’t contain the function SetVideoDeviceEvent, it’s defined instead for IVideoSettingContext, so I don’t see how this can work.

---

<div class="post-metadata">

**Author:** ![Wilmer\_Sun](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/wilmer_sun/32/61_2.png) [@Wilmer\_Sun](https://devforum.zoom.us/u/Wilmer_Sun)\
**Post date:** [December 22, 2018, 9:21am UTC](https://devforum.zoom.us/t/windows-net-sdk-ivideosettingscontext-events/2797/3 "2018-12-22T09:21:41Z")

</div>

@cfrost

Thanks for pointing out the mistake! When I wrote those snippet code, I haven’t VS2015 with me and didn’t test it. Sorry about that!

You are right, we should use pOwner-\>GetSDKObj()-\>SetVideoDeviceEvent(pEvent) to set the event handler. It seems that your wrapper has nothing wrong.

There is another reason that the callback isn’t fired. Do you call the CVideoSettingContextDotNetWrap::BindEvent() anywhere? It’s better to call it in the function GetVideoSettings().

If it still does’t work, please let me know. I will try to find out the reason next week.

Regards,  
Wilmer

---

<div class="post-metadata">

**Author:** ![cfrost](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/cfrost/32/152_2.png) [@cfrost](https://devforum.zoom.us/u/cfrost)\
**Post date:** [December 22, 2018, 6:51pm UTC](https://devforum.zoom.us/t/windows-net-sdk-ivideosettingscontext-events/2797/4 "2018-12-22T18:51:25Z")

</div>

No worries, I thought that might be the case.

I do call BindEvent in GetVideoSettings(), and the binding appears to be working.

```
IVideoSettingContextDotNetWrap^ CSettingServiceDotNetWrap::GetVideoSettings()
{
	if (CVideoSettingContextDotNetWrap::Instance)
	{
		CVideoSettingContextDotNetWrap::Instance->BindEvent();
	}

	return CVideoSettingContextDotNetWrap::Instance;
}
```

I appreciate any guidance you can provide.

---

<div class="post-metadata">

**Author:** ![Wilmer\_Sun](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/wilmer_sun/32/61_2.png) [@Wilmer\_Sun](https://devforum.zoom.us/u/Wilmer_Sun)\
**Post date:** [December 25, 2018, 5:40am UTC](https://devforum.zoom.us/t/windows-net-sdk-ivideosettingscontext-events/2797/5 "2018-12-25T05:40:30Z")

</div>

Well, the root cause is that the ISettingServiceWrap is initialized at a wrong place. The setting service only can be initialized successfully once the authentication of zoom sdk is passed.

In zoom\_sdk\_dotnet\_wrap.cpp, remove the following code from the function InitAllService()  
ZOOM\_SDK\_NAMESPACE::CSDKWrap::GetInst().GetSettingServiceWrap().Init();

In auth\_service\_dotnet\_wrap.cpp, add the following code to the success case in the function onAuthenticationReturn()  
ZOOM\_SDK\_NAMESPACE::CSDKWrap::GetInst().GetSettingServiceWrap().Init();  
ZOOM\_SDK\_NAMESPACE::ISettingserviceWrap& settingWrap = ZOOM\_SDK\_NAMESPACE::CSDKWrap::GetInst().GetSettingServiceWrap();  
ZOOM\_SDK\_NAMESPACE::IVideoSettingContextWrap& videosettingwrap = settingWrap.GetVideoSettings();  
videosettingwrap.Init(&settingWrap);

Thus, the callback can be fired.

Regards,  
Wilmer

---

<div class="post-metadata">

**Author:** ![cfrost](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/cfrost/32/152_2.png) [@cfrost](https://devforum.zoom.us/u/cfrost)\
**Post date:** [December 25, 2018, 8:00am UTC](https://devforum.zoom.us/t/windows-net-sdk-ivideosettingscontext-events/2797/6 "2018-12-25T08:00:26Z")

</div>

Hi Wilmer,

Yes, I remember when it worked in the SDK demo, it had to be after authentication, so this implementation makes perfect sense.

Much appreciated!  
Corey

---

<div class="post-metadata">

**Author:** ![DeveloperBot](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/developerbot/32/12632_2.png) [@DeveloperBot](https://devforum.zoom.us/u/DeveloperBot)\
**Post date:** [August 21, 2020, 6:01pm UTC](https://devforum.zoom.us/t/windows-net-sdk-ivideosettingscontext-events/2797/7 "2020-08-21T18:01:14Z")

</div>

Closed on August 21, 2020, 6:01pm UTC


