在紧凑架构更改文件的创建时间紧凑、架构、文件、时间

由网友(风晚)分享简介:我需要设置文件的创建时间后,我下载使用套接字。在CF FileInfo.CreationTime是只读的。我试图用从this话题,但它不会工作。我得到错误6(句柄无效)I need to set file creation time after I download it using sockets. In CF F...

我需要设置文件的创建时间后,我下载使用套接字。在CF FileInfo.CreationTime是只读的。我试图用从this话题,但它不会工作。我得到错误6(句柄无效)

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).

据为SetFileTime MSDN第一个参数()必须是一个把手,而题目中提到的是字符串,有人说,它适用于他。我究竟做错了什么?如果我需要使用手柄,我怎么能得到这个手柄,CF,我应该怎么改SetFileTime()的声明?

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?

推荐答案

有趣。你点到答案显然是错误的,尽管它被接受。

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

在任何情况下,你需要传递一个句柄(IntPtr的或者无论你想重新present它),其是通过调用CreateFile时返回 - 它的你还需要的P / Invoke 。

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); 

请务必打电话 CloseHandle的时,即可大功告成。

Be sure to call CloseHandle when you're done.

阅读全文

相关推荐

最新文章