How to set custom viewport class programmatically from C++?

I’m developing a plugin which needs to do efficient screen captures in standard resolution (high res is not needed). It seems one way to do this is by using ReadPixels in custom viewport. However one problem I have is that the class for custom viewport must be set in Project Settings (or project ini file). I’d just like plugin to override default viewport class at runtime programmatically.

Is that possible?

Thanks.