|
Hi,
in ur view which API can cause the deadlock(FindWindow() or PostMessage()).
I don't think that PostMessage() can cause a deadlock.
Thanks
|
|
|
|
|
FindWindow() internally sends each top-level window a WM_GETTEXT message. But if the thread that owns that window is blocked (e.g., a Semaphore, a Mutex, an Event, an I/O operation), SendMessage() will block until that thread frees up and runs. Since this could potentially never happen, FindWindow() will block forever.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello
I have a program using waveIn API.
This is part of my code.
Originally, my program has a deadlock while running waveInReset.
I google it and it is said putting the wavein function in the callback function is forbidden.
So I delete the code which I put waveinstop in the callback function.
It can run waveInReset and waveInunprepareheader successfully.
But it halt at waveInClose.
I can't find information about waveInClose halt.
Can anybody solve this problem?Thx,
Jane.
<br />
while(1){ if(isopen==1){<br />
if(waveInOpen(&hWavin,WAVE_MAPPER, &wfx,(DWORD_PTR)WaveInProc ,0, CALLBACK_FUNCTION) == <br />
MMSYSERR_NOERROR)<br />
{<br />
<br />
isopen=1;<br />
for(int i=0;i<4;i++)<br />
{ <br />
mmrr = waveInPrepareHeader(hWavin, headersend + i, sizeof(WAVEHDR));<br />
mmrr = waveInAddBuffer(hWavin, headersend + i, sizeof(WAVEHDR));<br />
}<br />
mmrr = waveInStart(hWavin); <br />
}<br />
}<br />
if(isclose==1)<br />
{ <br />
if(hWavin)<br />
{ <br />
mmrr=waveInReset(hWavin);<br />
<br />
for(int i=0;i<4;i++)<br />
{<br />
<br />
mmrr=waveInUnprepareHeader(hWavin,headersend+i, sizeof(WAVEHDR));<br />
} <br />
for(int i=0;i<4;i++)<br />
{<br />
mmrr=waveInReset(hWavin);<br />
} <br />
mmrr=waveInClose(hWavin);<br />
sclose=0;<br />
<br />
}<br />
}<br />
}<br />
static void CALLBACK WaveInProc(HWAVEIN hw, UINT uMsg,DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD dwParam2)<br />
{<br />
WAVEHDR* curhdrin = (WAVEHDR*)dwParam1;<br />
if(uMsg != WIM_DATA)<br />
return;<br />
if(isclose==1){<br />
<br />
Sleep(1000);<br />
return;<br />
}<br />
waveInAddBuffer(hw, curhdrin, sizeof(WAVEHDR));<br />
<br />
}
|
|
|
|
|
How does isclose ever get set to 1?
Why is there no waveInStop() call anywhere?
Why do you use the Sleep() call in the waveInProc?
That's really going to mess things up if isclose==1.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thx for ur reply.
I have a button that would let user click to stop recording.
That would make isclose = 1;
Originally, I use waveInStop but I waveInStop only stop recording.
waveInReset would stop recording and set the position to 0.
I see some information in the Internet that says use waveInUnPrepareHeader before using waveInReset.
Originally, I don't use Sleep() function,but it has same problem.
I write it in a new small program as follow.
It halts at waveInReset.
If I delete waveInReset, waveInUnPrepareHeader and waveInClose falses and returns 33.
#include "stdafx.h"<br />
#include <winsock2.h><br />
#include <windows.h><br />
#include <iostream><br />
#include <mmsystem.h><br />
#pragma comment(lib, "ws2_32.lib")<br />
#pragma comment(lib, "Winmm.lib")<br />
using namespace System;<br />
using namespace std;<br />
static void CALLBACK WaveInProc(HWAVEIN, UINT, DWORD , DWORD , DWORD );<br />
<br />
static const int SNDNBUF = 2;<br />
static const int SNDSIZEBUF = 320;<br />
HWAVEOUT hWavout;<br />
MMRESULT mmrr;<br />
WAVEHDR headersend[SNDNBUF];<br />
char hdrDatasend[SNDSIZEBUF*SNDNBUF];<br />
HWAVEIN hWavin;<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
WAVEFORMATEX wfx; <br />
wfx.nSamplesPerSec = 8000;<br />
wfx.nChannels = 1;<br />
wfx.wFormatTag = WAVE_FORMAT_PCM;<br />
wfx.wBitsPerSample = 16;<br />
wfx.nBlockAlign = wfx.nChannels * (wfx.wBitsPerSample / 8);<br />
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;<br />
<br />
memset(headersend, 0,sizeof(WAVEHDR)*SNDNBUF);<br />
for(int i=0;i<sndnbuf;i++){<br />
headersend[i].lpData = hdrDatasend + i*SNDSIZEBUF;<br />
headersend[i].dwBufferLength = SNDSIZEBUF;}<br />
<br />
memset(hdrDatasend,0,SNDSIZEBUF*SNDNBUF);<br />
<br />
if(waveInOpen(&hWavin,WAVE_MAPPER, &wfx,(DWORD_PTR)WaveInProc ,0, CALLBACK_FUNCTION) == MMSYSERR_NOERROR){<br />
for(int i=0;i<sndnbuf;i++)>{ <br />
mmrr = waveInPrepareHeader(hWavin, headersend + i, sizeof(WAVEHDR));<br />
mmrr = waveInAddBuffer(hWavin, headersend + i, sizeof(WAVEHDR));}<br />
mmrr = waveInStart(hWavin); }<br />
int i;<br />
cin >> i;<br />
mmrr=waveInStop(hWavin);<br />
mmrr=waveInReset(hWavin);<br />
Sleep(500);<br />
for(int i=0;i<sndnbuf;i++){<br />
if ((headersend+i)->dwFlags & WHDR_PREPARED){<br />
mmrr=waveInUnprepareHeader(hWavin,headersend+i, sizeof(WAVEHDR));}<br />
Sleep(500);<br />
mmrr=waveInClose(hWavin);<br />
cin >> i;<br />
return 0;<br />
}<br />
<br />
static void CALLBACK WaveInProc(HWAVEIN hw, UINT uMsg,DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD dwParam2)<br />
{<br />
WAVEHDR* curhdrin = (WAVEHDR*)dwParam1;<br />
if(uMsg != WIM_DATA)return;<br />
waveInAddBuffer(hw, curhdrin, sizeof(WAVEHDR));<br />
return;<br />
}</sndnbuf;i++)></mmsystem.h></iostream></windows.h></winsock2.h>
Jane
modified on Friday, January 11, 2008 4:23:59 AM
|
|
|
|
|
The order should be:
waveInStop
waveInReset
waveInUnprepareHeader (for all buffers)
And get rid of the Sleep() calls. There is absolutely NO reason for them.
When you prepare the headers, you must initialize dwFlags (Use 0 for input
buffers) as well as lpData and dwBufferLength.
Also, IMO, "headersend + i" is confusing to read. I'd use "&headersend[i]".
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi all,
I want to get a file path(say a text file) to read and do some processing on it. So the file path is like this, as an example.
"G:\\Work On\\CPP\\ReadFolder\\Data.txt"
So I want to change this path to refer another PC. How can I do it.
I appreciate your help all the time...
Eranga
|
|
|
|
|
change to something like this :
\\\\The_Machine_Name\\TheSharedFolder$\\Work On\\CPP\\ReadFolder\\Data.txt
for instance :
\\\\10.248.0.50\\C$\\Temp\\temp.txt
|
|
|
|
|
Thanks, that is what I have tried. But it not work. I check the error codes, get 123 - The file name, directory name, or volume label syntax is incorrect.
Then I removed $ and test, error code is 5, says access denied. Actually I have permission to access that machine.
I appreciate your help all the time...
Eranga
|
|
|
|
|
To replace the path but keep the same file name, do the below.
CString sOri = "C:\\Tmp\\Hello.txt";
CFile file(sOri, CFile::modeRead);
CString sNew = "\\\\192.168.0.3\\doc\\; // Get from some approach.
sNew += file.GetFileName(); // Result in "\\\\192.168.0.3\\doc\\Hello.txt".
Maxwell Chen
|
|
|
|
|
Ok, I solve this and found these things.
1) Should be shared
2) Should login as Admin to the file containing PC
3) Should have rite permission
What you guys think on my conclusion.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: 1) Should be shared
2) Should login as Admin to the file containing PC
Connecting via the admin share (C$) will get it done, but it would be better to create a specific share, and user account, for just what you need.
Eranga Thennakoon wrote: 3) Should have rite permission
Not necessary if all you're doing is reading from the file.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: Eranga Thennakoon wrote:
3) Should have rite permission
Not necessary if all you're doing is reading from the file.
but by rite, he meant write or right ?
|
|
|
|
|
toxcct wrote: he meant write or right ?
Yep!
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: Yep!
ok
|
|
|
|
|
|
DavidCrow wrote:
Not necessary if all you're doing is reading from the file.
Yes it is. Since I read it no need. It's my fault. I got that conclusion when I'm writing something to a file.
I appreciate your help all the time...
Eranga
|
|
|
|
|
how can i get the character inserted last in the edit box control.
last inserted character doesn't mean the last character of the corresponding string variable.
|
|
|
|
|
Handle the keydown (WM_KEYDOWN ) event.
Maxwell Chen
|
|
|
|
|
Can you use of GetWindowText for get string of edit ctrl?
|
|
|
|
|
He wants to know the last character which user inserted.
For example,
Originally the text in the Edit Control was:
Hllo. Then user inserted an 'e ' to become:
Hello.
Maxwell Chen
|
|
|
|
|
I think yes my answer not good.
|
|
|
|
|
But to get the WM_KEYDOWN for a edit box he has to subclass the edit box.
|
|
|
|
|
Subclass the edit control and handle the WM_CHAR message.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
How do i display time and date in an application? the current time and the current date.
|
|
|
|