DocumentProperties() cause a First-chance exception
-
In an application i wrote years ago, i need to have a handle to printer propertiers device mode structure; i searched documents and i finded this function (DocumentProperties()); i searched example, i tried to use it, i writed code and the application works yet. Now i have to write similar application and i note when i call this function, it cause a first-chance exception (only when i call it to know the size of buffer); so i try with the old application and also that cause the exception; i try to solve it, but the the example i find and the documentation i have tell me that the use of the function i make it's correct; the funny fact is this method works very well in release mode and with the old application the customer don't have problems. The code is this:
BOOL PrinterSettings(LPTSTR pszPrinterName, BOOL bSet)
{
if (_tcslen(pszPrinterName) <= 0)
return FALSE;if (bSet && theApp.m\_hBarcodePrinterDev == NULL) return FALSE; PRINTER\_DEFAULTS pd; DWORD dwNeeded; LONG lFlag; HANDLE hPrinter = NULL; DEVMODE FAR\* pDevMode = NULL; PRINTER\_INFO\_2\* pPrintInfo2 = NULL; BOOL bReturn = TRUE; ZeroMemory(&pd, sizeof(pd)); pd.DesiredAccess = PRINTER\_ALL\_ACCESS; bReturn = OpenPrinter(pszPrinterName, &hPrinter, &pd); if (bReturn) { SetLastError(0); bReturn = GetPrinter(hPrinter, 2, 0, 0, &dwNeeded); if (!bReturn && (GetLastError() == ERROR\_INSUFFICIENT\_BUFFER) && dwNeeded > 0) bReturn = TRUE; } if (bReturn && (dwNeeded <= 0)) bReturn = FALSE; if (bReturn) pPrintInfo2 = (PRINTER\_INFO\_2 \*) GlobalAlloc (GPTR, dwNeeded); if (bReturn && pPrintInfo2 == NULL) bReturn = FALSE; if (bReturn) bReturn = GetPrinter(hPrinter, 2, (LPBYTE) pPrintInfo2, dwNeeded, &dwNeeded); if (bReturn && pPrintInfo2->pDevMode == NULL) { // Here cause exception dwNeeded = DocumentProperties(NULL, hPrinter, pszPrinterName, NULL, NULL, 0); if (dwNeeded <= 0) bReturn = FALSE; if (bReturn) pDevMode = (DEVMODE FAR\*) GlobalAlloc(GHND, dwNeeded); if (bReturn && pDevMode == NULL) bReturn = FALSE; if (bReturn) { lFlag = DocumentProperties(NULL, hPrinter, pszPrinterName, pDevMode, NULL,DM\_OUT\_BUFFER); if (lFlag != IDOK || pDevMode == NULL) bReturn = FALSE; } if (bReturn) pPrintInfo2->pDevMode = pDevMode; } if (
-
In an application i wrote years ago, i need to have a handle to printer propertiers device mode structure; i searched documents and i finded this function (DocumentProperties()); i searched example, i tried to use it, i writed code and the application works yet. Now i have to write similar application and i note when i call this function, it cause a first-chance exception (only when i call it to know the size of buffer); so i try with the old application and also that cause the exception; i try to solve it, but the the example i find and the documentation i have tell me that the use of the function i make it's correct; the funny fact is this method works very well in release mode and with the old application the customer don't have problems. The code is this:
BOOL PrinterSettings(LPTSTR pszPrinterName, BOOL bSet)
{
if (_tcslen(pszPrinterName) <= 0)
return FALSE;if (bSet && theApp.m\_hBarcodePrinterDev == NULL) return FALSE; PRINTER\_DEFAULTS pd; DWORD dwNeeded; LONG lFlag; HANDLE hPrinter = NULL; DEVMODE FAR\* pDevMode = NULL; PRINTER\_INFO\_2\* pPrintInfo2 = NULL; BOOL bReturn = TRUE; ZeroMemory(&pd, sizeof(pd)); pd.DesiredAccess = PRINTER\_ALL\_ACCESS; bReturn = OpenPrinter(pszPrinterName, &hPrinter, &pd); if (bReturn) { SetLastError(0); bReturn = GetPrinter(hPrinter, 2, 0, 0, &dwNeeded); if (!bReturn && (GetLastError() == ERROR\_INSUFFICIENT\_BUFFER) && dwNeeded > 0) bReturn = TRUE; } if (bReturn && (dwNeeded <= 0)) bReturn = FALSE; if (bReturn) pPrintInfo2 = (PRINTER\_INFO\_2 \*) GlobalAlloc (GPTR, dwNeeded); if (bReturn && pPrintInfo2 == NULL) bReturn = FALSE; if (bReturn) bReturn = GetPrinter(hPrinter, 2, (LPBYTE) pPrintInfo2, dwNeeded, &dwNeeded); if (bReturn && pPrintInfo2->pDevMode == NULL) { // Here cause exception dwNeeded = DocumentProperties(NULL, hPrinter, pszPrinterName, NULL, NULL, 0); if (dwNeeded <= 0) bReturn = FALSE; if (bReturn) pDevMode = (DEVMODE FAR\*) GlobalAlloc(GHND, dwNeeded); if (bReturn && pDevMode == NULL) bReturn = FALSE; if (bReturn) { lFlag = DocumentProperties(NULL, hPrinter, pszPrinterName, pDevMode, NULL,DM\_OUT\_BUFFER); if (lFlag != IDOK || pDevMode == NULL) bReturn = FALSE; } if (bReturn) pPrintInfo2->pDevMode = pDevMode; } if (
-
Whene the execution arrives in one of two lines i signed, compiler write: First-chance exception in MyApp.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception. First-chance exception in MyApp.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception. but the function works normally. Thanks Drugo
-
Whene the execution arrives in one of two lines i signed, compiler write: First-chance exception in MyApp.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception. First-chance exception in MyApp.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception. but the function works normally. Thanks Drugo
-
These are not compiler messages, they look more like the messages you see in the debug log and can be ignored. Unless you get an exception inside your program, which causes the application to fail, you do not need to take any action.
-
They are written to the debug log by the debugger; they are not being sent to the application. These exceptions are caught and handled by the system libraries.