|
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 ;
}
|
|
|
|
|
Howdy all,
So I'm trying to decide which STL container would be more appropriate, a multimap or a list. What I need is a storage class which will be holding a lot of objects (maybe 2000?). Each object will have a unique ID. Every time an object is added it's ID will be one larger than the previously added object. Objects will be accessed and removed pretty much at random.
So basically, objects are always added with an incremented ID, but are accessed and removed randomly, in terms of ID.
Now the fact that the object ID is always increasing make me consider a list ordered on ID, so that I could just shove new objects onto the tail without having to look at the storage.
The fact that the objects are random accessed makes me lean towards a multimap<obj_id, object>.
Oh, and it looks like once the storage is initially filled it will stay /fairly/ constant in size, i.e. addition and removals will be fairly even in number.
The main concern here is speed of access, with speed of insertion/removal second, and memory usage a fairly distant third.
Anyone have any insights, suggestions, comments, etc for me
TIA,
Pete
|
|
|
|
|
Objects will be accessed and removed pretty much at random.
This is a big point here. Straight lists perform very poorly on lookup. The list has to be searched sequentially to find the object.
However, for lists, insertions are very fast. So are removals. But when you compare them to maps, lists insert and removals probably are much faster at all.
IMHO, I see little reason to even bother with a list. Just given that you are doing random lookups, you really need something that is fast.
If available in your STL (i.e. STLPort), you might take a look at a hash map. Since your data set is remaining a constant size, you don't have to worry about the re-hash performance hit. As long as your ID's are well distributed, hash maps should perform very fast.
... IMHO
|
|
|
|
|
>>Since your data set is remaining a constant size, you don't
>>have to worry about the re-hash performance hit.
Is this true, even thought the ID's I'll be hashing on are constantly increasing?
Thinking about it, a list is definately not the way to go. As you rightly say, the lookup times for a random element in a list would /not/ be great, and that's my main priority.
I'm using M$'s STL. I'm not sure about a hash map. Is this similar to a map<obj_id, pObjData>? Forgive my ignorance, I haven't used the STL much.
Thanks,
Pete
|
|
|
|
|