Subj : Re: How can I make a very large program run? To : borland.public.cpp.borlandcpp From : "Richard Hufford" Date : Mon Feb 09 2004 05:22 pm I apologize for this long post. I can't think of a way to ask this briefly. I thought I'd try asking my question again in a different way. The situation may appear different, but I'm sure it's the same problem. I am 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 gets the size of the DEVMODE structure using the DocumentProperties function. Once the size of the DEVMODE structure is known, the DocumentProperties function is used again to retrieve the DEVMODE structure. A message box is displayed at the end of the function indicating whether the function was successful. If I put a call to this function in a very small OWL application, the function is always successful. I can put the function call in OwlMain, before the application is run, and it is successful. In my very large program, for most computers and printers, the function is successful. 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. The reason I believe the error is a size limitation is that I can put the function call in OwlMain, before any other code I've written, and the error still occurs. I thought Windows was basically limitless. We haven't run into any size problems since we got away from MS-DOS, until now. Are there any limits related to TLINK or TLIB or compiled modules that I need to know about? Here's the function that fails on Windows 2000 in large programs: #include #include #include void CmiPrinterTest() { char device[201]; GetProfileString("windows", "device", ",,,", device, 200); char *comma = strchr (device, ','); if (comma) *comma = 0; DEVMODE *DevMode = NULL; HANDLE h; if (OpenPrinter (device, &h, NULL)) { int DmSize = DocumentProperties(NULL, h, device, NULL, NULL, 0); if (DmSize < 0) { int e = GetLastError(); char buf[101]; sprintf (buf, "error=%d", e); ::MessageBox (NULL, buf, "after docprop", MB_OK); } 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; } .