|
This shouldn't have anything to do with idle processing.
It doesn't make sense that you are missing a message between OnInitDialog and the displaying of
the dialog since you would have needed a valid HWND to get the message in the first place.
What window handle are you passing when you call midiInOpen()?
When are you calling midiInOpen()?
You may get better performance if you use a callback function instead of window messages.
If you choose to use window messages, you should be able to get them just like any other
window message - for example:
afx_msg LRESULT OnMIMLongData(WPARAM wp, LPARAM lp);
ON_MESSAGE(MM_MIM_LONGDATA, &CMyDlg::OnMIMLongData)
LRESULT CMyDlg::OnMIMLongData(WPARAM wParam, LPARAM lParam)
{
HMIDIIN MIDIDeviceHandle = (HMIDIIN)wParam;
MIDIHDR *pMIDIHdr = (MIDIHDR *)lParam;
...
return 0;
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
"Remember the five Ds of dogeball: Dodge, Dip, Duck, Dive, and Dodge."
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
Mark Salsbery wrote: You may get better performance if you use a callback function instead of window messages.
Yes, If I use callback function, there is no problem.
Mark Salsbery wrote: What window handle are you passing when you call midiInOpen()?
When are you calling midiInOpen()?
I am calling both midiOutOpen() and midiInOpen in OnInitDialog() function.
The window handle passed is the pointer to application's main window handle as in following code:
HMIDIIN hdlMidiIn = NULL;<br />
MMRESULT mReturnCode=MMSYSERR_NOERROR; <br />
CWnd* pMainDialog = (CWnd*)AfxGetApp()->m_pMainWnd;<br />
HWND hWnd = pMainDialog->m_hWnd;<br />
mReturnCode = midiInOpen(&hdlMidiIn,uhInID,(DWORD)hWnd,(DWORD)NULL,CALLBACK_WINDOW);<br /> Where, uhInID is MIDI port number.
Now I changed the midiInOpen as follows:
mReturnCode = midiInOpen(&hdlMidiIn,uhInID,(DWORD_PTR)MidiInProc,(DWORD)NULL,CALLBACK_FUNCTION);
Where MidiInProc() is the callback function.
Now I am calling the MIDI message processing function directly by creating object of Dialog class inside the callback. But I want to just send the message, so that callback load will be reduced.
Best Regards,
Suman
|
|
|
|
|
The message will go to the window handle you pass to midiInOpen().
If you pass the main window handle, you won't receive a message in a dialog, unless the dialog is
your main window. Make sure you pass the handle to the window you want to get messages in
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark,
I changed the midiInOpen() to use CALLBACK_FUNCTION as it works fine.
Callback is working well, if I use SendMessage() or directly call the function for MIDI message processing from callback. The PostMessage() is not working well with callback. So, I have implemented SendMessage() . Is there any issues using SendMessage() in callback? Thank you for your great help!!
Best Regards,
Suman
|
|
|
|
|
Hi Mark,
If I dispatch the message from OnKickIdle() I am getting the missing message most of the times. The code is:
LRESULT CMIDIDlg::OnKickIdle(WPARAM wp, LPARAM lp)<br />
{<br />
MSG msg;<br />
if(GetMessage(&msg,NULL,0,MM_MIM_LONGDATA)){<br />
if(msg.message != WM_KICKIDLE)<br />
DispatchMessage(&msg);<br />
}<br />
return 0L;<br />
}<br />
I am going to try some other methods like Win 32 project instead of MFC etc.
Thanks for the help!!
Best Regards,
Suman
P.S. As Saturday & Sunday are holiday I will come again on monday.
Mark, Dont foget to relax & rest while hard work.
|
|
|
|
|
You shouldn't be doing a GetMessage() call here because you've halted message processing for the
window until you get a message. That's not good
See my other reply above.
rp_suman wrote: Mark, Dont foget to relax & rest while hard work.
I work at home - I always get to relax
Have a nice weekend!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
"Remember the five Ds of dogeball: Dodge, Dip, Duck, Dive, and Dodge."
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
Mark Salsbery wrote: You shouldn't be doing a GetMessage() call here because you've halted message processing for the
window until you get a message. That's not good
See my other reply above.
Yes, you are right. I think, If Message comes inside OnKickIdle() means it should also comes if there is no OnKickIdle() .
Best Regards,
Suman
|
|
|
|
|
Hello, I have a vector(CMyData) of an MFC class CMyData in CMyDocumentClass. Because program have to display different sets of Data I usually pass a pointer from a member of this data vector that should be displayed to different view classes. In CMyDataListView, CMyDataPlotView classes before doing anything I first check the validity of pointer with
<br />
if(!AfxIsValidAddress(m_pData, sizeof(CMyData), TRUE))<br />
return;<br />
this line usually is passed without problem indication I can read and write to memory location pointed by m_pData.
but Next line fails!
<br />
if(!m_pData->IsKindOf(RUNTIME_CLASS(CMyData)))<br />
return;<br />
It says Access violation writing location 0x000000000
checking Call Stack shows that AfxIsValidAddress(...) has been actually executed without problem.
Can someone explain what is going on please? How should I check that a memory access failure won't happen.
By the way I have to add that in CMyData I have multiple vectors but please note that all this problems occure before I try to access such variables. Actually in the process of checking validity of pointer.
Thanks
|
|
|
|
|
If the CMyData data object contains pointers itself, it is perfectally reasonable for AfxIsValidAddress(...) to say that a pointer to the object itself is valid, but it cannot evaluate the object's internals to see if its contained pointers are valid. For example, the object itself may have stepped on its runtime-type information.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Electronic75 wrote: if(!m_pData->IsKindOf(RUNTIME_CLASS(CMyData)))
Set a breakpoint on this statement. Is m_pData a CMyData object? Does it point to the same address as it did when first initialized?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
AfxIsValidAddress in VS6 calls IsBadReadPtr or IsBadWritePtr depending on whether bReadWrite is FALSE or TRUE respectively. However, it's been discovered in the last few years that these APIs are seriously flawed. See IsBadXxxPtr should really be called CrashProgramRandomly[^] for details.
Visual Studio .NET 2003 still calls IsBadXxxPtr in Debug builds, but in Release builds only checks for NULL. In Visual Studio 2005, the IsBadXxxPtr checks are completely removed, the function only checks for NULL.
It does look like you've called through a bad pointer - this could well mean that the virtual function pointer inside CMyData is NULL, which it will be if you used memset , for example.
|
|
|
|
|
There is no way to check if an actual non-null pointer is valid!
You might want to look at MSDN and read the remake section or learn the limitation of AfxIsValidAddress
Yours Truly, The One and Only!
|
|
|
|
|
I have found a way to connect visual c++ into MS-access database using ADODC (in active x control), but i don't know how to update, insert, or delete recordset from the database.. does anyone have the code to access the records?? please help me out, I need this for my thesis
|
|
|
|
|
|
i have used map in my program and i m getting these type of warnings
e:\program files\microsoft visual studio\vc98\include\xtree(182) : warning C4786: 'std::_Tree<int,std::pair<int const ,CErrorNotifications *>,std::map<int,CErrorNotifications *,std::less<int>,std::allocator<CErrorNotifications *> >::_Kfn,std::less<i
nt__^,std::allocator<cerrornotifications *=""> >::~_Tree<int,std::pair<int const ,CErrorNotifications *>,std::map<int,CErrorNotifications *,std::less<int>,std::allocator<CErrorNotifications *> >::_Kfn,std::less<int>,std::allocator<CErrorNotifications *>
>' : identifier was truncated to '255' characters in the debug information
e:\program files\microsoft visual studio\vc98\include\xtree(162) : warning C4786: 'std::_Tree<int,std::pair<int const ,CErrorNotifications *>,std::map<int,CErrorNotifications *,std::less<int>,std::allocator<CErrorNotifications *> >::_Kfn,std::less^__i
nt>,std::allocator<CErrorNotifications *> >::_Tree<int,std::pair<int const ,CErrorNotifications *>,std::map<int,CErrorNotifications *,std::less<int>,std::allocator<CErrorNotifications *> >::_Kfn,std::less<int>,std::allocator<CErrorNotifications *> >
' : identifier was truncated to '255' characters in the debug information
e:\program files\microsoft visual studio\vc98\include\xtree(374) : warning C4786: '__unwindfunclet$?erase@?$_Tree@HU?$pair@$$CBHPAVCErrorNotifications@@@std@@U_Kfn@?$map@HPAVCErrorNotifications@@U?$less@H@std@@V?$allocator@PAVCErrorNotifications@@@3
@@2@U?$less@H@2@V?$allocator@PAVCErrorNotifications@@@2@@std@@QAE?AViterator@12@V312@0@Z$0' : identifier was truncated to '255' characters in the debug information
e:\program files\microsoft visual studio\vc98\include\xtree(236) : warning C4786: '__ehhandler$?insert@?$_Tree@HU?$pair@$$CBHPAVCErrorNotifications@@@std@@U_Kfn@?$map@HPAVCErrorNotifications@@U?$less@H@std@@V?$allocator@PAVCErrorNotifications@@@3@@2
@U?$less@H@2@V?$allocator@PAVCErrorNotifications@@@2@@std@@QAE?AU?$pair@Viterator@?$_Tree@HU?$pair@$$CBHPAVCErrorNotifications@@@std@@U_Kfn@?$map@HPAVCErrorNotifications@@U?$less@H@std@@V?$allocator@PAVCErrorNotifications@@@3@@2@U?$less@H@2@V?$alloc
ator@PAVCErrorNotifications@@@2@@std@@_N@2@ABU?$pair@$$CBHPAVCErrorNotifications@@@2@@Z' : identifier was truncated to '255' characters in the debug information
e:\program files\microsoft visual studio\vc98\include\xtree(236) : warning C4786: '__unwindfunclet$?insert@?$_Tree@HU?$pair@$$CBHPAVCErrorNotifications@@@std@@U_Kfn@?$map@HPAVCErrorNotifications@@U?$less@H@std@@V?$allocator@PAVCErrorNotifications@@@
3@@2@U?$less@H@2@V?$allocator@PAVCErrorNotifications@@@2@@std@@QAE?AU?$pair@Viterator@?$_Tree@HU?$pair@$$CBHPAVCErrorNotifications@@@std@@U_Kfn@?$map@HPAVCErrorNotifications@@U?$less@H@std@@V?$allocator@PAVCErrorNotifications@@@3@@2@U?$less@H@2@V?$a
llocator@PAVCErrorNotifications@@@2@@std@@_N@2@ABU?$pair@$$CBHPAVCErrorNotifications@@@2@@Z$0' : identifier was truncated to '255' characters in the debug information
e:\program files\microsoft visual studio\vc98\include\utility(21) : warning C4786: 'std::pair<std::_Tree<int,std::pair<int const ,CErrorNotifications *>,std::map<int,CErrorNotifications *,std::less<int>,std::allocator<CErrorNotifications *> >::_Kfn,
std::less<int>,std::allocator<CErrorNotifications *> >::iterator,bool>::pair<std::_Tree<int,std::pair<int const ,CErrorNotifications *>,std::map<int,CErrorNotifications *,std::less<int>,std::allocator<CErrorNotifications *> >::_Kfn,std::less<int>,st
please anybosy can help me in removing these warnings.....
|
|
|
|
|
#pragma warning( disable : 4786 )
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
#pragma can remove warning from Output window, but find the cause and solving if possible could be better.
Best Regards,
Suman
|
|
|
|
|
Oh, you cannot. And you don't need to worry about: the warning simply states that the identifiers will be truncated in the debug info. But this is inavoidable since there is a 255-characters limit for identifiers in debug information and, on the other hand, STL templates produce very long identifiers. Bottom line you can safely ignore that warnings.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
thanks for your replys...
now my problem is i have made various ui threads before starting these thread i have checked using this code whether they are running or not..
std::map<int, CSmtpThread*>::iterator pos = assocs_Smtp.find(l);
if(pos == assocs_Smtp.end())
{
StartingSmtpThread(URL,l,total_timeinterval,prt,Task_Nm);
}
}
and i have closed my thread using this code
std::map<int, CSmtpThread*>::iterator pos = assocs_Smtp.find(smtpkey);
if(pos != assocs_Smtp.end())
{
CSmtpThread* pThread = pos->second;
pThread->PostThreadMessage(WM_QUIT,NULL,NULL);
}
once i start thread it works fine, when i stop it try to start it it doen't work.It doesn't go inside if condition...
how to solve this problem...
|
|
|
|
|
Because (as far as I can guess...), once you stopped the thread, you have to remove it from the map.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
how to remove them from map
|
|
|
|
|
|
Thanks this solved my problem....
now one more problem i m having that when these ui threads give me result i send the output to my main window to print it in my list control using SendMessage. like this
if (m_pLogWnd)
{
pasiin_val obj_val;
obj_val.index = test_int;
obj_val.url = test_str;
obj_val.task_n = test_task_name;
m_pLogWnd->SendMessage(LOGMSG, (WPARAM)(CString*)&logmsg, (LPARAM)(&obj_val));
}
m_pLogWnd is been assigned with this of my main window...
now my first problem is when i start and stop my thread various times it gives abort assertion failed error sometimes in wincore.cpp in line 980 and sometimes in afxwin2.inl and it sometimes also say that refrenced memory cannot be accessed..
and second after stopping my thread in some threads it shows output value...
how to resolve it...
|
|
|
|
|
Oh I see, Thanks for your help and explanation!!
Other than code, there is one more option to disable the warning:
In Project Menu --> Project Properties --> C/C++ --> Advanced --> Disable Specific Warnings, we can specify a warning number to be suppressed as follows:
/wdn Disables the specified compiler warning where n is the compiler warning number.
For example,
/wd4786 disables compiler warning C4786.
Best Regards,
Suman
|
|
|
|
|
|