what is the correct usage of GetLastErrorMsg function call?

If you are a C/C++/C# developer and have any questions about using our products from your application here is the place to post them.
Post Reply
AviG
Posts: 2
Joined: Sun Apr 15 2007

what is the correct usage of GetLastErrorMsg function call?

Post by AviG »

I'm using CDINTF250.DLL to print an already made PDF file using the library entry PrintPDFDocument function.
If the function fails I am trying to log an error message that will clarify the reason for the failure. In order to do that I'm using GetLastErrorMsg immediately after the failed function.
However, no matter what, the GetLastErrorMsg function returns the message "The operation completed succesfully".

On the other hand, if I replace the call to GetLastErrorMsg with the Windows API call like: FormatMessage(..,.., GetLastError(),...) I retrieve the correct error.

In the following code I'm calling PrintPDFDocument with non existing file name, yet Amyuni dll function GetLastErrorMsg returns with "The operation completed succesfully":

Code: Select all

if (TRUE != PrintPDFDocument("non_existing_file_path, "printer_name", 1, 10000, 1))
		{
			GetLastErrorMsg((char*)lpMsgBuf,sizeof(buf));
			cout << "Printing failed, Amyuni error is: " << (char*)lpMsgBuf << endl;
		}
The result is: Printing failed, amyuni error is: The operation completed successfully.

while the following code provides the correct error message:

Code: Select all

if (TRUE != PrintPDFDocument("non_existing_file_path, "printer_name", 1, 10000, 1))
		{
			LPVOID lpMsgBuf;
			FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
				      NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
				      (LPTSTR) &lpMsgBuf, NULL, NULL);
			cout << "Printing failed, Microsoft error is: " << (char*)lpMsgBuf << endl;
			LocalFree(lpMsgBuf);
		}
The result is: Printing failed, ms error is: The system cannot find the path specified.

To summarize: I am preferring the usage of the Amyuni GetLastErrorMsg thinking that this function encapsulates both Windows API error messages and Amyuni specific errors. From the above bad experience however, I wonder:

1) Why the GetLastErrorMsg retruned with incorrect message?

2) What are the real rules of calling GetLastErrorMsg after library function failure?

3) If for several Library functions a failure occur and the GetLastErrorMsg is a no no. Is it safe to assume that using the Windows GetLastError along with FormatMessage will always get me the correct reason text for the failure.
Jose
Amyuni Team
Posts: 553
Joined: Tue Oct 01 2002
Contact:

Post by Jose »

Hello,

The GetLastErrorMsg() is only supported to retrieve error messages generated by the CDIntf object (ex: PDFDriverInit, DriverInit etc).

Hope this helps?
AviG
Posts: 2
Joined: Sun Apr 15 2007

Post by AviG »

Your answer
The GetLastErrorMsg() is only supported to retrieve error messages generated by the CDIntf

is very confusing since it means that you think that the function PrintPDFDocument() is not part of the CDIntf DLL while it is actually part of the DLL and hence it must supply the caller the means to know what is the reason of the failure.

More than that, if Amyuni insists on claiming that the GetLastErrorMsg() is not usefull in this situation, you must than supply an answer to question 3 from my original post. Otherwise, you leave the programmer with a useless function.
Post Reply