The cast is the problem, don't use casts unless you really have to.
Amazing that you got that cast from a Microsoft web site! You have to wonder about the quality of people MS hire. But in their code it's not wrong just superfluous. When you translated it to your code it is wrong.
CreateEnhMetaFile(hdcRef, _T("temp.emf"), &rect, NULL);
The _T
macro is the official way to write a string literal that will be interpreted as either a Unicode string or a ANSI string depending on your compiler settings.