The first thing to do would be to check what the call returns. You can find more details
here[
^] but the simple explanation is: you should only call CoUninitialise if
your call to CoInitialize SUCCEEDED:
"
To close the COM library gracefully on a thread, each successful call to CoInitialize or CoInitializeEx, including any call that returns S_FALSE, must be balanced by a corresponding call to CoUninitialize."
My guess would be that the XMLDOMDocPtr calls CoInitialize with the APARTMENTTHREADED model and you get a RPC_E_CHANGED_MODE from your call. If this is the case you should not call CoUninitialize.