|
i am writing a code for playing an mp3 file.i will first read 2mb from the file and it will put in to a buffer and then i will play it.then the next 2mb will read and so on.but there is an almost 1 second delay after each 2mb.what will be the problem. this is my code
void CMP3PLAYERDlg::OnPlay()
{
m_Video=NULL;
if(m_Video==NULL)
{
m_Video = MCIWndCreate(this->GetSafeHwnd(),
AfxGetInstanceHandle(),
WS_CHILD |MCIWNDF_NOMENU|MCIWNDF_SHOWNAME,m_Path);
m_Play.EnableWindow(FALSE);
//CMP3PLAYERDlg pNewObject = new CMP3PLAYERDlg;
AfxBeginThread(MyThreadProc, this);
}
Pause = FALSE;
}
UINT MyThreadProc( LPVOID pParam )
{
CMP3PLAYERDlg* pObject = (CMP3PLAYERDlg*)pParam;
CMediaType mt;
mt.majortype = MEDIATYPE_Stream;
mt.subtype = MEDIASUBTYPE_MPEG1Audio;
DWORD dwKBPerSec =INFINITE;
HANDLE hFile = CreateFile(pObject->m_Path,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
0,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
AfxMessageBox("Could not open "+ pObject->m_Path);
}
ULARGE_INTEGER uliSize;
uliSize.LowPart = GetFileSize(hFile, &uliSize.HighPart);
read=uliSize.LowPart;
uliSize.LowPart=2000000;
PBYTE pbMem = new BYTE[uliSize.LowPart];
if (pbMem == NULL)
{
AfxMessageBox("Could not allocate %d bytes", uliSize.LowPart);
}
do
{
if(read<ulisize.lowpart)
{
="" ulisize.lowpart="read;
" read+="2000000;
" pbyte="" pbmem="new" byte[ulisize.lowpart];
="" }
="" bool="" h="ReadFile(hFile,(LPVOID)pbMem,uliSize.LowPart,&dwBytesRead,NULL)" ;
="" if="" (!h)
="" afxmessagebox("could="" not="" read="" file");
="" closehandle(hfile);
="" break;
=""
="" hresult="" hr="S_OK;
" coinitialize(null);
=""
="" cmemstream="" stream(pbmem,="" (longlong)ulisize.quadpart,="" dwkbpersec);
="" cmemreader="" *rdr="new" cmemreader(&stream,="" &mt,="" &hr);
="" (failed(hr)="" ||="" rdr="=" null)
="" delete="" rdr;
="" create="" filter="" 0x%8.8x",="" hr);
="" couninitialize();
="" rdr-="">AddRef();
hr = CoCreateInstance(CLSID_FilterGraph,
NULL,
CLSCTX_INPROC,
IID_IFilterGraph,
(void **)&pFG);
if(hr!=0)
{
AfxMessageBox("cannot create instance");
}
hr = pFG->AddFilter(rdr, NULL);
IGraphBuilder *pBuilder;
hr = (pFG)->QueryInterface(IID_IGraphBuilder, (void **)&pBuilder);
pin=rdr->GetPin(0);
int n=rdr->GetPinCount();
hr = pBuilder->Render(pin);
pBuilder->Release();
hr = pFG->QueryInterface(IID_IMediaControl, (void **)&pMC);
hr = pFG->QueryInterface(IID_IMediaEvent, (void **)&pME);
OAEVENT oEvent;
hr = pME->GetEventHandle(&oEvent);
hr = pMC->Run();
if (SUCCEEDED(hr))
{
LONG levCode;
hr = pME->WaitForCompletion(INFINITE, &levCode);
read-=2000000;
}
rdr->Release();
}while(dwBytesRead!=read);
pMC->Release();
pME->Release();
if (pFG)
{
ULONG ulRelease = pFG->Release();
if (ulRelease != 0)
{
AfxMessageBox("Filter graph count not 0! was %d", ulRelease);
}
}
CloseHandle(hFile);
CoUninitialize();
pObject->m_Play.EnableWindow(TRUE);
return TRUE;
}
please give me an elaborate answer.
sebin
|
|
|
|
|
I'm writing a simple flat file database MFC SDI application. However after i save n close the file, i cant open it again and shows 'unexpected file format'.
below is my serialize funcation for the new class, the sequence is correct. What other problem can it be?
void CPerson::Serialize(CArchive &ar)
{
CObject::Serialize(ar);
if (ar.IsStoring())
ar << m_sName << m_sRoom << m_iSex << m_iStatus;
else
ar >> m_sName >> m_sRoom >> m_iSex >> m_iStatus;
}
|
|
|
|
|
What are the data types for the member variables and if you open file were the contents saved as expected ?
Do a test with CString variables to make a test file if you are uncertain about what should happen when storing.
Elaine
The tigress is here
|
|
|
|
|
Problem solved, there's nothing wrong with the code. actually i have another similar application, it's because the save-filetype (fdb) for both applications are the same, so when i save using the second application, the window uses my first application to open and resulting in 'unexpected file format'.
|
|
|
|
|
|
Hello Friends
I have an application in which I need to start one exe from another one and at the end when the first one ends, it should automatically end the second one.
To start I use ShellExecute() or WinExec() function. And to terminate the another exe I put code into the destructor of the first one from where I have started it. But the problem is I don't know the Handle of the new exe that I have started using ShellExecute() or WinEec().....
Is there any functions which can give me the Handle of a perticular window or is there any other way to stop the application without knowing the handle or process id ?
Thankx in advance
My Code Looks Like :
-------------------
My first.exe file
================
MyClass()
{
// Do some work here........
WinExec("C:\\Temp\\second.exe",SW_SHOW);
// Do some work here...
};
~MyClass()
{
Here I want to kill(Terminate) the second.exe
}
Any help plz ?
Thankx
}
}
Amarelia Maehsh
Gujarat
India
|
|
|
|
|
You could use CreateProcess() and TerminateProcess(), however TerminateProcess() ends a program so abruptly that some applications don't handle it well, it doesn't give them time to save their settings or other exit code. I'd recommend using FindWindowEx() and sending a WM_CLOSE to the main window.
|
|
|
|
|
|
Not a good idea if handling other messages during shutdown is a concern. Call PostMessage(WM_CLOSE) instead. PostQuitMessage() does not shut down an application properly as other messages might be initiated by the shutdown operation (e.g., save the document?) and those messages, along with any other messages that might be in the queue, will not be processed.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
|
Thankx for taking time to read my question...
Amarelia Maehsh
Gujarat
India
|
|
|
|
|
Thankx a lot for giving attention to my question ....
Amarelia Maehsh
Gujarat
India
|
|
|
|
|
Amarelia wrote:
But the problem is I don't know the Handle of the new exe that I have started using ShellExecute()...
Why not? It's in the PROCESS_INFORMATION structure that ShellExecute() populates.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Thank you very much
I did the same but bit differently. I used CreateProcess() and in that there is last parameter as [out] parameter which is PROCESS_INFORMATION structure and I use that to close application.
thankx once again
Amarelia Maehsh
Gujarat
India
|
|
|
|
|
I'm glad you figured it out because my suggestion was wrong. I meant to say CreateProcess() not ShellExecute() .
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
How to check the type of the mouse using Win32? Is there any API? Please help.
Software Developer
Sanjay Khapre
|
|
|
|
|
You can get some of the properties using GetSystemMetrics().
SM_CMOUSEBUTTONS will get you the number of buttons.
SM_MOUSEWHEELPRESENT will tell you if it has a wheel.
SM_SWAPBUTTON will tell you if they swapped their buttons (left handed).
|
|
|
|
|
I have created a bmp file.
Using CImage can load the file and save as a another file format like tiff, but how can i set the DPI of the image.
Please help, thanks.
|
|
|
|
|
|
I am declaring a list and add in contents into it~
But i am always unpredictably facing the display problem~
For example, i am reading information from a database entry by entry, but what is displayed in the list control is totally out of order, and correspondance is wrong. what is worse, some of the colums are blank though i can see the entries are correctly inserted into the list(i have traced this using break point).
The code i used is as below:
(m_bList is the list control declared)
int index;<br />
for(index = 0; index < total; index++)<br />
{<br />
LV_ITEM lvi;<br />
lvi.mask = LVIF_TEXT;<br />
<br />
lvi.iItem = index;<br />
lvi.iSubItem = 0;<br />
lvi.pszText = (LPSTR)(LPCSTR)sbatchid;<br />
lvi.lParam = 1;<br />
m_bList.InsertItem(&lvi); <br />
<br />
lvi.iSubItem = 1;<br />
lvi.pszText = (LPSTR)(LPCSTR)page;m_bList.SetItem(&lvi);<br />
<br />
CString modi = time.Format("%Y/%m/%d/%H:%M");<br />
<br />
lvi.iSubItem = 2;<br />
lvi.pszText = (LPSTR)(LPCSTR)modi;<br />
m_bList.SetItem(&lvi);<br />
}
|
|
|
|
|
zhaopi wrote:
what is displayed in the list control is totally out of order
First thought (without reading your code) have you disabled the "Sorted" option of the list control ?
~RaGE();
|
|
|
|
|
Second thought, after reading the code :
It is a safe thing to zero the LVITEM struct (you wrote LV_ITEM, but it is in fact LVITEM) before using it.
LVITEM lvi;
ZeroMemory(&lvi,sizeof(lvi));
It is also not a bad idea to check for the result of the InsertItem and SetItem functions before going on.
Last thing to do is maybe to prevent updating the control before it is entirely full, or use virtual list if you are dealing with database entries (search on Code Project for virtual lists).
But the code seems OK to my point of view. You should really check that the Sort ComboBox in the Properties of the control is set on "None" (in the VC++ Dialog Editor). Or programatically unset the LVS_SORTASCENDING and LVS_SORTDESCENDING window styles of the control.
~RaGE();
|
|
|
|
|
Thanks for your reply first~
I have checked the sort combobox, unfortunately it is set to none.
For the result of insertitem, it is always returning 0 which seems to be fine~
and the setitem function is returning 1 for successful.
And how should i use zeromemory function, since it seems to be deleting the LVITEM and all the items are failed to be displayed in the list~
|
|
|
|
|
zhaopi wrote:
And how should i use zeromemory function, s
For initialisation of your lvi variable. Use it just once, after the variable definition:
LVITEM lvi;
ZeroMemory(&lvi,sizeof(lvi));
Now you can use lvi safely.
~RaGE();
|
|
|
|
|
How about:
for (int index = 0; index < total; index++)
{
int item = m_bList.InsertItem(index, 0, sbatchid);
m_bList.SetItemText(item, 1, page);
m_bList.SetItemText(item, 2, time.Format("%Y/%m/%d/%H:%M"));
}
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|