|
Actually a critical section is a better sync object for your purposes, and easier to use. Each thread calls EnterCriticalSection() before accessing the list, then LeaveCriticalSection() once it's done with the list.
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Just out of interest, why is critical section better in this case? Wouldn't mutex serve the same purpose?
Regards,
wilche
|
|
|
|
|
A critical section is more lightweight than a mutex. A mutex differs from a critical section in it can be accessed across process boundaries and you can specify a timeout when waiting on it. Neither of these are needed in his situation so might as well use a critical section.
|
|
|
|
|
The technical reason is that a critical section doesn't require a switch to kernel mode unless a second thread is trying to lock it when another already has the lock. A mutex will always cause a kernel mode switch.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Hi,
What is the best method for deleting all files and
folders from a floppy (programatically)
Sameer
|
|
|
|
|
You can use SHFileOperation.
Use FO_DELETE and make pFrom "A:\*.*"
That should delete the files in the root directory as well as recursively delete all directories and sub-directories.
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Buy it, read it and admire me
|
|
|
|
|
That depends on your view of "best", but I think the following might work:
system("del /q/s a:\\*");
Maybe you need to expand the environment variable ComSpec (case is unimportant) and prepend it to the command.
|
|
|
|
|
Hello All,
Can you ppl out there pls explain what shared
memory is and what is it used for? If some code snippets
or location to the resource is sent would be highly
appreciable.
With Regards
Pradeep
|
|
|
|
|
Hello,
Do any one know that how can I convert directX .x file format to 3ds file format? Or where can I find the tools to do it. Microsoft only provide .3ds format to .x, but I need some tools which can work in the opposite way! Thanks!
Nachi
|
|
|
|
|
Hi.
I have question questions that are related: focus and always-on-top.
Focus: I have a modal dialog box with an edit box. When the program first initialized the dialog box, I would like the the edit box to be in focus. Okay, there is no problem. The solution is to set the edit box to focus on InitDialog(). I am having a problem setting the edit box focus if the program is no longer in focus and then regains focus. I overloaded OnSetFocus in the dialog box and called SetFocus() for the edit box, but that does not work. For some reason, OnSetFocus() never gets called even if the program loses focus and then focuses again. What do I have to overload to catch the program regaining focus so I can focus the edit box?
My second question is about always-on-top. I would like to add a feature to have the program always be on top. Is there a flag I need to add in main frame?
Thanks,
Kuphryn
|
|
|
|
|
Part two -> SetWindowPos has a first parameter that allows you to make a window topmost.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
|
|
|
|
|
|
Okay. I added the following to the dialog box's InitDialog().
-----
SetWindowPos(&wndTopMost, 0, 0, 0, 0, 0);
-----
However, the program crashes/stalls before it draws the dialog box. I tried using a check box that will enable/disable the function above. The program reacted the same way. I believe the problem has something to do with the fact that SetWindowPos() can only be called in main.
Kuphryn
|
|
|
|
|
Wait. Okay. Everything works. I lost my thought for a few minutes and was thinking about the dialog box instead of the window. I really wanted the window to be on top, which is exactly what Christian showed me.
Thanks,
Kuphryn
|
|
|
|
|
Hello,
Did you discover anything about setfocus event ??
Thanks,
Cris.
|
|
|
|
|
the following code will not compile but can i load the entire contents of a file into a CString? or is there a better way?
int filelen = 0;
CString Cbuf;
......
if(rfile.Open(openfile,CFile::modeRead | CFile::shareDenyWrite,NULL)){
filelen = rfile.GetLength();
if(filelen>0){
rfile.Read(Cbuf,filelen);
........
thank you.
|
|
|
|
|
jafrazee wrote:
but can i load the entire contents of a file into a CString? or is there a better way?
If it's a file of reasonable length, then the answer is you can. But it's not recommended for binary files.
But say you have some kinda textual config file which you want to parse. Nothing wrong in reading it into a CString even if it goes to 10-20 KB
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Buy it, read it and admire me
|
|
|
|
|
if you use the std library, it's very easy to read the entire contents of a file into a string. I show how in my STL series of articles. If CFile won't do the same then it is more pathetic than I thought. Either way, it's generally better to use the std library.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
|
|
|
|
|
Bah, there is nothing (for the most part) wrong with CFile. It is just a wrapper for file IO, nothing more. No point in adding 80k of code to you program just to read a simple file. If that is all he needs to do, then CFile will work just fine.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
I guess it depends on your POV. I use STL and iostreams a lot, and a lot within the one project. I could not live without the facilities it offers me, which CFile/CArray does not. The average programmer seems blissfully unaware that such facilities exist, and so will suffer CFile when on a large scale project, where the 80k or so that gets added would be of real benefit to them.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
|
|
|
|
|
LPTSTR psz = Cbuf .GetBuffer (filelen);
rfile .Read (psz, filelen);
Cbuf .ReleaseBuffer ();
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
thank you.
after reading on stl i really did not want to add that much overhead to my program when i am only reading a file that would be about 5k max.
|
|
|
|
|
How do I get the IP address of the machine running my application within VC++?
Ed
|
|
|
|
|
I got most of my Winsock programming hints from this program though it was designed for Win2K only and uses Winsock 2.0. You do not need Win2K or Winsock 2.0 to do get the IP address and the code below will work. However, here is the link and some of the code from the sample:
http://www.sometips.com/tips/systemmanagement/213.htm
// Here read all IPs of this host
DWORD dwSize = 0 ;
GetIpAddrTable( NULL , &dwSize, FALSE ) ;
PMIB_IPADDRTABLE pIpAddrTable = (PMIB_IPADDRTABLE )new BYTE [ dwSize ] ;
if( pIpAddrTable )
{
if( GetIpAddrTable( (PMIB_IPADDRTABLE)pIpAddrTable, // // buffer for IP table
&dwSize, // size of buffer
FALSE // sort by IP address
) == NO_ERROR )
{
if( pIpAddrTable->dwNumEntries > 2 ) // Second is MS TCP loopback IP ( 127.0.0.1 )
{
m_Multihomed = TRUE ;
char szIP[16];
for( int i = 0 ; i < (int)pIpAddrTable->dwNumEntries ; i++ )
{
in_addr ina ;
ina.S_un.S_addr = pIpAddrTable->table[i].dwAddr ;
char *pIP = inet_ntoa( ina ) ;
strcpy( szIP , pIP ) ;
if( stricmp( szIP , "127.0.0.1" ) )
m_IPArr.Add(pIpAddrTable->table[i].dwAddr) ;
}
}
}
delete [] pIpAddrTable ;
}
|
|
|
|
|
Sorry, here it is with the checkbox on and formatted beter. I got most of my Winsock programming hints from this program though it was designed for Win2K only and uses Winsock 2.0. You do not need Win2K or Winsock 2.0 to do get the IP address and the code below will work. However, here is the link and some of the code from the sample:
http://www.sometips.com/tips/systemmanagement/213.htm
// Here read all IPs of this host
DWORD dwSize = 0 ;
GetIpAddrTable( NULL , &dwSize, FALSE ) ;
PMIB_IPADDRTABLE pIpAddrTable = (PMIB_IPADDRTABLE )new BYTE [ dwSize ] ;
if( pIpAddrTable )
{
if( GetIpAddrTable( (PMIB_IPADDRTABLE)pIpAddrTable, // // buffer for IP table
&dwSize, // size of buffer
FALSE // sort by IP address
) == NO_ERROR )
{
if( pIpAddrTable->dwNumEntries > 2 ) // Second is MS TCP loopback IP ( 127.0.0.1 )
{
m_Multihomed = TRUE ;
char szIP[16];
for( int i = 0 ; i < (int)pIpAddrTable->dwNumEntries ; i++ )
{
in_addr ina ;
ina.S_un.S_addr = pIpAddrTable->table[i].dwAddr ;
char *pIP = inet_ntoa( ina ) ;
strcpy( szIP , pIP ) ;
if( stricmp( szIP , "127.0.0.1" ) )
m_IPArr.Add(pIpAddrTable->table[i].dwAddr) ;
}
}
}
delete [] pIpAddrTable ;
}
|
|
|
|