lundi 17 juillet 2017

declare a variable based on __uuidof

I'd like to set a webcam's property, say a "focus". Normally it'll look something like that (ignoring error handling):

CComPrt<IUnknown> unkn = ...; // doesn't matter how we get that
CComPtr<IAMCameraControl> cameraCtrl;
unkn->QueryInterface(IAMCameraControl, (void**)&cameraCtrl);
cameraCtrl->Set(CameraControl_Zoom, 123, 1);

The MS-specific operator __uuidof returns a "data type" and its result can be stored in a variable of type IID, like the following:

IID cameraCtrlType = __uuidof(IAMCameraControl);

My question: is there a way to declare a variable based on its IID? Something like that:

CComPrt<IUnknown> unkn = ...; // doesn't matter how we get that
CComQIPtr<decltype(reverse_of__uuid(cameraCtrlType))> cameraCtrl(unkn);
cameraCtrl->Set(CameraControl_Zoom, 123, 1);

I'm looking for a non-template solution here.

As far as I understand this is not possible, at least not with C++11 or even C++17. But maybe someone way more knowledgeable than I am will prove me wrong?

Aucun commentaire:

Enregistrer un commentaire