I'm trying to get the printer name selected by the user with the PrintDlg() dialog.
I made a sample Win32 project with VS 2008, (with "Use Multi-Byte Character Set") and inserted the following code in the "About" callback part:
PRINTDLG pd; BOOL rc; DEVMODE *dev; DEVNAMES *dvn; char *name; unsigned char *nme; memset(&pd, 0, sizeof(PRINTDLG)); pd.lStructSize = sizeof(PRINTDLG); pd.hwndOwner = hWnd; pd.Flags = PD_NOPAGENUMS|PD_NOSELECTION|PD_RETURNDC|PD_COLLATE; pd.hDevMode = NULL; // Don't forget to free or store hDevMode. pd.hDevNames = NULL; // Don't forget to free or store hDevNames. pd.nCopies = 1; pd.nFromPage = 0xFFFF; pd.nToPage = 0xFFFF; pd.nMinPage = 1; pd.nMaxPage = 0xFFFF; rc = PrintDlg(&pd); dev = (DEVMODE *) pd.hDevMode; nme = dev->dmDeviceName; dvn = (DEVNAMES *) pd.hDevNames; name = (char *)dvn; name = name + dvn->wDeviceOffset;
But neither nme nor name contain a meaningfull string.
What am I doing wrong?