|
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
|
|
|
|
|
Thanks for the comments and links.
Ken
|
|
|
|
|
Use an “event” — a synchronization object that allows one thread to notify another that an event has occurred. Events are useful when a thread needs to know when to perform its task. For example, a thread that copies data to a data archive would need to be notified when new data is available. Look for CreateEvent(), SetEvent(), WaitForSingleObject(), etc.
|
|
|
|
|
Hiya when I use these Win32 functions for the registry:
#define REGKEY_SOFTWARE "Pass1"
#define REGKEY_DIRECTORY_PATH "Software\\Projects\\Password"
rc = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
REGKEY_DIRECTORY_PATH,
0,
KEY_QUERY_VALUE | KEY_SET_VALUE,
&hKeyParent );
and then this:
rc = RegSetValueEx( hKeyParent,
_T("Project Password"),
0, REG_SZ,
(const unsigned char *)(REGKEY_SOFTWARE),
sizeof( REGKEY_SOFTWARE) );
it is fine. It inserts my key into the registry no problem. But when I swop RegOpenKeyEx for:
CRegKey *pRegKey;
pRegKey = new CRegKey;
rc = pRegKey->Open( hKeyParent,
REGKEY_DIRECTORY_PATH,
KEY_READ | KEY_WRITE );
it doesn't put my key in. What am I doing wrong with this function??
I have error checking on Open and it returns no errors..
Thanks,
grahamoj.
|
|
|
|
|
You must follow the pRegKey->Open() call with a call to either pRegKey->SetKeyValue() or pRegKey->SetValue().
Why are you using a CRegKey pointer? Just declare it on the stack. Allocating little bits of memory like this is unnecessarily wasteful. Use new only when you have a compelling reason to do so.
|
|
|
|
|
How can you make a CView window appear OUTSIDE the CFrame (CMainFrame?).
The goal is to create a CMainFrame with multiple different CView classes that appear floating on the desktop that all attach to the same CDoc.
- Jeff Sidlosky
jsidlosky@yahoo.com
|
|
|
|
|
So you basically want a whole separate window. One solution is to call the view class Create(). Try with the different window properties.
Kuphryn
|
|
|
|
|
I have my own database server application that optionally runs as service. I need it to restart (or reinitialize in some other way) as the configuration files change. On initialization, I create and store the notification handle by calling FindFirstChangeNotification .
Where is the best place to put the wait function (WaitForSingleObject )?
Regards,
BB
|
|
|
|
|
Bartosz Bien wrote:
Where is the best place to put the wait function (WaitForSingleObject)?
In a separate thread...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Hi there.
Here's a pretty simple program:
void main(void) {
HRESULT hr = URLDownloadToFile(NULL, "http://www.google.com", "c:\\output.htm", 0, NULL) ;
if (SUCCEEDED(hr)) {
printf("success\n") ;
}
else {
printf("failed\n") ;
}
}
For some reason the URLDownloadToFile call fails. If I put any of a host of other urls in the call the download works perfectly, however, for www.google.com and several other pages (www.yahoo.es for one) the function just refuses to work. I'm completely baffled by this. I can't find any commonality between the pages that fail and I know that www.google.com does indeed exist on the internet.
Has anyone else had problems using the URLDownloadToFile function?
Thanks
|
|
|
|
|
It would help to know the error returned by URLDownloadToFile() . One possibility is that the server doesn't allow downloads without a proper HTTP_REFERER header, which is not present when using that API.
--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
|
|
|
|
|
I experimented with this method and got the same problem for google and a few other sites. The error code is 0x800401e4 which translates to "Invalid syntax"????
Art
|
|
|
|