|
|
|
Read this[^].
It is quite similar to what I always do when developing solutions for serial communication.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
I want to do two to three tasks at the same time at regular interval ,time is important so i m using multimedia timer .
problem is ....timer run the thread only once .code is below
when I click button thread is created and multimedia timer is set.
count is an integer initialized with 0
void CTimerDlg::Onbtnstart()
{
Thread=AfxBeginThread(ThreadDisplay, this, THREAD_PRIORITY_TIME_CRITICAL,0 ,CREATE_SUSPENDED);
handle=Thread->m_hThread;
Thread->m_bAutoDelete=false;
timeSetEvent(100, 0, TimeProcVideo, (DWORD)this, TIME_PERIODIC);
}
//thread analyzing data
UINT ThreadDisplay(LPVOID lParam)
{
CTimerDlg *obj=(CTimerDlg*) lParam;
obj->abc();
return 1;
}
void CTimerDlg::abc()
{
count++;
char a[20];
GetDlgItem(IDC_STATIC)->SetWindowText("");
CString s=itoa(count,a,10);
GetDlgItem(IDC_STATIC)->SetWindowText(s);
SuspendThread(handle);
}
void CALLBACK TimeProcVideo(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
CTimerDlg* timer=(CTimerDlg*) dwUser;
timer->ControlThreads();
}
void CTimerDlg::ControlThreads()
{
ResumeThread(handle);
}
modified on Friday, November 28, 2008 11:18 PM
|
|
|
|
|
|
i want to show some icons or bitmaps on status bar, how can i do this?
thanks in advance.
|
|
|
|
|
This[^]might help
Some things seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
I want to enumerates ac3filter's preferred media types, I suppose this process should be very easy, but I can't get this work.
PLZ help!
int _tmain(int argc, _TCHAR* argv[])
{
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
CLSID clsid;
::CLSIDFromString(_T("{A753A1EC-973E-4718-AF8E-A3F554D45C44}"), &clsid);
IBaseFilter* pFilter = NULL;
HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, __uuidof(IBaseFilter), (void **)&pFilter);
IEnumPins* pEnumPins = NULL;
hr = pFilter->EnumPins(&pEnumPins);
if (SUCCEEDED(hr))
{
IPin* pPin = NULL;
while (pEnumPins->Next(1, &pPin, NULL) == S_OK)
{
PIN_DIRECTION pinDir;
pPin->QueryDirection(&pinDir);
IEnumMediaTypes* pEnumMediaTypes = NULL;
HRESULT hr = pPin->EnumMediaTypes(&pEnumMediaTypes);
if (SUCCEEDED(hr))
{
AM_MEDIA_TYPE* pMediaType = NULL;
hr = pEnumMediaTypes->Next(1, &pMediaType, NULL);
pEnumMediaTypes->Release();
}
pPin->Release();
}
pEnumPins->Release();
}
return 0;
}
A Chinese VC++ programmer
|
|
|
|
|
I'm not an expert on Pins, but I'm sure you can give more information on your problem.
*What* didn;t work? Does it not compile?
Does CoCreateInstance even work?
Does it give success code, but no Pins?
Do you get enumerators, they just are empty?
Etc.
We're not going to visit you and sit at your computer and use the debugger. China is a long way from here!
Iain.
|
|
|
|
|
Thank you Iain.
As I commentted in the code, everything looks finely.The filter can be created; the pins can be enumerated; and the direction of the pins can be queried too, but when it comes to the media types of a given pin, IEnumMediaTypes::Next always returns S_FALSE.
So I can't numerates media types on a given pin.
A Chinese VC++ programmer
|
|
|
|
|
I am implementing multi-threaded application in C++ in which I have 2 functions i.e. 1. Read 2. Write and both are sharing one global variable.
There are 10 threads,1 thread will use write function and rest 9 will use read function.When writing is taking place, all thread should wait else remaining 9 threads should not wait to read.
Now my question is how to use the synchronization technique so that 9 threads should not wait if no writing is taking place.
Thanks
|
|
|
|
|
Use CSemaphore with CSingLock/CMultiLock. You can call a lock on the object/resource while writing is in progress
Some things seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
But Semaphore is use to limit the number of thread, where as my requirement is different.
I don't want to limit my number of read and write thread. Actually i want that if any writing there is in progress then other all thread ( read and write) must wait. where as any number of reading thread can run concurrently.
I believe that this can be archived by WaitForMultipleObject. but how to use it.
Any link for the same or any hint.
Thanks
|
|
|
|
|
Semaphore does allow you to access the resources when the threads are limited, and is not used to limit the number of threads.
MSDN - ***An object of class CSemaphore represents a "semaphore" — a synchronization object that allows a limited number of threads in one or more processes to access a resource
If you want to use WaitForMultipleObject than you can store the handles of the thread in an array and then pass this as a parameter to it.
Some things seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
In such scenario (one writer, multiple readers), you can avoid using critical section using guards 'around' your variable. Suppose you use two integers, m_iSeqId1 and m_iSeqId2 (both initialized to 0). Your writer thread will first increase m_iSeqId1, then update the new value, then increase m_iSeqId2 (so that it becomes equal to m_iSeqId1). Your reader threads first read m_iSeqId2 (yes m_iSeqId2 and not m_iSeqId1), read the value and then read m_iSeqId1. If both sequence Ids are the same, the value can be read and is not corrupted. If the Ids are different, the read should repeat the full operation until both Ids are the same.
But, this is only usefull when you are working with variables that cannot be set in one single instruction (e.g. an array, a string, an object, ...). Assignements of simple types (like int, char, ...) are atomic.
|
|
|
|
|
singh_nav wrote: Now my question is how to use the synchronization technique so that 9 threads should not wait if no writing is taking place.
Reader Writer Lock[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Can you please explain what you mean exactly by "pop_up interface" ?
|
|
|
|
|
do you mean a pop up window/menu?
Some things seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
Hi,
I used CreateFileMapping() to map a file. Will this work with drive handle to map a drive? I tried but not wotking.
|
|
|
|
|
Hi,
I m trying to load a resource dll to my application but its failing with error code 126(which says dll not found).
I have also checked the path manually as well as using CFileFind (and it shows that dll is there).
One more thing i have also checked the same code with normal dll(i.e. which has some code) and it works absolutely fine.
Does anyone has any idea or hint about this?
Is it related to trusted dll?
Thanks in Advance!
Tony
|
|
|
|
|
It might help if you showed some code and said where the file is located.
|
|
|
|
|
CString strPath = "C:\\Test\\SampleResource.dll";
CFileFind Ff;
bool bIsFilePresent = Ff.FindFile(strPath); // It returns true
HINSTANCE hTest = LoadLibrary(strPath); // It returns NULL
DWORD dwError = GetLastError();// It returns 126
I hope this piece of code is understandable.
Thanks.
|
|
|
|