I forgot to say that SetOrientation() function should be declared in your application class derrived from CWinApp. HGLOBAL m_hDevMode is protected member of the CWinApp class.