|
Thanks, you last suggestion helped me better understand how TEMP files work.
When I run test program on my hard drive, "test_file.txt" is not created at all, Explorer simply doesn't show it. I can see file only when I run program on my USB drive. After realizing that, I re-read this sentence from MSDN:
"Specifying the FILE_ATTRIBUTE_TEMPORARY attribute causes file systems to avoid writing data back to mass storage if sufficient cache memory is available, because an application deletes a temporary file after a handle is closed. In that case, the system can entirely avoid writing the data."
So, TEMP file is held in memory as long enough cache memory is available. And after seeing that file is NOT deleted on my USB stick, I can verify that application is the one responsible for deleting file (unless FILE_FLAG_DELETE_ON_CLOSE is set in CreateFile)
Now, at least I fully understand what MSDN documentation says about FILE_ATTRIBUTE_TEMPORARY .
Off course, my problem still remains. GetFileAttributes and FindFirstFile *should* see the same set of file attributes, and should report the same DWORD value.
And BTW, you really have a "hawk eye", I meant to call CreateFile with FILE_ATTRIBUTE_TEMPORARY parameter but I made a mistake when copied source code here (in original that parameter is "*iter").
But it doesn't change much, no matter how I create file, once I set TEMP attribute, FindFirstFile chokes on it(on FAT32).
|
|
|
|
|
To complicate matters, I think removable devices such as USB sticks, work or may work slightly differently from regular disks; you (sometimes?) can set a device attribute that makes it safe
to remove them at all times, which tells me they can only cache on read, not on write; if you don't,
they may operate faster (on writes that is) but you officially need to "safely remove hardware"
telling Windows it should flush the cache to the device.
I don't always find how to control this feature though, it should be on one of the Device Property tabs but sometimes seems missing; I use both XP and Vista, and it may depend on the specific USB stick (some tend to install and use their own driver).
As a last remark: USB sticks really contain a microcontroller and a flash EEPROM, so there is software
involved there too; they get to execute FAT commands, so your TEMP problem could even be stick-specific!
If you ever discover the finer details on the TEMP matter, feel free to write and publish an article
on the subject!
|
|
|
|
|
This post brought smile to my face, I too am an electronics engineer and I program microcontrollers in my spare time (Microchip's PIC family) and my next project (if I ever find time to do it, that is) is to implement procedure to save data (collected from various sensors) on USB stick.
Back to topic...
I think Windows simply flushes data on USB stick because they are removable, and that is the only reason I can see the file with TEMP attribute. So it is probably not specific to my UBS stick.
But I was thinking along the same lines, so I tested on three different USB stick and two computers, and then I created a small FAT32 (and FAT) partition on my hard drive and tested it there too.
I got the same results everywhere, FindFirstFile identifies TEMP file only on NTFS partitions
|
|
|
|
|
loreia wrote: FindFirstFile identifies TEMP file only on NTFS partitions
FindFirstFile is returning the FAT attributes from reading the disk because it was designed to also work with 16-bit programs. FILE_ATTRIBUTE_TEMPORARY is an attribute which does not exist in the FAT specification[^] but does in NTFS. Would you expect to see FILE_ATTRIBUTE_ENCRYPTED on a FAT partition? No because only NTFS supports encryption. GetFileAttributes is different and checks internel objects such as the cache manager. There are *many* attributes in the GetFileAttributes Function[^] which are not present on a FAT based disk.
Best Wishes,
-David Delaune
|
|
|
|
|
David, thank you a lot for your answer.
I know from experience that FAT32 doesn't support encryption, so answer to your question is: no. LOL
So, TEMP attribute is NTFS specific, and it is not supported on FAT32. Thanks for clarifying that, but what I don't understand is why SetFileAttributes returns TRUE when setting TEMP attribute to a file on FAT32.
It SetFileAttributes function returned FALSE I wouldn't be in this mess in the first place.
My understanding is: if FAT32 doesn't support TEMP files, than SetFileAttributes should fail to set TEMP attribute.
I was wrong in presuming that "error" (for the lack of better description) was in FindFirstFile. But in fact FindFirstFile correctly reports that TEMP attribute is not set on FAT32 (as it cannot be set on FAT32).
And the real problem is in SetFileAttributes/GetFileAttributes functions that *claim* that file has a TEMP attribute set even on FAT32 (and this is in direct contradiction to FAT32 File System Specification that you posted a link for).
I you know why are SetFileAttributes/GetFileAttributes acting in this way, your explanation would help me a lot.
Best regards
loreia
|
|
|
|
|
loreia wrote: My understanding is: if FAT32 doesn't support TEMP files, than SetFileAttributes should fail to set TEMP attribute.
You need to seperate FAT from the operating system within your mind. When you call SetFileAttributes and set the file as FILE_ATTRIBUTE_TEMPORARY what happens internally is that the NT kernel calls CcInitializeCacheMap[^] and CcSetAdditionalCacheAttributes[^] which disables write-behind and essentially enables a "lazy write" which means that the file may or may not be written to disk depending on an internal algorithm based on critera such as i/o priority, filesize, media type ect...
The difference is that FAT32 does not have anywhere to store this extra information as it is an older technology. NTFS on the other hand was designed to store additional file attributes for both now and in the future as it can be extended.
FindFirstFile[^] has many other problematic surprises[^]. Some of which stem from supporting 16 bit applications.
GetFileAttributes is not lying to you when it says the file is FILE_ATTRIBUTE_TEMPORARY.
Best Wishes,
-David Delaune
|
|
|
|
|
What a great explanation, Now I fully understand what happened in my program.
Thanks a lot, I owe you one
Best regards,
loreia
|
|
|
|
|
OK, that seems to explain it all. Thanks.
|
|
|
|
|
GetFileAttributes() is used to retrieve a set of FAT-style attributes. See if GetFileAttributesEx() behaves any differently.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hi David, thanks for your suggestion.
GetFileAttributesEx() won't help me. I had problems understanding why ::FindFirstFile and GetFileAttributes() report different set of file attributes on FAT32.
And now I get it, TEMP files are not flushed to HDD, and therefore limitations of FAT can be see with ::FindFirstFile and not with GetFileAttributes().
I made a small test in which I created a file on USB stick (with FAT32 file system), then added a TEMP attribute to it and:
a) read file attributes right after creating file
b) then I safely removed USB drive (forcing windows to flush file to FAT)
c) re-read file attributes, now both ::FindFirstFile and GetFileAttributes() reported correct values
Now I can safely continue developing my enumeration class.
One more time, a BIG thank you to all three of you for your help, suggestions and explanations.
Best regards
loreia
|
|
|
|
|
the same way as with a button? There is a static control in my dialog, and if it is clicked (single click) an action must be performed.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
modified on Saturday, January 10, 2009 1:32 PM
|
|
|
|
|
The CStatic should have the BS_NOTIFY SS_NOTIFY style. If you are using MS Visual Studio then you can set this property in the dialog resource editor by setting the 'Notify' property to TRUE.
Some documentation:
STN_CLICKED Notification[^]
Best Wishes,
-David Delaune
[Edit]
Updated erroneous style.
|
|
|
|
|
Hi,
I tried what they said in MSDN:
The STN_CLICKED notification message is sent when the user clicks a static control that has the SS_NOTIFY style. The parent window of the control receives this notification message through the WM_COMMAND message.
I put SS_NOTIFY and BS_NOTIFY style on the static, but no WM_COMMAND was received when I clicked on it
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
BS_NOTIFY is for buttons, not statics, don't use it on a static, use only SS_NOTIFY. And you won't receive a command message you can handle using ON_COMMAND, you need to use ON_NOTIFY, specifying the ID (make sure this is not the default IDC_STATIC but something else, at least to avoid confusement) of your static and STN_CLICKED, or i think there should be an ON_STN_CLICKED macro somewhere too.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
sashoalm wrote: I put SS_NOTIFY and BS_NOTIFY style on the static
Sorry about that, I meant to say SS_NOTIFY. You also should change the ID of the CStatic to something other than the default. In your message map add:
ON_STN_CLICKED(IDC_STATIC_YOURNAME, &CYourClass::OnStnClickedStatic)
And in your header:
afx_msg void OnStnClickedStatic();
Best Wishes,
-David Delaune
|
|
|
|
|
Could there be something wrong with my static control? It's not working, and I checked that the id is not the default IDC_STATIC.
Here's how the static is defined in the *.rc2 file
LTEXT "Static",IDC_MY_STATIC_ID,81,198,109,8,
SS_CENTERIMAGE, SS_NOTIFY
I turned on the message loop tracing with MFC Tracer, but the only WM_LBUTTONUP and WM_LBUTTONDOWN messages were appearing when I was clicking on the static:
WndProc: hwnd=0x5B0BBA, msg = WM_LBUTTONDOWN (0x0001, 0x015700D0)
WndProc: hwnd=0x5B0BBA, msg = 0x036A (0x0000, 0x00000000)
WndProc: hwnd=0x5B0BBA, msg = 0x036A (0x0000, 0x00000001)
WndProc: hwnd=0x5B0BBA, msg = 0x036A (0x0000, 0x00000002)
WndProc: hwnd=0x5B0BBA, msg = 0x036A (0x0000, 0x00000003)
WndProc: hwnd=0x5B0BBA, msg = WM_LBUTTONUP (0x0000, 0x015700D0)
WndProc: hwnd=0x5B0BBA, msg = 0x036A (0x0000, 0x00000000)
WndProc: hwnd=0x5B0BBA, msg = 0x036A (0x0000, 0x00000001)
WndProc: hwnd=0x5B0BBA, msg = 0x036A (0x0000, 0x00000002)
WndProc: hwnd=0x5B0BBA, msg = 0x036A (0x0000, 0x00000003)
[Added]
I checked again and the hwnd is actually that of the dialog! The static control didn't receive any event in the first place.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
modified on Saturday, January 10, 2009 1:28 PM
|
|
|
|
|
I found where the problem is, I had incorrectly written the flags. The dialog was in a *.rc2 file so it had to be edited manually.
Thanks, your solution works now
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Glad you have located the problem, I was beginning to scratch my beard with absolute dismay.
Best Wishes,
-David Delaune
|
|
|
|
|
Be careful that you have to change the default id of static - IDC_STATIC to something else like IDC_STATIC_MY_LABEL. Or else the static will not notify any messages.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
|
When i applied LAYOUTRTL layout on my window by setting extended window style, everthing went fine. All the contorls, title bar, scroll bar all are now in right to left layout. However the images that were being displayed previously are not being displayed instead of that blank window is being displayed in place of the image data.
I am now totally clueless.
|
|
|
|
|
Hello to all,
First of all let me tell you what I am doing in my project, in my project I am collecting some data from two devices, one device is having USB connector and another device is having serial port (RS232) connector.
Now I will tell you the main problem, In my project I am creating one file and writting the data collected from any one of above device, into that file.The function in which I have written file writting operation code gets called after each 10 seconds. But problem is that when I collect data from device having serial port (RS232) connector then sometimes I get "CFile::sharingViolation" exception in file operation.I am giving my code also here. In below code "CreateRawDataFile()" function gets called after each 10 seconds and this function contains the code regarding file handling operation.
void CMainFrame::CreateRawDataFile()
{
CFile oRawFile;
CFileException ExceptionObj;
if(oRawFileIO.Open(FileName,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite,&ExceptionObj)==FALSE)
{
if(ExceptionObj.m_cause == CFileException::sharingViolation)
{
TRACE("\n Sharing violation");
}
}
else
{
code for writting data in a file
.
.
.
.
oRawFile.Close();
}
}
In above function sometimes I get "CFileException::sharingViolation" exception and then the TRACE statement which I have written gets displayed.Most surprising thing is that this file exception occurs only when I collect the data from the device having serial port (RS232) connector.Also I have checked that call to above function is going exactly after each 10 seconds and not before that.Also data is not much long which will not get written into file within 10 seconds.Most surprisingly it works very much accuratly without any file exception when I collect data from the device having USB connector.
Really I am not getting what exactly happening? Please can any body tell me what to do and how to remove this problem? It is really really very very urgent? Please help me out.
Thanks and Regards,
Anay
|
|
|
|
|
Maybe you have a race condition, where the USB handler has opened the file and then the serial handler tries to open it as well?
If I were you, I hold the file open through the life of the program (make the CFile variable a member of CMainFrame and open it in CMainFrame::Create , close it when the CMainFrame closes). Then there's no worry about the file needing to be shareable, as you won't be trying to open it more than once.
|
|
|
|
|
I build a web browser using Chtmlview.
and now I don't want use "Navigate2" function ,I want to get HTTP request ,which is come from the web browser, and store the this HTTP request,send it to WEB server by myself.
at the other hand , I can acquire the HTTP response by my application , How can I send the response to the web browser built by Chtmlview class.
I mean that how can I send/get the HTTP message between the chtmlview and myself.
Thank you very much!
Lampa
|
|
|
|
|
If you have the HTTP response, extract the body into a string and set it as the CHtmlView 's document by extracting the web browser interface pointer with CHtmlView::GetHtmlDocument and using the sample code on this page[^].
|
|
|
|
|