User forums > Help
Segmentation fault using Beep()
Biplab:
Did you check the return value you are getting? It should return Non-zero values on Successful completion.
tom0769:
Hi,
I used the following code to track the error:
int ret = Beep(1000,500);
if (ret != 0)
{
char szMsgBuf[MAX_PATH] = "";
DWORD dwLastError = GetLastError();
wsprintf(szMsgBuf,"Error #%ld: ", dwLastError);
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dwLastError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
&szMsgBuf[lstrlen(szMsgBuf)],
MAX_PATH,
NULL );
MessageBox( m_hWnd, szMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION );
}
The message box shows "Error #6: Invalid handle" (tranlated from german "Error #6: Das Handle ist ungülltig")
Seems a little bit strange to me since the return value of Beep is definetly not zero :?.
Anybody with a clue?
Thanx
Tom
Biplab:
Hi tom0769,
I didn't see your reply. :)
--- Quote from: Biplab on January 31, 2007, 12:55:43 pm ---Did you check the return value you are getting? It should return Non-zero values on Successful completion.
--- End quote ---
As I wrote in my last reply that the function will return Non-zero value on successful completion. So you must check for errors only when the ret == 0 but NOT when it is non-zero. So change the following code to-
--- Code: --- int ret = Beep(1000,500);
if (ret == 0)
{
--- End code ---
In my PC, the function returns 1 after execution which means it's a successful execution. :)
AFAIK, GetLastError() does not take any argument as input, it only reports the last error which may not be, in this case, related to Beep() function. :)
tom0769:
Hi Biplap,
Thanks for reply! :)
It is really so, that the Beep() function returns with a value non-zero.
So the conclusion would be that there is something behind the Beep() function that fails
and GetLastError() shows the result of this "something behind Beep()".
Is there a chance to evaluate this? :?
Biplab:
Is your application still crashing after Beep() function? If it's so then you may look backwards or just after your beep function, where that Particular Handle related problems occur. Try using a debugger. :)
A Beep() should not give you so much trouble. ;)
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version