|
Thanks, it works fine so far...but the exception occurs very rarely so time will tell.
The problem with this kind of class is that you have to leave critical section explicitly so if you have functions with many return points you must copy the "Leave()" everywhere. Anyway I'm quite confident in this implementation.
|
|
|
|
|
>>The problem with this kind of class is that you have to leave critical section explicitly so if
>>you have functions with many return points you must copy the "Leave()" everywhere.
Cool. I guess I prefer it that way personally I can't recall ever needing to block an entire function.
Anyway I suspect the exception is unrelated to the critical section. But if it only rarely
happens I guess it's ok?
Best of luck,
Mark
|
|
|
|
|
You need two SEPARATE objects.
The first object constructor initializes the critical section, and its destructor deletes the critical section.
It has a member function Lock() and Unlock()
The second class, its constructor Enters the critical section of first object, by calling its Lock function. The destructor of this class calls the Unlock() of the first class.
That way, you don't have to worry about calling Unlock() explicitly from your code.
You also don't have to use a 'global' class from your common code, you use instances of the second class.
If you don't want to block out the entire scope of a function, then use the local scoping operators around the second class and the code like so
{
SecondClass MyLocker;
... code
}
and it will release when closing brace is met.
This is also handy when there is an exception, your critical section is not permanently locked and lost by the unwinding of the exception.
Any sufficiently gross incompetence is nearly indistinguishable from malice.
|
|
|
|
|
Hi all, i'm researching accessing data on a hard drive through using absolute addresses in C/C++. Somthing similar to "peek", and "poke", in
DOS-C. I Dont think its possible using visual studio.net, but someone may know somthing useful. Thanks.
p.s. This is my first question in my first forum, so go easy on me.
Craig
|
|
|
|
|
I think what you are after is CreateFile("\\\\.\\PHYSICALDRIVE0", ...) and ReadFile() .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thanks for your prompt reply. What you wrote looks interesting i'll check it out. Thanks again.
Craig
|
|
|
|
|
Take care with that kind of I/O. You could easily fubar a filesystem that way...
--
-= Proudly Made on Earth =-
|
|
|
|
|
In addition to the response from DavidCrow, you must read a number of full sectors in the ReadFile function. Else, ReadFile will fail on you.
A HD sector is normally 512 bytes. The actual sector size can be retrieved with a GetDriveGeometry call.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
How to exchange boolean data of Edit Control of a dialog using DDX_....?
|
|
|
|
|
Just like you would any other type:
void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, int& value );
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thanks David
But if I try to exchange data between an IDC control and a structure member that is defined as boolean - The compiler poses an error.
What I'm doing right now is to store the value of this struct member (boolean)in an int, exchange the data with int and store this int back in struct member (boolean)- Any better way to do this - ?
|
|
|
|
|
Sonia Horra wrote: Any better way to do this - ?
Not without seeing the actual code.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
You can always write your own custom DDX_ routine. They are not sacrosanct, after all.
Just use the one that does ints as a template and copy the code to your program.
Then modify it to accept the BOOL and do necessary conversions.
Any sufficiently gross incompetence is nearly indistinguishable from malice.
|
|
|
|
|
Is that any way that call CMainFrame's function
from my CDocument class?
Best Regards.
MJM.
|
|
|
|
|
What's wrong with AfxGetMainWnd() ?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Do u mean i use AfxGetMainWnd()
& then use PostMessage to handling that with
CMainFrame class?
|
|
|
|
|
You indicated that you wanted to "call CMainFrame's function from my CDocument class." AfxGetMainWnd() is used to get a pointer to the frame window object. With that, you can call whatever function you need.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
But i can not access function that i declare in CMainFrame object!
for example i wrote CreatePane function in CMainFrame object.
i wanna call this function
from CMyDocument ! i use AfxGetMainWnd but m_pMainWnd can not access
CreatePane or CreatePane did not declare in FrameWnd object!
best Regards.
MJM.
|
|
|
|
|
mostafa_pasha wrote: But i can not access function that i declare in CMainFrame object!
Why not?
mostafa_pasha wrote: but m_pMainWnd can not access
CreatePane or
Probably because you forgot to cast the return value from AfxGetMainWnd() .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thanks a lot , i forget casting!
Best Regards.
MJM.
|
|
|
|
|
i need if is found , or not !
if is found SetWindowText the string from another table and if is not AfxMessageBox ("Not Found in your Database !")
this is my code :
void CNcontabile::OnChangeGestiuneadb()
{
CString strCourseID;
CWaitCursor wait; // Display a wait cursor
CDatabase_Bun *pBun;
pBun = new CDatabase_Bun;
// Set the filter
pBun->m_strFilter = "um = '" + strCourseID +"'";
if(pBun->Open());
return;
if (pBun->IsOpen())
{
while(!pBun->IsEOF())
{
m_gestiuneaDb.GetWindowText(strCourseID);
strCourseID.TrimLeft();
strCourseID.TrimRight();
m_gestiuneaDb.SetWindowText(strCourseID);
if(strCourseID == pBun->m_um )
{
m_dengestiuneDb.SetWindowText("GGGGGGG");
}
}
}
pBun->Close();
delete pBun;
}
is not working because i have a filter and is no match !
my second problem is how to trim the spaces ? (CEdit & the CDatabase spaces ) ????????????
Bravoone
|
|
|
|
|
Why it doesnt work and what filter?
|
|
|
|
|
Bravoone_2006 wrote: pBun->m_strFilter = "um = '" + strCourseID +"'";
Since strCourseID is empty, this'll never work.
Bravoone_2006 wrote: m_gestiuneaDb.GetWindowText(strCourseID);
strCourseID.TrimLeft();
strCourseID.TrimRight();
m_gestiuneaDb.SetWindowText(strCourseID);
Why are you calling these in a loop? Call them once outside of the loop.
Bravoone_2006 wrote: if(strCourseID == pBun->m_um )
I don't suppose you've bothered to set a breakpoint on this statement to see the different values of strCourseID (which we already know is empty) and pBun->m_um . That's the main reason why you can't see the problem.
Bravoone_2006 wrote: is not working because i have a filter and is no match !
Actually it is working. It's doing exactly what you told it to do - find records where pBun->m_um is equal to empty. Hint: no records match this criteria.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
And then how can i match records with strCourseID? and i need to do this fast because i have many records !
the records in my database have spaces !
Bravoone
|
|
|
|
|
Bravoone_2006 wrote: And then how can i match records with strCourseID?
By assigning it a value.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|