|
1. Why extern "C" ?
2. If it is a regular DLL using MFC, you need to add:
AFX_MANAGE_STATE(AfxGetStaticModuleState());
at the beginning of your DLL-exported function.
Regards,
BB
|
|
|
|
|
After initializing the timer by:
SetTimer(ID_PLAYTIME_EVENT, 1000, NULL);
The following codes will result in exception: 0XC00000FD: stack overflow?
void CCPPPLAYERDlg::OnTimer (UINT nIDEvent)
{
MSG msg={0};
switch (nIDEvent) {
case ID_PLAYTIME_EVENT:
if(g_hwndMain)
{
// Main message loop
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg); DispatchMessage(&msg);
}
break;
}
CDialog::OnTimer(nIDEvent);
}
DJ
|
|
|
|
|
Don't put such a loop into a timer function. They were not designed to co-exist. The code you put into a timer function must be short, sweet and to the point, consuming as little CPU as possible.
|
|
|
|
|
If my brain is thinking right, if there are too many messages in the queue, this code will never finish and end up basically calling itself.
(I am baffled as to why you need to do a message look anyway.)
Finally, why use switch? Why not use if (nIDEvent == ID_PLAYTIME_EVENT)
|
|
|
|
|
After initializing the timer by:
SetTimer(ID_PLAYTIME_EVENT, 1000, NULL);
The following codes will result in exception: 0XC00000FD: stack overflow?
void CCPPPLAYERDlg::OnTimer (UINT nIDEvent)
{
MSG msg={0};
switch (nIDEvent) {
case ID_PLAYTIME_EVENT:
if(g_hwndMain)
{
// Main message loop
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg); DispatchMessage(&msg);
}
}
else
{
// AfxMessageBox(_T("Failed to create the main window!"));
}
break;
}
CDialog::OnTimer(nIDEvent);
}
DJ
|
|
|
|
|
Your implementation is not corectly!!
The return value of 'GetMessage' function can be:
zero - If the function retrieves the WM_QUIT message;
nonzero - If the function retrieves a message other than WM_QUIT;
-1 - If there is an error (ex. if hWnd is an invalid window handle or lpMsg is an invalid pointer).
In your function the 'GetMessage' returns nonzero always and when arrive a timer message this will be blocked in while loop, but after 1 sec. will arrive other timer message and will be blocked.
This is the problem, you never exit from OnTimer function, but OnTimer function is called at each 1 sec.
From this reason you have a Stack Overflow exception.
|
|
|
|
|
You are most likely right. The funciton (while uncommented) of AfxMessageBox(_T("Failed to create the main window!")); never be reached.
Thus I called KillTimer somewhere in the program to kill ID_PLAYTIME_EVENT and there were no more Stack Overflow problems.
But question again:
How do the following codes work? Once this code being called and run, how does it exit the while loop? Is it the correct way to process the message queue?
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
From my tests, once the program runs to this code, the while loop will exit forever until exiting the entire program. Actually that is what I had expected so that some other codes can run on a multitasking windows such 2000.
DJ
|
|
|
|
|
I'm trying to use the following code
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CDocument),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CLeftView));
AddDocTemplate(pDocTemplate);
But i'm getting an error because I haven't created an CDocument derived object. However I have to use this approach, because i'm trying to create splitter windows using this code:
m_wndSplitterLR.CreateStatic(this, 1, 2);
m_wndSplitterLR.CreateView(0, 1, RUNTIME_CLASS(CRightView), CSize(0, 0), pContext);
m_wndSplitterLR.SetColumnInfo(0, 200, 0);
m_wndSplitterUD.CreateStatic(&m_wndSplitterLR, 2, 1, WS_CHILD | WS_VISIBLE, m_wndSplitterLR.IdFromRowCol(0, 0));
m_wndSplitterUD.CreateView(0, 0, pContext->m_pNewViewClass, CSize(0, 200), pContext);
m_wndSplitterUD.CreateView(1, 0, RUNTIME_CLASS(CLeftView), CSize(0, 0), pContext);
And pContext is NULL unless I use Doc/View architechture and if it's NULL the second last line chokes...but I do not need a CDocument....
Any ideas or suggestions...? Should I just define a phantom CDocument class or soemthing, somehoe???
Thanks.
"Two wrongs don't make a right, but three lefts do!" - Alex Barylski
|
|
|
|
|
First: you don't need any document to create and use splitters.
If you want your CDocument to be a communication "media" among your views (via CDocument::UpdateAllViews ), you need to derive it and add this functionality. If you don't want to, you'll probably end up with the nasty code like:
((CMyRightPane*)((CSplitterWnd*)GetParent())->GetPane(x, y))->DoSomething();
which I personally hate.
So, run for your document or explicitly create/load a frame and create its views (in CYourFrame::OnCreateClient ) without using document templates.
Regards,
BB
|
|
|
|
|
If i don't use doc/view pContext->m_pNewViewClass is NULL inside OnCreateClient() and the application crashes???
How would I get the desired effect using the above I posted, without using DOC/VIEW???
Thanks!
"Two wrongs don't make a right, but three lefts do!" - Alex Barylski
|
|
|
|
|
Sample OnCreateClient for NULL document case (untested and not very elegant - but you will get the idea):
class CYourFrame : public CFrameWnd<br />
{<br />
CSplitterWnd Splitter;<br />
}
BOOL CYourFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext*) <br />
{<br />
CCreateContext cx;<br />
cx.m_pCurrentFrame = this;<br />
<br />
Splitter.CreateStatic(this, 1, 2);<br />
Splitter.CreateView(0, 0, RUNTIME_CLASS(CMyViewLeft), CSize(250, 250), &cx);<br />
Splitter.CreateView(0, 1, RUNTIME_CLASS(CMyViewRight), CSize(0, 0), &cx);<br />
<br />
if(bInitialUpdate) Splitter.SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, FALSE);<br />
<br />
Splitter.SetActivePane(0, 0);<br />
return TRUE;<br />
}
Note: You may pass NULL as a last parameter to CSplitterWnd::CreateView , the WM_INITIALUPDATE message will then be automagically sent to the subsequently created views.
Regards,
BB
|
|
|
|
|
I am trying to code a program to play wave files using the low level functions provided by VC++ such as the "MMIO" functions.
I encountered problems in "waveOutOpen","waveOutWrite","waveOutPrepareHeader" functions.
A handle was passed as the first parameter to each of the function calls.The error i got was "waveOutOpen cannot convert parameter one from void ** to struct HWaveout_ **".the same error was shown for each of the other function calls(i.e for waveOutPrepareHeader etc),subsequently i typecasted the handle as (HWAVEOUT*).While this caused the errors to stop the program did not run as the header was not being prepared. The code is as shown below.
HANDLE hWaveOut;
MMRESULT ReturnCode = waveOutOpen((HWAVEOUT*)&hWaveOut,WAVE_MAPPER,(tWAVEFORMATEX*)&PCMWaveFmtRecord,NULL,NULL,NULL);
if(ReturnCode)
{
AfxMessageBox("Could Not Open Wave Device",MB_OK | MB_ICONSTOP,NULL);
return(FALSE);
}
ReturnCode=waveOutPrepareHeader((HWAVEOUT)&hWaveOut,&WaveHeader,sizeof(WaveHeader));
if(ReturnCode)
{
AfxMessageBox("Could Not Prepare Header",MB_OK | MB_ICONSTOP,NULL);
waveOutClose((HWAVEOUT)hWaveOut);
return(FALSE);
}
ReturnCode = waveOutWrite((HWAVEOUT)&hWaveOut,&WaveHeader,sizeof(WaveHeader));
if(ReturnCode)
{
AfxMessageBox("Error Writing to Wave Device",MB_OK | MB_ICONSTOP,NULL);
waveOutClose((HWAVEOUT)hWaveOut);
return(FALSE);
}
Could anyone let me know how to proceed?
novicedude
|
|
|
|
|
Your first function,
waveOutOpen((HWAVEOUT*)&hWaveOut,WAVE_MAPPER,(tWAVEFORMATEX*)&PCMWaveFmtRecord,NULL,NULL,NULL);
seems to be correctly, but more correctly is to use function like that:
HWAVEOUT hWaveOut;
waveOutOpen(&hWaveOut,WAVE_MAPPER,(LPWAVEFORMATEX)&PCMWaveFmtRecord,NULL,NULL,NULL);
(where PCMWaveFmtRecord identifies the format of the waveform-audio data to be sent to the device).
The second and third function:
waveOutPrepareHeader((HWAVEOUT)&hWaveOut,&WaveHeader,sizeof(WaveHeader));
waveOutWrite((HWAVEOUT)&hWaveOut,&WaveHeader,sizeof(WaveHeader));
is not correctly because the first parrametter pased is need to be a HWAVEOUT handle and not a reference.
Correctly is:
waveOutPrepareHeader(hWaveOut,&WaveHeader,sizeof(WAVEHDR));
waveOutWrite(hWaveOut,&WaveHeader,sizeof(WAVEHDR));
|
|
|
|
|
Hi:
As you know "SetTimer" has the following syntax:
UINT_PTR SetTimer(
HWND hWnd, // handle to window
UINT_PTR nIDEvent, // timer identifier
UINT uElapse, // time-out value
TIMERPROC lpTimerFunc); // timer procedure
I have problem with first parameter.i used m_hWnd (public member),but it doesn't work!!!.now in my MFC application,what should i choose for first parameter ? in the other hand how can i get a handle to the form or dialog's window ? please help me.
Best Regards.
|
|
|
|
|
In MFC, SetTimer() is a CWnd method. Just call it in your dialog's OnInitDialog() or in your CFormView's OnInitialUpdate() .
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
HWND GetDlgItem( int nID ) will give you the window handle.
You could actually use CWnd::SetTimer which doesn't require a handle as a parameter.
UINT SetTimer( UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORT* lpfnTimer)(HWND, UINT, UINT, DWORD) );
For your Callback function you can have a NULL parameter and you can handle WM_TIMER instead or CWnd::OnTimer(UINT nIDEvent );
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
What do you mean "it doesn't work"? It won't compile? It formats your drive?
When you call SetTimer in a window class, you use CWnd::SetTimer , which doesn't take an HWND parameter.
--Mike--
THERE IS NO THERE IS NO BUT THERE IS
MAGIC PIXIE DUST BUSINESS GENIE CODE PROJECT
Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
Michael Dunn wrote:
It formats your drive?
Bad day @ work, Mike?
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
MR ZarrinPour wrote:
now in my MFC application,what should i choose for first parameter ?
Have a look at GetSafeHwnd(), although CWnd::SetTimer() is probably what you should be using.
|
|
|
|
|
i want to restrict a user from accessing different drives in the system from the IE url box.
when u type d: in internet explorer it directly opens the drive d i donot what this to happen. how can i acheive this ....
thnks in advance
qrious
|
|
|
|
|
Are you wanting to prevent a user from opening up their own D: drive? Is the OS on that machine Windows NT, 2000, or XP? If not, I do not know of a "clean" way.
|
|
|
|
|
Hi, everyone!
Suppose I have a istream and I want to read an
integer from a istream. If the length is 0 and
I think the stream is correpted and I won't like
any other operations on the stream later. So I
think I can set the state of the stream. The following
is my sample code. I want to know whether my solution
is correct? Are there some other things to consider?
Source codes:
--------
int data;
/** return value is used to indicate whether the return
value is correct.
*/
bool A::Read (std::istream& is)
{
is.exceptions(ios::failbit|ios::eofbit);
try {
is.read ((char*)&data, sizeof (data));
if (!data) {
is.setstate (ios::failbit);
return false;
}
} catch (ios::failure e)
{
return false;
}
return true;
}
--------
Thanks in advance,
George
|
|
|
|
|
Can someone suggest a method to accomplish writing to a file and at that moment another program would read that same data for its use.
The program is writing a line of floats to just generate data while the other program needs to read and process it.
Using two seperate executables and an ascii file led to apparent file locking issues.
Thanks for any suggestions.
Ken
|
|
|
|
|
A file isn't the most reliable way to transfer data between apps. From your description, a socket would be a better way.
And in any event, you'd still need some IPC to let the second app know that there's data to be read
--Mike--
THERE IS NO THERE IS NO BUT THERE IS
MAGIC PIXIE DUST BUSINESS GENIE CODE PROJECT
Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
You can do this with a memory mapped file and a named event. Create a named event and open it in both applications. Set it in one thread to signal that the other can read the data. When the data is read reset the event.
http://www.codeproject.com/win32/cmemmap.asp[^]
John
|
|
|
|
|