Change file creation time on compact framework

人盡茶涼 提交于 2020-01-04 14:15:34

问题


I need to set file creation time after I download it using sockets. In CF FileInfo.CreationTime is readonly. I tried to use P/Invoke solution from this topic, but it won't work: I get error 6 (Invalid handle).

According to MSDN first parameter for SetFileTime() must be a handle, while in the topic mentioned it is string, and somebody says that it works for him. What am I doing wrong? If I need to use handle, how can I get this handle in CF and how should I change SetFileTime() declaration?


回答1:


Interesting. The answer you point to is obviously wrong, though it was accepted.

At any rate, you need to pass in a HANDLE (IntPtr or however you'd like to represent it) that is returned from a call to CreateFile - which you'll also need to P/Invoke.

[DllImport("coredll.dll")] 
private static extern bool SetFileTime(IntPtr fileHandle, 
                                  ref long creationTime, 
                                  ref long lastAccessTime, 
                                  ref long lastWriteTime); 

Be sure to call CloseHandle when you're done.



来源:https://stackoverflow.com/questions/13036165/change-file-creation-time-on-compact-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!