问题描述
如何获得规模使用C#的是Windows Mobile手机上的任何驱动器(免费,总计)?
How do I get the size (free, total) of any drive on a Windows Mobile phone using C#?
我需要在运行的代码要做到这一点装置(未连接的PC上)。
I need to do this with code running on the device (not on a connected PC).
推荐答案
我已经重写的基础上更好地理解这个问题的答案,但而不会丢失任何我原来的答复对于那些谁找到这个问题。
I've rewritten the answer based on a better understanding of the question, but without losing any of my original answer for those who find this question.
充分利用代码在设备上运行的大小
答案很简单:P / Invoke的直接()或使用的说的的。
The answer is simple: P/Invoke GetDiskFreeSpaceEx directly (example here) or use a third-party library that does it for you.
我也要去编辑帖子以使它看起来像我的假设是正确的 - 改变它们,否则读,如果你需要
I'm also going to edit the post to make it seem like my assumptions are correct - change them to read otherwise if you need to.
您有一个的P / Invoke的定义。这是一个简单的静态方法调用。你把它放在一个类。事情是这样的:
You have a P/Invoke definition. This is simply a static method call. You put it in a class. Something like this:
public class MyClass
{
[DllImport("coredll.dll", SetLastError=true, CharSet=CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
out ulong lpFreeBytesAvailable,
out ulong lpTotalNumberOfBytes,
out ulong lpTotalNumberOfFreeBytes);
}
然后调用它(不知道你想与所有做什么您编组的东西):
Then you call it (no idea what you're trying to do with all of your marshaling stuff):
ulong GetDiskSize(string volumeName)
{
ulong avail;
ulong total;
ulong totalfree;
MyClass.GetDiskFreeSpaceEx(volumeName, out avail, out total, out totalFree);
return total;
// return others as desired
}
然后用它它的东西像这样的:
Then to use it it's something like this:
ulong diskSize = GetDiskSize("\\Storage Card");
充分利用代码运行在PC上的大小
当设备在资源管理器中显示出来像一个驱动器,它不是一个驱动器。一个外壳扩展用于获取它出现在资源管理器。您不能使用任何驱动器的API,在框架或通过P / Invoke的,以获得有关设备的信息。
While the device shows up in Explorer like a "drive", it is not a drive. A shell extension is used to get it to appear in Explorer. You cannot use any drive APIs, in the framework or via P/Invoke, to get information about the device.
如果您需要获得有关通过ActiveSync连接的设备的信息(XP和更早版本)或WMDC(Vista的),那么你的有无的使用远程API或RAPI。具体的API是的,但你必须在你面前做一些初始化。可以称之为
If you need to get information about a device connected via ActiveSync (XP and earlier) or WMDC (Vista) then you have to use the Remote API, or RAPI. The specific API is CeGetStoreInformation, but you have to do some initialization before you can call it.
RAPI是有点过于复杂在这里回答覆盖,但它同时在线记录,并有一个的现成的托管包装(自由和开放源码)。具体的调用你是在该库后。
RAPI is a bit too complex to cover in an answer here, but it's well documented online, and there is a ready-made managed wrapper for it (free and open source) here. The specific call you are after in that library is RAPI.GetDeviceStoreInformation.
这篇关于获取使用C#的Windows Mobile电话驱动器大小(免费,全)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!