简体   繁体   中英

Calling GetDiskFreeSpaceExW api from WindowsPhone 8.1

I am trying to call GetDiskFreeSpaceExW Win Api call in my Windows Phone 8.1 application, and I am always failing the certification.

This function is in the List of supported Win32 APIs : https://msdn.microsoft.com/en-us/library/windows/apps/jj662956(v=vs.105).aspx#BKMK_ListofsupportedWin32APIs

My call:

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

Erorr:

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.

What am I missing here?

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

Because you did not specify a CharSet value, this is marshalled with CharSet of CharSet.Ansi by default. You should specify CharSet.Unicode like so:

[DllImport("api-ms-win-core-file-l1-2-0.dll", CharSet = CharSet.Unicode, 
    SetLastError = true)]
static extern bool GetDiskFreeSpaceEx(...);

It seems that the certification process also requires explicit statement of the entry point name:

[DllImport("api-ms-win-core-file-l1-2-0.dll", CharSet = CharSet.Unicode, 
    Entry point = "GetDiskFreeSpaceExW", SetLastError = true)]
static extern bool GetDiskFreeSpaceEx(...);

这非常令人困惑,只需将函数名称从GetDiskFreeSpaceEx更改为GetDiskFreeSpaceExW工作(通过认证)+ CharSet = CharSet.Unicode,如@David Heffernan回答:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM