从 WindowsPhone 8.1 调用 GetDiskFreeSpaceExW api
Calling GetDiskFreeSpaceExW api from WindowsPhone 8.1
我正在尝试在我的 Windows Phone 8.1 应用程序中调用 GetDiskFreeSpaceExW Win Api 调用,但我总是无法通过认证。
此函数在支持的 Win32 API 列表中:
https://msdn.microsoft.com/en-us/library/windows/apps/jj662956(v=vs.105).aspx#BKMK_ListofsupportedWin32APIs
我的电话:
[DllImport("api-ms-win-core-file-l1-2-0.dll", SetLastError = true)]
static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
out ulong lpFreeBytesAvailable,
out ulong lpTotalNumberOfBytes,
out ulong lpTotalNumberOfFreeBytes);
错误:
This API is not supported for this application type -
Api=GetDiskFreeSpaceEx. Module=api-ms-win-core-file-l1-2-0.dll.
File=Glide.WindowsCommon.dll.
我在这里错过了什么?
这非常令人困惑,只需将函数名称从 GetDiskFreeSpaceEx 更改为 GetDiskFreeSpaceExW 即可(通过认证)+ CharSet = CharSet.Unicode 如@David Heffernan 的回答:)
[DllImport("api-ms-win-core-file-l1-2-0.dll", SetLastError = true)]
static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
out ulong lpFreeBytesAvailable,
out ulong lpTotalNumberOfBytes,
out ulong lpTotalNumberOfFreeBytes);
因为您没有指定 CharSet
值,所以默认情况下这是用 CharSet
编组的 CharSet.Ansi
。您应该像这样指定 CharSet.Unicode
:
[DllImport("api-ms-win-core-file-l1-2-0.dll", CharSet = CharSet.Unicode,
SetLastError = true)]
static extern bool GetDiskFreeSpaceEx(...);
看来认证过程还需要显式声明入口点名称:
[DllImport("api-ms-win-core-file-l1-2-0.dll", CharSet = CharSet.Unicode,
Entry point = "GetDiskFreeSpaceExW", SetLastError = true)]
static extern bool GetDiskFreeSpaceEx(...);
我正在尝试在我的 Windows Phone 8.1 应用程序中调用 GetDiskFreeSpaceExW Win Api 调用,但我总是无法通过认证。
此函数在支持的 Win32 API 列表中: https://msdn.microsoft.com/en-us/library/windows/apps/jj662956(v=vs.105).aspx#BKMK_ListofsupportedWin32APIs
我的电话:
[DllImport("api-ms-win-core-file-l1-2-0.dll", SetLastError = true)]
static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
out ulong lpFreeBytesAvailable,
out ulong lpTotalNumberOfBytes,
out ulong lpTotalNumberOfFreeBytes);
错误:
This API is not supported for this application type - Api=GetDiskFreeSpaceEx. Module=api-ms-win-core-file-l1-2-0.dll. File=Glide.WindowsCommon.dll.
我在这里错过了什么?
这非常令人困惑,只需将函数名称从 GetDiskFreeSpaceEx 更改为 GetDiskFreeSpaceExW 即可(通过认证)+ CharSet = CharSet.Unicode 如@David Heffernan 的回答:)
[DllImport("api-ms-win-core-file-l1-2-0.dll", SetLastError = true)]
static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
out ulong lpFreeBytesAvailable,
out ulong lpTotalNumberOfBytes,
out ulong lpTotalNumberOfFreeBytes);
因为您没有指定 CharSet
值,所以默认情况下这是用 CharSet
编组的 CharSet.Ansi
。您应该像这样指定 CharSet.Unicode
:
[DllImport("api-ms-win-core-file-l1-2-0.dll", CharSet = CharSet.Unicode,
SetLastError = true)]
static extern bool GetDiskFreeSpaceEx(...);
看来认证过程还需要显式声明入口点名称:
[DllImport("api-ms-win-core-file-l1-2-0.dll", CharSet = CharSet.Unicode,
Entry point = "GetDiskFreeSpaceExW", SetLastError = true)]
static extern bool GetDiskFreeSpaceEx(...);