UIAutomation GetTopLevelWindowByName
See the question and my original answer on StackOverflowYou must create g_pAutomation, it cannot be null, for example like this:
CoCreateInstance(
__uuidof(CUIAutomation),
NULL,
CLSCTX_ALL,
_uuidof(IUIAutomation),
(void**)&g_pAutomation);