Subj : Re: How can I make a very large program run? To : borland.public.cpp.borlandcpp From : Bob Gonder Date : Mon Feb 09 2004 07:01 pm Richard Hufford wrote: >trying to get a DEVMODE structure for the default printer. I have a >function that gets the device name from the profile, opens the printer, and Yes, it gets it from WIN.INI You probably don't have a WIN.INI on your 2000 machine, or the printer isn't specified correctly in it. Is this a 32bit app? The help mentions that you shouldn't use GetProfileString in 32bit apps, that it is a holdover from Win3.1 >However, if I am using a Windows 2000 machine and a newer HP Laserjet >printer, for example an HP Laserjet 1200 series, the first call to >DocumentProperties returns -1, and GetLastError returns 6, which I believe >is ERROR_INVALID_HANDLE. The function succeeds on a Windows 2000 machine if >I have an older HP Laserjet, such as a LaserJet III set as the default >printer. Did you check the result of GetProfileString()? Does it return the correct printer name when things fail? As an alternative, you could call PrintDlg() with a parameter of PD_RETURNDEFAULT. That will return 2 GlobalAlloc handles that you apply GlobalLock() to get the address thereof. One is the DeviceName, the other is a filled-in DevMode of the proper size. Totally untested.... HGLOBAL GetDefaultDevMode(void) { PRINTDLG pd = {sizeof(PRINTDLG)}; pd.Flags = PD_RETURNDEFAULT; PrintDlg(&pd); GlobalFree( pd.hDevNames ); return pd.hDevMode; }; HGLOBAL hDM = GetDefaultDevMode(); LPDEVMODE DM = (LPDEVMODE)GlobalLock(hDM); Don't forget to GlobalUnlock() then GlobalFree() when done. > Here's the function that fails on Windows 2000 in large programs: > >void CmiPrinterTest() { > char device[201]; > GetProfileString("windows", "device", ",,,", device, 200); > DEVMODE *DevMode = NULL; > HANDLE h; > if (OpenPrinter (device, &h, NULL)) { > int DmSize = DocumentProperties(NULL, h, device, NULL, NULL, 0); > if (DmSize > 0) { > DevMode = (DEVMODE *) new char[DmSize]; > DocumentProperties(NULL, h, device, DevMode, NULL, DM_OUT_BUFFER); > } > ClosePrinter (h); > } > ::MessageBox (NULL, DevMode ? "OK" : "fail", "test", MB_OK); > if (DevMode) delete DevMode; >} > .