在紧凑架构更改文件的创建时间 [英] Change file creation time on compact framework

查看:130
本文介绍了在紧凑架构更改文件的创建时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要设置文件的创建时间后,我下载使用套接字。在CF FileInfo.CreationTime是只读的。我试图用从<一名P / Invoke的解决方案href="http://stackoverflow.com/questions/5673921/change-file-lastwritedate-in-compact-framework">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.

这篇关于在紧凑架构更改文件的创建时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆