|
see its my task to read all the files from usb and display it
|
|
|
|
|
My question was how different is reading a file from USB than reading a file from the hard disk? Can't you use CFile? What exactly are you unable to do?
|
|
|
|
|
those file will be in flash memory. how to read and write from it
|
|
|
|
|
Use CFile to read and write from and to files. You can work with files using CFile . You need not worry if the file is located in hard disk or a flash drive.
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
somebody would tell me why the following codes would failed at the calling:
lpDirectSound->CreateSoundBuffer(&BufferDesc,&pSoundBuffer,NULL);
CString strFile_in="sound.wav";<br />
LPVOID lpPtr1=NULL;<br />
LPVOID lpPtr2=NULL;<br />
HRESULT hr;<br />
DWORD dwLen1,dwLen2;<br />
LPVOID lp_mMemory=NULL;
LPVOID lpData=NULL;
LPWAVEFORMATEX lpWaveFormat=NULL;
DWORD dwSize=0;
CFile file;<br />
DWORD dwFileSize;
if(!file.Open(strFile_in,CFile::modeRead|CFile::shareDenyNone))<br />
{<br />
AfxMessageBox("Open the media file failed!");<br />
return ;<br />
}<br />
dwFileSize=file.Seek(0L,CFile::end);
file.Seek(0L,CFile::begin);
lp_mMemory=GlobalAlloc(GMEM_FIXED,dwFileSize);<br />
if(lp_mMemory==NULL)<br />
{<br />
AfxMessageBox("Allocate memory failed!");<br />
file.Close();<br />
return ;<br />
}<br />
if(file.ReadHuge(lp_mMemory,dwFileSize)!=dwFileSize)<br />
{<br />
AfxMessageBox("Read file error!");<br />
file.Close();<br />
GlobalFree(lp_mMemory);
return ;<br />
}<br />
file.Close();
<br />
LPDWORD lpdFile,lpdEnd;<br />
DWORD dwRiff,dwType,dwLen;<br />
lpdFile=(DWORD*)lp_mMemory;<br />
dwRiff=*lpdFile++;<br />
dwLen=*lpdFile++;<br />
dwType=*lpdFile++;<br />
if(dwRiff!=mmioFOURCC('R','I','F','F'))<br />
{<br />
AfxMessageBox("This is not a RIFF file!");<br />
GlobalFree(lp_mMemory);<br />
return ;<br />
}<br />
if(dwType!=mmioFOURCC('W','A','V','E'))<br />
{<br />
AfxMessageBox("This is not a WAVE file!");<br />
GlobalFree(lp_mMemory);<br />
return ;<br />
}<br />
<br />
lpdEnd=(DWORD*)((BYTE*)lp_mMemory+dwFileSize-4);<br />
BOOL bEnd=FALSE;<br />
while((lpdFile<lpdEnd)&&(!bEnd))<br />
{<br />
dwType=*lpdFile++;<br />
dwLen=*lpdFile++;<br />
switch(dwType)<br />
{<br />
case mmioFOURCC('f','m','t',' '):
if(!lpWaveFormat)<br />
{<br />
if(dwLen<sizeof(LPWAVEFORMATEX))<br />
{<br />
AfxMessageBox("There is some wrong in the file struct!");<br />
return ;<br />
}<br />
else<br />
lpWaveFormat=(LPWAVEFORMATEX)lpdFile;<br />
}<br />
break;<br />
case mmioFOURCC('d','a','t','a'):
if(!lpData||!dwSize)<br />
{<br />
lpData=(LPBYTE)lpdFile;<br />
dwSize=dwLen;<br />
if(lpWaveFormat)<br />
bEnd=TRUE;<br />
}<br />
break;<br />
}<br />
<br />
lpdFile=(DWORD*)((BYTE*)lpdFile+((dwLen+1)&~1));<br />
}<br />
<br />
DSBUFFERDESC BufferDesc;<br />
memset(&BufferDesc,0,sizeof(BufferDesc));<br />
BufferDesc.lpwfxFormat=(LPWAVEFORMATEX)lpWaveFormat;<br />
BufferDesc.dwSize=sizeof(DSBUFFERDESC);<br />
BufferDesc.dwBufferBytes=dwSize;<br />
BufferDesc.dwFlags=0;<br />
<br />
LPDIRECTSOUND lpDirectSound;<br />
hr=::DirectSoundCreate(0,&lpDirectSound,NULL);<br />
if(hr!=DS_OK)<br />
{<br />
AfxMessageBox("Create DirectSound failed!");<br />
GlobalFree(lp_mMemory);<br />
return ;<br />
}<br />
hr=lpDirectSound->SetCooperativeLevel(this->GetSafeHwnd(),DSSCL_NORMAL);<br />
if(hr!=DS_OK)<br />
{<br />
AfxMessageBox("SetCooperativeLevel failed!");<br />
}<br />
lpDirectSound->Initialize(NULL);<br />
LPDIRECTSOUNDBUFFER pSoundBuffer=NULL;<br />
hr=lpDirectSound->CreateSoundBuffer(&BufferDesc,&pSoundBuffer,NULL);<br />
if(hr==DS_OK)<br />
{<br />
hr=pSoundBuffer->Lock(0,dwSize,&lpPtr1,&dwLen1,&lpPtr2,&dwLen2,0);<br />
if(hr==DS_OK)<br />
{<br />
memcpy(lpPtr1,lpData,dwLen1);<br />
if(dwLen2>0)<br />
{<br />
BYTE* pData=(BYTE*)lpData+dwLen1;<br />
lpData=(void*)pData;<br />
memcpy(lpPtr2,lpData,dwLen2);<br />
}<br />
}<br />
pSoundBuffer->Unlock(lpPtr1,dwLen1,lpPtr2,dwLen2);<br />
DWORD dwFlags=0;<br />
pSoundBuffer->Play(0,0,dwFlags);<br />
}<br />
else<br />
{<br />
AfxMessageBox("Create buffer failed!");<br />
switch(hr)<br />
{<br />
case DSERR_ALLOCATED:<br />
AfxMessageBox("DSERR_ALLOCATED ");<br />
break;<br />
case DSERR_BADFORMAT:<br />
AfxMessageBox("DSERR_BADFORMAT ");<br />
break;<br />
case DSERR_INVALIDPARAM:<br />
AfxMessageBox("DSERR_INVALIDPARAM ");<br />
break;<br />
case DSERR_NOAGGREGATION:<br />
AfxMessageBox("DSERR_NOAGGREGATION ");<br />
break;<br />
case DSERR_OUTOFMEMORY :<br />
AfxMessageBox("DSERR_OUTOFMEMORY ");<br />
break;<br />
case DSERR_UNINITIALIZED:<br />
AfxMessageBox("DSERR_UNINITIALIZED");<br />
break;<br />
case DSERR_UNSUPPORTED :<br />
AfxMessageBox("DSERR_UNSUPPORTED ");<br />
break;<br />
case DSERR_INVALIDCALL:<br />
AfxMessageBox("DSERR_INVALIDCALL");<br />
break;<br />
}<br />
}<br />
GlobalFree(lp_mMemory);
Thanks
|
|
|
|
|
What error are you getting?
I'll look at your code if you edit your post and wrap the code in "pre" tags instead of "code"
tags.
The unindented, red text makes my eyes bleed
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I'm sorry.I will have a try to using 'pre' this time
CString strFile_in="sound.wav";
LPVOID lpPtr1=NULL;
LPVOID lpPtr2=NULL;
HRESULT hr;
DWORD dwLen1,dwLen2;
LPVOID lp_mMemory=NULL;
LPVOID lpData=NULL;
LPWAVEFORMATEX lpWaveFormat=NULL;
DWORD dwSize=0;
CFile file;
DWORD dwFileSize;
if(!file.Open(strFile_in,CFile::modeRead|CFile::shareDenyNone))
{
AfxMessageBox("Open the media file failed!");
return ;
}
dwFileSize=file.Seek(0L,CFile::end);
file.Seek(0L,CFile::begin);
lp_mMemory=GlobalAlloc(GMEM_FIXED,dwFileSize);
if(lp_mMemory==NULL)
{
AfxMessageBox("Allocate memory failed!");
file.Close();
return ;
}
if(file.ReadHuge(lp_mMemory,dwFileSize)!=dwFileSize)
{
AfxMessageBox("Read file error!");
file.Close();
GlobalFree(lp_mMemory);
return ;
}
file.Close();
LPDWORD lpdFile,lpdEnd;
DWORD dwRiff,dwType,dwLen;
lpdFile=(DWORD*)lp_mMemory;
dwRiff=*lpdFile++;
dwLen=*lpdFile++;
dwType=*lpdFile++;
if(dwRiff!=mmioFOURCC('R','I','F','F'))
{
AfxMessageBox("This is not a RIFF file!");
GlobalFree(lp_mMemory);
return ;
}
if(dwType!=mmioFOURCC('W','A','V','E'))
{
AfxMessageBox("This is not a WAVE file!");
GlobalFree(lp_mMemory);
return ;
}
lpdEnd=(DWORD*)((BYTE*)lp_mMemory+dwFileSize-4);
BOOL bEnd=FALSE;
while((lpdFile{
dwType=*lpdFile++;
dwLen=*lpdFile++;
switch(dwType)
{
case mmioFOURCC('f','m','t',' '):
if(!lpWaveFormat)
{
if(dwLen {
AfxMessageBox("There is some wrong in the file struct!");
return ;
}
else
lpWaveFormat=(LPWAVEFORMATEX)lpdFile;
}
break;
case mmioFOURCC('d','a','t','a'):
if(!lpData||!dwSize)
{
lpData=(LPBYTE)lpdFile;
dwSize=dwLen;
if(lpWaveFormat)
bEnd=TRUE;
}
break;
}
lpdFile=(DWORD*)((BYTE*)lpdFile+((dwLen+1)&~1));
}
DSBUFFERDESC BufferDesc;
memset(&BufferDesc,0,sizeof(BufferDesc));
BufferDesc.lpwfxFormat=(LPWAVEFORMATEX)lpWaveFormat;
BufferDesc.dwSize=sizeof(DSBUFFERDESC);
BufferDesc.dwBufferBytes=dwSize;
BufferDesc.dwFlags=0;
LPDIRECTSOUND lpDirectSound;
hr=::DirectSoundCreate(0,&lpDirectSound,NULL);
if(hr!=DS_OK)
{
AfxMessageBox("Create DirectSound failed!");
GlobalFree(lp_mMemory);
return ;
}
hr=lpDirectSound->SetCooperativeLevel(this->GetSafeHwnd(),DSSCL_NORMAL);
if(hr!=DS_OK)
{
AfxMessageBox("SetCooperativeLevel failed!");
}
lpDirectSound->Initialize(NULL);
LPDIRECTSOUNDBUFFER pSoundBuffer=NULL;
hr=lpDirectSound->CreateSoundBuffer(&BufferDesc,&pSoundBuffer,NULL);
if(hr==DS_OK)
{
hr=pSoundBuffer->Lock(0,dwSize,&lpPtr1,&dwLen1,&lpPtr2,&dwLen2,0);
if(hr==DS_OK)
{
memcpy(lpPtr1,lpData,dwLen1);
if(dwLen2>0)
{
BYTE* pData=(BYTE*)lpData+dwLen1;
lpData=(void*)pData;
memcpy(lpPtr2,lpData,dwLen2);
}
}
pSoundBuffer->Unlock(lpPtr1,dwLen1,lpPtr2,dwLen2);
DWORD dwFlags=0;
pSoundBuffer->Play(0,0,dwFlags);
}
else
{
AfxMessageBox("Create buffer failed!");
switch(hr)
{
case DSERR_ALLOCATED:
AfxMessageBox("DSERR_ALLOCATED ");
break;
case DSERR_BADFORMAT:
AfxMessageBox("DSERR_BADFORMAT ");
break;
case DSERR_INVALIDPARAM:
AfxMessageBox("DSERR_INVALIDPARAM ");
break;
case DSERR_NOAGGREGATION:
AfxMessageBox("DSERR_NOAGGREGATION ");
break;
case DSERR_OUTOFMEMORY :
AfxMessageBox("DSERR_OUTOFMEMORY ");
break;
case DSERR_UNINITIALIZED:
AfxMessageBox("DSERR_UNINITIALIZED");
break;
case DSERR_UNSUPPORTED :
AfxMessageBox("DSERR_UNSUPPORTED ");
break;
case DSERR_INVALIDCALL:
AfxMessageBox("DSERR_INVALIDCALL");
break;
}
}
GlobalFree(lp_mMemory);
|
|
|
|
|
Thanks
And what error are you getting?
Mark
Indentation is your friend!
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
there,the calling function:
lpDirectSound->CreateSoundBuffer(&BufferDesc,&pSoundBuffer,NULL);
would return a value: DSERR_INVALIDCALL!
|
|
|
|
|
In BufferDesc, is BufferDesc.lpwfxFormat valid? What are the values in the WAVEFORMATEX struct
pointed to by BufferDesc.lpwfxFormat?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Yes,it's valid.I can indicate.
|
|
|
|
|
Ok then I'm not seeing why CreateSoundBuffer would fail in your code.
Here's what I do different in my working code:
1) I use DirectSoundCreate8() instead of DirectSoundCreate()
2) For pDirectSound8->SetCooperativeLevel(), I use DSSCL_PRIORITY
3) For pDirectSound8->CreateSoundBuffer() -
for the DSBUFFERDESC.dwFlags I use DSBCAPS_GLOBALFOCUS | DSBCAPS_GETCURRENTPOSITION2
Those are the only differences I can see. You'll have to check all other parameters in the
debugger and see if they are valid.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hello all ,
I have made a Worker thread. In that worker thread i have a flag who's value i am increasing on particular conditions. I m returning same flag value from the thread but not getting how and where to retrieve that value.
Can anbody help me in this.
Thanks in advance.
|
|
|
|
|
Call GetExitCodeThread , see here [^] for details.
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.
|
|
|
|
|
Hello,
does std::vector have some function to search in?
I found iterator to loop over vector, but nothing for search!?
Thanks for any help
termal
|
|
|
|
|
// Console.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream> // For "cout"
#include <vector> // For "vector"
#include <algorithm> // For "find" and "copy"
#include <iterator> // For "ostream_iterator"
int main(int arvc, char* argv[])
{
using namespace std;
vector<int> ints;
for (int i=1; i<=10; ++i)
{
ints.push_back(i);
}
// Change first 5 to 50.
vector<int>::iterator it = find(ints.begin(), ints.end(), 5);
if (it != ints.end())
{
// We found 5, change it to 50.
*it = 50;
}
// Output the results.
copy(ints.begin(), ints.end(), ostream_iterator<int>(cout, " "));
cout << endl;
return 0;
}
Steve
|
|
|
|
|
Hello,
thanx for help!
I save a class derived from CObject in my vector, so i recive an error like this:
algorithm(43) : error C2678: binary '==' : no operator defined which takes a left-hand operand
of type 'class CMyObject' (or there is no acceptable conversion)
vector <CMyObject> VectorObjects;
class CMyObject:public CObject
{
....
}
CMyObject myObject;
myObject.iIndex = 1;
myObject.csName = "Test";
VectorObjects.push_back(myObject);
vector<CMyObject>::iterator it = find(VectorObjects.begin(), VectorObject.end(), myObject.iIndex);
I can sort and loop over my vector without errors, now is this the next to solve!
I try with pointer and without but still the same problem, any idea to solve this?
regards
termal
|
|
|
|
|
Try adding an == operator as follows:
class CMyObject <br />
{<br />
public:<br />
<br />
bool operator==(int val) const<br />
{<br />
return iIndex == val;<br />
}<br />
<br />
};
Steve
|
|
|
|
|
Hello,
an own relational operator? Ok, i try this now!
thanx
termal
|
|
|
|
|
Hello Steve,
yes that works!
Thank you wery much for help!
with best regards
termal
|
|
|
|
|
std::vector itself does not have any. But of course, std algorithms has many search tools.
Some of them;
std::binary_search
std::search
std::find
--
=====
Arman
|
|
|
|
|
Hello,
thanks for answer!
regards
termal
|
|
|
|
|
Please if any one have idea about developing a CD+G format CD burner, pls pls pls let me know.
|
|
|
|
|
Hello all,
I have to save a word document programmaticaly. anybody have idea about this please share with me.
Thanks
bankey
|
|
|
|
|
You need to use interfaces , exposed by MS Word, for this purpose.
For instance, some thing like _Document::Save .
Prasad
MS MVP - VC++
|
|
|
|
|