|
The Server stalled posting this one, (and crashed my Laptop) Tought it was Lost.
Good for You, Enjoy
Bram van Kampen
modified on Saturday, July 12, 2008 9:02 PM
|
|
|
|
|
led mike wrote: I'm outta here, have a great weekend!
Just Enjoy, You Deserve.
Wish I was there thoug,
Regards
Bram van Kampen
|
|
|
|
|
What class is your view derived from?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
CrocodileBuck wrote: fom CView !
And you're using SetWindowText() ? I've not ever tried that, but it just seems odd.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Sry, i was too fast, but your version won't work Too !
Thax for all your help & best regards
Croc
|
|
|
|
|
I inserted a shockwaveflash activex control in my project, and it works.
How to find the file (eg. .ocx)? The "Insert ActiveX Control" dialog shows no path info.
system
|
|
|
|
|
Working with EVc++4 on ARMV4I device.
I have an CArray :
CArray<CStockEntry, CStockEntry> stockArr;
void SetCStockEntryArr(CArray<CStockEntry, CStockEntry>& arr);
CArray<CStockEntry, CStockEntry>& GetStockEntryArr();
in my .cpp:
void DeptStock::SetCStockEntryArr(CArray<CStockEntry, CStockEntry>& arr) {
for (int i=0; i <= arr.GetUpperBound(); i++) {
CStockEntry se = arr.GetAt(i);
this->stockArr.Add(se);
}
CString s1 = _T("Size of copied Array & Org:");
s1.Format(_T("%s %d %d"), s1, stockArr.GetSize(), arr.GetSize());
AfxMessageBox(s1);
s1.Empty();
return;
}
CArray<CStockEntry, CStockEntry>& DeptStock::GetStockEntryArr() {
CString s1 = _T("Size of Returning Array:");
s1.Format(_T("%s %d"), s1, stockArr.GetSize());
AfxMessageBox(s1);
s1.Empty();
return this->stockArr;
}
In between Set & Get I don't perform any operations on the stockArr.
Why is while set, it is stored properly, but while retriing I get an empty array.
Any help is appreciated.
Thanks
Terry
|
|
|
|
|
I tested your code as follows:
struct CStockEntry
{
int entry;
CStockEntry(int i = 0) {entry = i;}
};
class DeptStock
{
public:
CArray<CStockEntry, CStockEntry> stockArr;
void SetCStockEntryArr(CArray<CStockEntry, CStockEntry>& arr)
{
for (int i=0; i <= arr.GetUpperBound(); i++)
{
CStockEntry se = arr.GetAt(i);
this->stockArr.Add(se);
}
CString s1 = _T("Size of copied Array & Org:");
s1.Format(_T("%s %d %d"), s1, stockArr.GetSize(), arr.GetSize());
AfxMessageBox(s1);
s1.Empty();
return;
}
CArray<CStockEntry, CStockEntry>& GetStockEntryArr()
{
CString s1 = _T("Size of Returning Array:");
s1.Format(_T("%s %d"), s1, stockArr.GetSize());
AfxMessageBox(s1);
s1.Empty();
return this->stockArr;
}
};
...
CArray<CStockEntry, CStockEntry> stockArr;
stockArr.Add(CStockEntry(0));
stockArr.Add(CStockEntry(1));
stockArr.Add(CStockEntry(2));
stockArr.Add(CStockEntry(3));
stockArr.Add(CStockEntry(4));
DeptStock test;
test.SetCStockEntryArr(stockArr);
CArray<CStockEntry, CStockEntry> &stockArrRef = test.GetStockEntryArr();
It works fine.
What aren't you showing?
FWIW, calling Empty() on those local CStrings is unnecessary.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark,
If I add objects in array like you are adding, then my code is working perfect. But I am working different way. In my GUI, I add objects in the array in my GUI CPage4 (m_page4 member var), then on Ok button I create DeptStock deptStock object & SetCStockEntryArr(m_page4.GetStockEntries()).
TILL this things are fine.
Then I pass deptStock to a file to store the object details in file.
g_dbOperations.Write_StockTextFile(deptStock);
void DbOperations::Write_StockTextFile(DeptStock deptStock) {
.........
CString toWrite;
int index = -1;
OperatorDetails od = deptStock.GetOperator();
DeptDetails dd = deptStock.GetDept();
CArray<cstockentry,>& stockArr = deptStock.GetStockEntryArr();
CString str(_T("Stock Size:"));
str.Format(_T("%s %d \n %s %d"), str, stockArr.GetSize(), _T("Dept Stock Arr "), deptStock.GetStockEntryArr().GetSize());
AfxMessageBox(str);
This is how the flow is. If I remove the above comments of adding objects od CStockEntry to stockArr, it gives proper results. But I have already added the array elements & not able to retrive.
I have given a better & clear picture of the flow of my program & error point. Hope you can help me out to track the problem.
Thanks
Terry
|
|
|
|
|
Trupti Mehta wrote: If I add objects in array like you are adding, then my code is working perfect.
That should help you track it down. If your array is empty, debug the code
that's supposed to populate it...why are no items added?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am displaying some text in a window.
I want to have a text cursor when I click the mouse left button.
How can I do this?
danginkgo
|
|
|
|
|
danginkgo wrote: I am displaying some text in a window.
I want to have a text cursor when I click the mouse left button.
How can I do this?
Well it's called a Caret, but if you are trying to create your own text editing window you have a lot of work to do.
SetCaretPos[^]
led mike
|
|
|
|
|
Hi,
i want to draw the graph in excel by parsing file,
so when i have parsed the data, in that period i want to hide the construction of the graph between the parsing process completion,In Excel we can write this script to hide the Macro:
Application.ScreenUpdating = false or true,
and between this processing period we can show message in status bar by using this
Application.StatusBar = "Now processing File "
Application.StatusBar = false;
i want to do this in the C++, Is that any method available in that which can corelate the same functionality as like as excel scripting..
Thanks in advance,
Regards,
Vimal
|
|
|
|
|
|
Hi,
I have thread running. It will EnterCriticalSection at some poit. This works perfectly alright on Windows XP or lower versions of OS. But it is not working on Vista. Sometime it works but sometimes it doesn't. It always stuck at EnterCriticalSection(). It is not able to get the ownership. I have written code like:
pReadList->Request(); //This function calls EnterCriticalSection(. But it will always stuck on Vista.
if( some condition )
{
//some action
}
pReadList->Release() //This function calls LeaveCriticalSection() API.
Please help.
Thanks
|
|
|
|
|
SRKSHOME wrote: This works perfectly alright
Extremely unlikely. "Appears to work perfectly" is probably more accurate.
You don't show any relevant code, so it's tough to offer any kind of help.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Here is sample code. Please help
void DSReadableConnectionThread::RemoveConnection( const DSReadableConnection &connection )
{
pReadList->Request(); /*Request()calls ::EnterCriticalSection().This works in windows xp and below versions of OS. But it is not working on Vista. It contineously wait at EnterCriticalSection().
pNewConnectionList>Request();*/
if( !pReadList->Remove(connection) )
{
pNewConnectionList->Remove( connection );
}
// If no connections to process then put ThreadMain() to sleep
if( pReadList->isEmpty()&& pNewConnectionList->isEmpty() )
{
ready.ClearSignal();
}
pNewConnectionList->Release();
pReadList->Release();
}
|
|
|
|
|
The only way this can happen is if another thread is already "in" the
critical section. But that wouldn't work on any OS.
If you can put together a project that builds and fails that will run on
my machine, I can take a look. Otherwise it's really hard to debug from here
There's still no relevant code I've seen. Is the critical section initialized properly
before any thread tries to enter it?
Are you positive it's deadlocking at the EnterCriticalSection?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I checked it again. Initialization of critical section is properly done.
Here is actual code goes..
inline void Request() const
{
EnterCriticalSection( &_section ); //Here actually it stuck on Vista.
::InterlockedIncrement(&m_nLockCount);
}
If some other thread is using this crititcal section,it shouldn't have worked on any other os also.But it is working perfectly except on Vista.
Is there any change on Vista architecture in threading and synchronization. Something is mentioned in this link: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=510229&SiteID=1
Do you have any idea on this?
|
|
|
|
|
The only difference in Vista is the threading is more efficient.
The changes can expose problems in improperly written threading code
(not as many problems as multi-core machines expose ).
You've got some kind of deadlock. Maybe put TRACE statements before
and after EVERY enter/leave of the critical section and see if you can find
it. I don't know what else to say except you need to debug it.
Why the InterlockedIncrement() call? What is the critical section protecting?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi...
I have checked it again. I don’t think there is any deadlock present. There is no resource as such on which more than 1 threads are waiting.
LockCount - RecursionCount = Number of waiting threads
In my case, Number of waiting threads = 0.
But I found one more interesting thing on vista. WaitForSingleObject() is used here. When I called this function with TIMEOUT=INFINITE. It is not coming out of loop at all. It will be looping there. On Vista WaitForSingleObject() returns 258(I guess it is=WAIT_TIMEOUT). But on XP and lower versions of OS this function returns 0(I guess it is=WAIT_OBJECT_0) and come out of the of the loop.Please see the below code.
bool DSEventSemaphore::WaitForSignal( DWORD TimeOut ) //TimeOut=INFINITE
{
if( State == SemInvalid )
{
return false;
}
DWORD retval;
#ifndef DSTRACEABLE_SIGNAL_STACK /*I haven't defined it. So it wiil not execute.*/
retval = WaitForSingleObject( event, TimeOut );
#else //It will come here
do
{ retval = WaitForSingleObject( event, (TimeOut< DSSLEEP_PERIOD ? TimeOut : DSSLEEP_PERIOD) ); //DSSLEEP_PERIOD=500
if( retval == WAIT_TIMEOUT )
{
if( TimeOut < DSSLEEP_PERIOD )
{
TimeOut = 0;
}
else
if( TimeOut != INFINITE )
{
TimeOut -= DSSLEEP_PERIOD;
}
}
else
{
TimeOut = 0;
}
} while( TimeOut );
#endif
switch (retval)
{
case WAIT_OBJECT_0:
State = SemOK;
return true;
case WAIT_TIMEOUT:
State = SemTimeOut;
Error = GetLastError();
return false;
case WAIT_FAILED:
default:
Error = GetLastError();
State = SemSystemError;
return false;
}
}
Could you please help me.
|
|
|
|
|
Forget about the difference between XP and Vista. It's not relevant
at all. The same threading rules apply as always. Vista can be much
more efficient at exposing faulty threading code. If it works on one
OS and not on another, then it DOESN'T WORK. I've found bugs YEARS
after I wrote the code that suddenly fail on a new OS. Also moving
from single core to multi-core machines can expose threading bugs.
Back to your code...
If WaitForSingleObject(INFINITE) is blocking forever, then the handle
is never getting signaled. It's that simple.
What code is responsible for signaling the event?
(FWIW, "event" is a keyword in C++ - you may not want to use that as a variable name )
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi mark,
Finaly I am able resolve the issue.This issue is a classical example of starvation. The critical section is held by thread and is being released and requested again immediately in a tight while loop. This never allows other threads to acquire the critical section. But it is working on xp OS. This was leading to starvation on vista for the thread/threads waiting on that critical section. I have used the SwitchToThread() API call( sleep() also serve the purpose).But I found SwitchToThread() is better option. Looks like threading model on Vista is more efficient.
thanks for your help.
|
|
|
|
|
It's "stuck" because that critical section is being used by another thread!
One possibility is that an exception is being thrown over the release.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|