|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++.windows.32-bits - SetFileTime Help
I have been working on this function to update the time stamp of a file.
I can open the file, but each time SetFileTime is called, it reports an
"Invalid Handle". What are the correct "Declarations to get the
SetFileTime function to work correctly? Please help. Thanks,
char strFile2Touch[255];
int result;
HFILE hfile;
OFSTRUCT info;
SYSTEMTIME st;
FILETIME ft;
st.wYear=atoi(strYr);
st.wMonth=atoi(strMon);
st.wDay=atoi(strDay);
st.wHour=atoi(strHr);
st.wMinute=atoi(strMin);
st.wSecond=atoi(strSec);
SystemTimeToFileTime(&st, &ft);
sprintf(strFile2Touch,"%s%s",strlwr(strDLFolder), strlwrstrFileName));
if(hfile=OpenFile(strFile2Touch, &info, OF_WRITE) != -1){
printf("File Open..Setting Time\n");
result=SetFileTime((HANDLE)hfile, (LPFILETIME)
&ft,LPFILETIME)&ft, LPFILETIME)&ft);
if (result)
reportError("Time Stamp Error");
else
printf("Time Stamp Error\n");
}
CloseHandle((HANDLE) hfile);
--
Regards,
Steve Topilnycky
Top Cat Computing
Web: http://www.topcatcomputing.com/
--
Regards,
Steve Topilnycky
Top Cat Computing
Web: http://www.topcatcomputing.com/
Jul 10 2003
Your problem is that OpenFile is a Win16 function, and not compatible with Win32. It returns an HFILE, whereas the Win32 API uses HANDLE. (It may be the case that they're both void* under the covers, but the difference in name indicates the different semantic.) Use CreateFile(), as in HANDLE hfile = CreateFile(strFile2Touch, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); btw, if you're interested, there's a nifty shell-extension at http://shellext.com will do touching of single or multiple files from with the Explorer shell. "Steve Topilnycky" <no.spam.steve topcatcomputing.com> wrote in message news:MPG.1977847a5d1418fd989686 news.digitalmars.com... Jul 10 2003
In the c++.windows.32-bits newsgroup Matthew Wilson wrote:HANDLE hfile = CreateFile(strFile2Touch, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); Jul 10 2003
In the c++.windows.32-bits newsgroup Steve Topilnycky wrote:Will using CreateFile destroy the original file.. Jul 10 2003
You're most welcome. Just remember that CreateFile returns INVALID_HANDLE_VALUE when it fails, and *not* NULL. :) P.S. If you install the shell extensions, please feel free to give me any feedback, and to register for the mailing list, if you wish. "Steve Topilnycky" <no.spam.steve topcatcomputing.com> wrote in message news:MPG.1977e5de2d9dd7a7989688 news.digitalmars.com...In the c++.windows.32-bits newsgroup Steve Topilnycky wrote:Will using CreateFile destroy the original file.. Jul 10 2003
In the c++.windows.32-bits newsgroup Matthew Wilson wrote:Just remember that CreateFile returns INVALID_HANDLE_VALUE when it fails, and *not* NULL. Jul 10 2003
|