|
Hi,
I am working with threads. I have a thread safe class as shown below.
class CUxx_MS_ListWordToPtr
{
// VARIABLE DECLARATION SECTION
public:
private:
//##ModelId=38BB19E501C9
CUxx_MS_CriticalSection m_Lockable;
//##ModelId=38BB19E501B5
CMapWordToPtr* m_List;
CSemaphore threadlock;
// FUNCTION DECLARATION SECTION
public:
// Construction
//##ModelId=38BB19E50291
CUxx_MS_ListWordToPtr(int nBlockSize = 10)
{
m_List = new CMapWordToPtr(nBlockSize);
}
// lock functions
//##ModelId=38BB19E50290
void Lock()
{
m_Lockable.Lock();
}
//##ModelId=38BB19E50287
void Unlock()
{
m_Lockable.Unlock();
}
// Attributes
// number of elements
//##ModelId=38BB19E50286
int GetCount() const
{
//CUxx_MS_Lock localLock((class CUxx_MS_LockableObject *) &m_Lockable);
// CUxx_MS_CriticalSection cs;
CSingleLock singleLock( (CSyncObject*)&threadlock);
singleLock.Lock();
int count = m_List->GetCount();;
singleLock.Unlock();
return count;
}
//##ModelId=38BB19E5027D
int GetCountNoLock() const
{
return m_List->GetCount();
}
//##ModelId=38BB19E5027C
BOOL IsEmpty() const
{
//CUxx_MS_Lock localLock((class CUxx_MS_LockableObject *) &m_Lockable);
CSingleLock singleLock( (CSyncObject*)&threadlock);
singleLock.Lock();
BOOL flag = m_List->IsEmpty();
singleLock.Unlock();
return flag;
}
//##ModelId=38BB19E50274
BOOL IsEmptyNoLock() const
{
return m_List->IsEmpty();
}
........
}
The way I use this class is
CTypedPtrMap<cuxx_ms_listptrtoptr, cmemmapmgr*,="" cstring*=""> ListOutput;
when I call methods like,
CString* pCStr;
CMemMapMgr* pCommunicationObject;
ListOutput.Lookup(*pCStr, pCommObject), sometimes it shows an error message->
The instruction at ".." referenced memory at " ", The memory could not be read and when I debug the code, it shows the root as
BOOL CSingleLock::Lock(DWORD dwTimeOut /* = INFINITE */)
{
ASSERT(m_pObject != NULL || m_hObject != NULL);
ASSERT(!m_bAcquired);
m_bAcquired = m_pObject->Lock(dwTimeOut);
return m_bAcquired;
}
Can anyone please help me to understand the reason for this crash and how to resolve this one?
Thanks
|
|
|
|
|
[Deleted - posted incorrectly - see next post]
|
|
|
|
|
You really need to format your code using the PRE tags...!
Anyway, in this code:
CString* pCStr;
CMemMapMgr* pCommunicationObject;
ListOutput.Lookup(*pCStr, pCommObject); You are using two uninitialized pointers there, and dereferencing the first one, which is likely the cause of your crash.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
I have a dialog based app which has a progress bar and other controls. I want to process some stuff in the background moving the progress bar, but not blocking the main process thread. I tried using threads but the child threads cannot move the progresss bar even if i pass the progress bar argument to the child thread.
Does anybody have any ideas??
Another idea could be create a new process and let it run and use intrprocess communication but still the parent process is blocked
I think i am just complicating things because many applications have this functionality
Any ideas would be greatly appreciated.
Kelvin Chikomo
|
|
|
|
|
theprinc wrote: I tried using threads but the child threads cannot move the progresss bar...
Nor should they. The secondary thread(s) should be posting a message back to the primary thread (which owns the progress control) to update the UI.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
How do you post messages back to the primary thread without blocking the primary thread.
Any sample code would help
Kelvi Chikomo
|
|
|
|
|
When you start your second thread, you give it the handle to the window to which it will post messages. Then, to post messages, simply use PostMessage which doesn't block the thread.
|
|
|
|
|
theprinc wrote: How do you post messages...
By using PostMessage() .
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
Say I use the PostThreadMessage() method the primary thread would have to have some sort of a loop to keep reading the messages therefore keeping the primary process busy.
The secondary thread would be sending lots of messages
Kelvin Chikomo
|
|
|
|
|
The primary thread, the one that owns the GUI, has a message queue, and a message pump to process messages in that queue. See here for more.
theprinc wrote: The secondary thread would be sending lots of messages
For just the updating of a progress bar? Even so, it's doubtful you'll exceed the maximum size of the message queue. You might look at using an I/O Completion Port to queue messages to the main GUI thread. See here for an example.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
Thanks dude. I am going to try it using peekMessage() in an MFC environment hope it works
Kelvin Chikomo
|
|
|
|
|
theprinc wrote: I am going to try it using peekMessage() in an MFC environment hope it works
Why? An application's primary thread already has a message pump. No need to reinvent the wheel.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
I dont know how to use the message pump do you have any references
Kelvin Chikomo
|
|
|
|
|
For most applications, there is no need to interface with the message pump, or even the message queue. It's all handled nicely for you. See that worker-thread link I referenced earlier.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
recently, I use the MFC's CSplitterWnd to split main frame as like "-|" with left pane and right pane , and I also split right pane to top sub-pane and bottom sub-pane, but I want to fix the boder bar between left and righ pane to avoid user to size. Has anyone some ideas to do that? thanks in advance.
|
|
|
|
|
|
See the second question here.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
|
I am having a problem which is as follows see if u can help me-
i have the problem to send the data through serial port in visual c++.pls help me how to do this with the code that is working in window NT/XP enivironment.
|
|
|
|
|
And the problem is ?
What happens EXACTLY ? I mean, with sentences like "it doesn't work" we are unlikely to help you much.
|
|
|
|
|
Come on, it's Friday. Didn't you bring your ESP helmet?
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
DavidCrow wrote: Didn't you bring your ESP helmet?
ESP Helment...WOW is it available at Amazon... ..
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
I am guessing from your message that you just do not know where to start. I recommend you type 'serial port' in the Search box above and you will get plenty of articles to get you going.
Good Luck
Ali
|
|
|
|
|
omprakashsingh wrote: i have the problem to send the data through serial port in visual c++.pls help me how to do this with the code that is working in window NT/XP enivironment.
Could you show me you code snippet or error you getting while sending data to serial port.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
hi all
iam working on WMI . iam trying to write an application for Event notification.
Iam usimg Win32_Process class, and ExecNotificationQuery for WQl query.
Iam trying to display a message when a new process is created.
my WQL query is
hres = pSvc->ExecNotificationQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM __InstanceCreationEvent WITHIN 5 WHERE TargetInstance ISA 'Win32_Process' And (TargetInstance.Name = 'notepad.exe' OR TargetInstance.Name = 'calc.exe' ) "),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if iam not wrong ,After executing this query TargetInstance will be Instance of WIn32_process class.
and now iam trying extract data usoing this statement
hr = pclsObj->Get(L("TargetInstance.Name"), 0, &vtProp, 0, 0);
but iam not able to get value of Name property of Win32_Process class into vtProp where vtProp is of type VARIANT.
IWbemClassObject->Get( LPCWSTR wszName,LONG lFlags, VARIANT* pVal,CIMTYPE* pvtType, LONG* plFlavor) is used to retrieves Specified property value.
but here iam using it for getting value fron an istance i.e TargetInstance.Name. Is it the correct way to do if not please help me in extracting value of Name Property.
Please help me in solving this .
Thanks in advance
abhi
|
|
|
|