|
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++
|
|
|
|
|
Look for WORD Automation, as said in the post above you would need to consume the methods exposed by WORD interfaces and implement them.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Hi all,
I developed an application as an installation in VC++. I am using Visual Studio 2005. The installation works perfectly. The problem arises when I am trying to install the application in a system without .net framework. Then the installation fails. I don't know why this happens. How can I remove this error?
Can anybody please help me...
Thanks in Advance.....
|
|
|
|
|
Run vcredist_x86 on the other computer to install the CRT DLLs.
|
|
|
|
|
how can i treat an item( in the 1st column) in a list control as a button.
that means selecting a row, it similar with pressing a button.
thanks
|
|
|
|
|
The item is marked as selected when the user clicks on the item. You can handle the item click event and then perform some action as it's done for a button.
I hope that I do get you correctly, or you would have to provide a few more details.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
which functino can i use to make an item click event
|
|
|
|
|