|
I'm making mpegPlayer.
but I cannot add random mode.
when i check random and play music.
'stack overflow' happen and go debug mode.
and No check on Repeat, Random next button clicked random mode has start
What is missing my program?
this is OnNext() -> when i next button clicked has happen
OnNext()
{
srand((unsigned)time(NULL));
int m_nPlayIndexTemp;
int nCount = theApp.GetMainDlg()->m_pDlg_PlayList->m_PlayList.GetCount();
if( theApp.GetMainDlg()->m_pDlg_PlayList==NULL)
return;
if( m_nPlayIndex > theApp.GetMainDlg()->m_pDlg_PlayList->m_PlayList.GetCount()-1 )
m_nPlayIndex = 0;
if( m_bRandom = true )
{
m_nPlayIndexTemp = rand()%theApp.GetMainDlg()->m_pDlg_PlayList->m_PlayList.GetCount();
if( m_nPlayIndexTemp != m_nPlayIndex )
{
m_nPlayIndex = m_nPlayIndexTemp;
}
else
{
OnNext();
}
}
else if ( (m_bRepeat = true && m_nPlayIndex) == nCount )
{
m_nPlayIndex = 0;
}
else if( ((m_bRepeat = false)&&(m_bRandom = false)) == true )
{
m_nPlayIndex++;
}
OnPlay();
}
----------------Please help me!!---------------------------
When you need all source.
Please reply and write your e-mail
|
|
|
|
|
Stack overflow happens in general when you have an infinite recursion (a function that calls itself that calls itself that....). Here in your code, you are calling OnNext until you get a different number of the song that is currently played (or at least, this is want you are trying to do).
First thing, don't call OnNext but rather but the selection of a new song number in a loop. This is really horrible (I mean by code):
if( m_nPlayIndexTemp != m_nPlayIndex )
{
m_nPlayIndex = m_nPlayIndexTemp;
}
else
{
OnNext();
}
rather replace it by something like that:
while (true)
{
m_nPlayIndexTemp = CalculateRandomNumberHere();
if (m_nPlayIndexTemp != m_nPlayIndex)
break;
}
Second, the way you use for calculate random numbers is false:
rand()%theApp.GetMainDlg()->m_pDlg_PlayList->m_PlayList.GetCount();
The modulo operator (%) will give you the remainder of the division. So for example if you have 1 song in the playlist, and rand() gives you 123456, the result will be 123456. Mhh, a little bit outside the bounds of your playlist no ?
Better use something like that:
rand()*nCount/RAND_MAX;
|
|
|
|
|
The info about the modulo operator is wrong. Modulo will give you the remainder, correct, but the remainder of 123456/1 is, have we guessed it yet, 0!!!
Any integer divided by 1, will leave no remainder. Similarily any integer divided by 2 will leave a remainder of 0 or 1, any integer divided by 3 will leave a remainder or 0, 1, or 2. And so on...
So the ouput of that expression will be inside your bounds if you have 1 element in your array. Also it will be in your array's bounds aslong as the size of the array is equal to (or greater than) the number of items in your playlist.
Be careful to check that if theApp...PlayList.GetCount() returns 0, (i.e. your playlist has no entries), that you don't calculate rand()%theApp..GetCount(), as rand()%0 will cause a 'Divide By Zero exception'.
|
|
|
|
|
one can burn cd disc or dvd disc with dvd-r drive, right?
the problem is that...
then an application can possibly know which media,
cd or dvd disc is inserted?
so that an application let users know how much data, 700M or 4.7G they can burn,..
is it possible or not to know in advance
(before burning started) ?
|
|
|
|
|
A CDR/RW has a "pre-burnt" area called ATIP (Absolute Time In Pregroove).
Most burners are able to read that area. (The ATIP isn't readable by a CD/DVD-ROM).
You read it by means of a SCSI-command to the burner.
That area givs you the recording time (for this disc) in minutes, seconds and frames.
As far as I can remember, a DVD has a similar area, but I can't remeber it's name right now.
But as usual, Google is your best friend...
|
|
|
|
|
While building a COM exe which is created using ATL COM App wizard, I got an link error "uuid.lib(comcat.obj) : fatal error LNK1103: debugging information corrupt; recompile module" .
What is the problem here and what will be the solution?
Thanx in advance..
|
|
|
|
|
I'd be starting with a clean and rebuild all. That appears to be what the system is telling you to do.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I had tried that also....
Another point is I had do nothing in the code that ATL COM App wizard created for me.
|
|
|
|
|
|
Ya, that is the scenario.
I could build it after removing SDK includes and libraries from
tools --->Option.
|
|
|
|
|
Hi
I am developing a Windows application which interacts with a add-on hardware device on a laptop. The device is connected to the laptop via., a USB cable. I am creating a thread to read from a flat file and write the contents to the USB. The thread runs normally if the Windows session is not disturbed. But if I try to minimise a window, maximise, open another application, or even turn off my monitor the thread is disturbed and the data is corrupted. Any solution to this? One of my friends in CodeProject suggested to raise the priority of the thread to a real time level so that it is not interrupted even by kernel threads. I tried doing this by setting a flag in AfxBeginThread and starting the thread. I hope the thread is created with real time priority, but still the problem exists.
Is there any other way to increase the priority of the user thread?
Please help...
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
Sreekanth Muralidharan wrote:
I hope the thread is created with real time priority
I Believe, Real time Priority Thread is not good solution to you problem!. AFAIK, you are developin gyou application using worker thread, my suggesstion will be create UserInterface thread and handle different POWER EVENT and Windows Event within UI thread!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
hi,
i am developing a folder watching application. i want to use the fuction FindFirstChangeNotification and ReadDirectoryChangeW.
The problem here is when i create a MFC project using Dialog approach
i inlcude the sample code MSDN provide in a button handler function, and if i run it, the application will hung and i have to use task manager to close it.
the same thing happen if i use ReadDirectoryChangeW.
however if i put the same code in a win32 application project( using MFC shared .dll ), it can works well.
Pls help, thanks, the msdn sample code is below:
DWORD dwWaitStatus;
HANDLE dwChangeHandles[2];
// Watch the C:\WINDOWS directory for file creation and
// deletion.
dwChangeHandles[0] = FindFirstChangeNotification(
"C:\\WINDOWS", // directory to watch
FALSE, // do not watch the subtree
FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes
if (dwChangeHandles[0] == INVALID_HANDLE_VALUE)
ExitProcess(GetLastError());
// Watch the C:\ subtree for directory creation and
// deletion.
dwChangeHandles[1] = FindFirstChangeNotification(
"C:\\", // directory to watch
TRUE, // watch the subtree
FILE_NOTIFY_CHANGE_DIR_NAME); // watch dir. name changes
if (dwChangeHandles[1] == INVALID_HANDLE_VALUE)
ExitProcess(GetLastError());
// Change notification is set. Now wait on both notification
// handles and refresh accordingly.
while (TRUE)
{
// Wait for notification.
dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles,
FALSE, INFINITE);
switch (dwWaitStatus)
{
case WAIT_OBJECT_0:
// A file was created or deleted in C:\WINDOWS.
// Refresh this directory and restart the
// change notification. RefreshDirectory is an
// application-defined function.
RefreshDirectory("C:\\WINDOWS")
if ( FindNextChangeNotification(
dwChangeHandles[0]) == FALSE )
ExitProcess(GetLastError());
break;
case WAIT_OBJECT_0 + 1:
// A directory was created or deleted in C:\.
// Refresh the directory tree and restart the
// change notification. RefreshTree is an
// application-defined function.
RefreshTree("C:\\");
if (FindNextChangeNotification(
dwChangeHandles[1]) == FALSE)
ExitProcess(GetLastError());
break;
default:
ExitProcess(GetLastError());
}
}
|
|
|
|
|
a_du wrote:
dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles,
FALSE, INFINITE);
Actaully this is BLOCKING CALL,this will block all Message Coming to your Dialog Box.
Only Solution to above problem is to create multithread Program!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Thanx alot. I have solved that problem by using multithread.
BTW, can some one tell me the differences between these two functions and whether it is possible to retrieve file name informations from the FindFirstChangeNotification approach.
|
|
|
|
|
a_du wrote:
it is possible to retrieve file name informations from the FindFirstChangeNotification approach.
Nope, It not Possible to Retrieve File Information using FindFirstChangeNotification approach!, only ReadDirectoryChangeW will help in this regard!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
As Alok said, you're blocking the UI thread and waiting for directory changes. You need to move that code to a separate worker thread and inform the UI when you get modifications.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
S. Senthil Kumar wrote:
and inform the UI when you get modifications.
Oops, I forget to mention that, Thanks for correcting me!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hello!
Here's my situation. I have a dialog with a CEdit-derived object and CListCtrl-derived object. When someone is typing in the edit control and they hit Enter, I want the text to be copied to the CListCtrl.
The CDialog class that contains these controls has a method that gets the text from the edit control and inserts it into the CListCtrl.
My problem is trapping the Enter key in the edit box and getting the dialog to call it's method that copies from the edit box to the list control.
I think I'm going about this all wrong. What I'm currently trying to do in the CEdit-derived class is this:
void CMyEdit::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// If Enter has been pressed, we need to post this message to the dialog.
if(nChar == 13)
{
// Get a handle to our dialog window
CWnd* pDialogWnd = GetParent();
// Post the message to our dialog window
pDialogWnd->PostMessage(WM_KEYUP, VK_RETURN, 0);
}
CEdit::OnKeyUp(nChar, nRepCnt, nFlags);
}
I implement the WM_KEYUP message in the parent dialog class as follows:
void CMyDlg::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// If Enter has been pressed, we need to update the rules list
if(nChar == 13)
{
UpdateRulesList();
}
CDialog::OnKeyUp(nChar, nRepCnt, nFlags);
}
But I end up hanging somewhere after my UpdateRulesList method executes (the problem is not in UpdateRulesList (at least I can call it from the dialog object and it works just fine)). I must be generating some kind of endless message loop or something...
Any help would be greatly appreciated!
Thanks!
-Ian
|
|
|
|
|
Ian Bowler wrote:
I must be generating some kind of endless message loop or something...
Does this mean you've put a breakpoint in to see if this is the case ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I put a break point where my dialog class calls the UpdateRegRules method. I step through that method and everything seems copacetic. If I hit f5, I seem to hang.
I'm totally guessing on the endless looping. I'm actually stumped. I've never used PostMessage before and I'd be willing to bet that that's the root of the problem...
|
|
|
|
|
If you hit F5 and you're creating an endless message loop, you should find yourself hitting the same spot over and over. You can also override PreTranslateMessage to see if this is in fact occuring.
The difference between SendMessage and PostMessage is just that PostMessage sends the message when the current function ends, SendMessage does it right away.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Not really, PostMessage posts the message to the message queue and returns immediately, SendMessage sends the message to the message pump and waits till it gets processed.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Try out with SendMessage instead of PostMessage
<bold>- Nilesh
<italics>"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
You guys ROCK! Thanks so much! SendMessage fixed the problem. I don't think I understand why sending the message right away fixed the problem though. Some crazy timing thing?
I actually thought the difference was that PostMessage added the message to the message queue and SendMessage bypassed the queue (at least that's how someone else explained it to me).
Thanks again, to both of you for your excellent help!
-Ian
|
|
|
|