locked
Windows CE 5.0 GetDiskFreeSpaceEx failing, returning GetLastError 1222 RRS feed

  • Question

  • I'm developing in C++ on a base Windows CE 5.0 device and am having difficulty in obtaining the free space and total size of a volume on the device. The GetDiskFreeSpaceEx works successfully on a WinMobile platform, but does not appear to be successful on this base CE 5.0 platform and returns a last error of 1222: The network is not present or not started.

    The call succeeds on the device if the first argument is the root directory "\\" but any other directory returns 1222.  It appears as though the explorer shell is able to obtain the used/free space if viewing, for example, the SD card's properties.  What is a possible cause of this failure and error?

    Also, is there a different API I could use to obtain a volume's used and free space?  Thanks.
    Wednesday, December 9, 2009 11:39 PM

Answers

  • Hi,


    By using Joel’s code in this page

    http://social.msdn.microsoft.com/forums/en-US/vssmartdevicesvbcs/thread/3de7a45d-5d6c-4a2f-a04c-84de07750ae3/

    I am able to get the results in WinCE emulator

    using System;

    using System.IO;

    using System.Runtime.InteropServices;

    namespace StorageCardInfo

    {

        class Program

        {

            const ulong Megabyte = 1048576;

            const ulong Gigabyte = 1073741824;

            [DllImport ("CoreDLL" )]

            static extern int GetDiskFreeSpaceEx(

               string DirectoryName,

               out ulong lpFreeBytesAvailableToCaller,

               out ulong lpTotalNumberOfBytes,

               out ulong lpTotalNumberOfFreeBytes

            );

            static void Main(string [] args)

            {

                DirectoryInfo root = new DirectoryInfo (@"\" );

                DirectoryInfo [] directoryList = root.GetDirectories();

                 ulong FreeBytesAvailable;

                ulong TotalCapacity;

                ulong TotalFreeBytes;

                for (int i = 0; i < directoryList.Length; ++i)

                {

                        GetDiskFreeSpaceEx(directoryList[i].FullName, out FreeBytesAvailable, out TotalCapacity, out TotalFreeBytes);

                        Console .Out.WriteLine("Storage card name: {0}" , directoryList[i].FullName);

                        Console .Out.WriteLine("Available Bytes : {0}" , FreeBytesAvailable);

                         Console .Out.WriteLine("Total Capacity : {0}" , TotalCapacity);

                        Console .Out.WriteLine("Total Free Bytes : {0}" , TotalFreeBytes);

               }

            

            }

        }

    }

     

    Hope this helps,

    Zhe Zhao

    • Marked as answer by ZHE ZHAO Wednesday, December 16, 2009 2:50 AM
    Monday, December 14, 2009 6:51 AM

All replies

  • Hi,


    By using Joel’s code in this page

    http://social.msdn.microsoft.com/forums/en-US/vssmartdevicesvbcs/thread/3de7a45d-5d6c-4a2f-a04c-84de07750ae3/

    I am able to get the results in WinCE emulator

    using System;

    using System.IO;

    using System.Runtime.InteropServices;

    namespace StorageCardInfo

    {

        class Program

        {

            const ulong Megabyte = 1048576;

            const ulong Gigabyte = 1073741824;

            [DllImport ("CoreDLL" )]

            static extern int GetDiskFreeSpaceEx(

               string DirectoryName,

               out ulong lpFreeBytesAvailableToCaller,

               out ulong lpTotalNumberOfBytes,

               out ulong lpTotalNumberOfFreeBytes

            );

            static void Main(string [] args)

            {

                DirectoryInfo root = new DirectoryInfo (@"\" );

                DirectoryInfo [] directoryList = root.GetDirectories();

                 ulong FreeBytesAvailable;

                ulong TotalCapacity;

                ulong TotalFreeBytes;

                for (int i = 0; i < directoryList.Length; ++i)

                {

                        GetDiskFreeSpaceEx(directoryList[i].FullName, out FreeBytesAvailable, out TotalCapacity, out TotalFreeBytes);

                        Console .Out.WriteLine("Storage card name: {0}" , directoryList[i].FullName);

                        Console .Out.WriteLine("Available Bytes : {0}" , FreeBytesAvailable);

                         Console .Out.WriteLine("Total Capacity : {0}" , TotalCapacity);

                        Console .Out.WriteLine("Total Free Bytes : {0}" , TotalFreeBytes);

               }

            

            }

        }

    }

     

    Hope this helps,

    Zhe Zhao

    • Marked as answer by ZHE ZHAO Wednesday, December 16, 2009 2:50 AM
    Monday, December 14, 2009 6:51 AM
  • Thanks for the reply Zhe.  I neglected to check this thread after a couple days but figured out my problem anyway.  Maybe I should have mentioned this but my source was actually contained in a device-side DLL that I was invoking via RapiInvoke through ActiveSync.  The path was being passed from the host down to the client in an escaped string, hence the double slashes in the path.  However, to my dismay, the path was being treated as an unescaped string resulting in the path being interpreted as a network location. That was the reason for the 1222 error: network not started or unavailable.  I felt a little dirty passing an unescaped path from the host but it worked.  Thanks for your time.
    Friday, January 8, 2010 11:12 PM