🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages Started by poojo hackma Mon, 25 Jun 2007 15:45
Custom Error Function Problems
#1730
Author: poojo hackma
Date: Mon, 25 Jun 2007 15:45
49 lines
2678 bytes
I've got a Custom Error handling function that I've used for a long time:

In the Header:
void ShowLastError(LPTSTR lpszMsgTitle);

The Code:
const DWORD dwSLEFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM;
const  WORD wSLEBuffer = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);

void ShowLastError(LPTSTR lpszMsgTitle)
{
  LPVOID lpErrorMessage;
  FormatMessage(dwSLEFlags, NULL, GetLastError(), wSLEBuffer,
(LPTSTR)&lpErrorMessage, 0, NULL);
  MessageBox(NULL, (LPTSTR)lpErrorMessage, lpszMsgTitle, MB_OK |
MB_ICONERROR);
  LocalFree(lpErrorMessage);
}

I'd like to change this a little. Sometimes the error is ERROR_SUCCESS or
something else that I don't really want to show the error for, so I'd like
to have the option of passing in the dwError value.

I tried changing my custom code to the following, but now I get ambiguous
call to overloaded function errors:

In the new Header:
void ShowLastError(LPTSTR lpszMsgTitle, DWORD dwErr = GetLastError());

The new Code:
const DWORD dwSLEFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM;
const  WORD wSLEBuffer = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);

void ShowLastError(LPTSTR lpszMsgTitle, DWORD dwErr)
{
  LPVOID lpErrorMessage;
  FormatMessage(dwSLEFlags, NULL, dwErr, wSLEBuffer,
(LPTSTR)&lpErrorMessage, 0, NULL);
  MessageBox(NULL, (LPTSTR)lpErrorMessage, lpszMsgTitle, MB_OK |
MB_ICONERROR);
  LocalFree(lpErrorMessage);
}

If I do not supply a value for dwErr in the new versions, shouldn't the code
attempt to fill this with the GetLastError default?

Why am I getting this error? What is the best way to correct my code?
Re: Custom Error Function Problems
#1731
Author: Remy Lebeau (TeamB)
Date: Mon, 25 Jun 2007 14:38
20 lines
1431 bytes
"poojo hackma" <poojo.com/mail> wrote in message
news:467fe307$1@newsgroups.borland.com...

> I've got a Custom Error handling function that I've used for a long
time:

You did not say which version of BCB you are using.

> I tried changing my custom code to the following, but now I get
ambiguous
> call to overloaded function errors:

I cannot reproduce that error.  It works fine when I try it exactly as
you have shown it.  Please show the exact error code, and the line of
code that is being reported.  You likely still have the old
ShowLastError() defined somewhere.


Gambit
Re: Custom Error Function Problems
#1733
Author: poojo hackma
Date: Mon, 25 Jun 2007 19:19
10 lines
1249 bytes
Yes! Very embarrassing. It was.

Thank you, Sir!

Gambit wrote:
>
> You likely still have the old ShowLastError() defined somewhere.
>
> Gambit
> 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads