Problem: getting mobile disk size using C # throws exception - Commented

when i run this code:

CONADefinitions.CONAPI_FOLDER_INFO2 FolderInfo;
int iResult = 0;
IntPtr Buffer =  Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CONADefinitions.CONAPI_FOLDER_INFO2)));                
iResult = CONAFileSystem.CONAFindNextFolder(hFindHandle, Buffer);
while (iResult == PCCSErrors.CONA_OK )
{
 FolderInfo = (CONADefinitions.CONAPI_FOLDER_INFO2)Marshal.PtrToStructure(Buffer,typeof(CONADefinitions.CONAPI_FOLDER_INFO2));                                                             
    //......................... i got an error msg here as follows:
    // Error Messege: 
       FatalExecutionEngineError was detected Message: The runtime has encountered a 
       fatal error. The address of the error was at 0x7a0ba769, on thread 0x1294. The
       error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe 
       or non-verifiable portions of user code. Common sources of this bug include 
       user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.

      

how to use CONADefinitions.CONAPI_FOLDER_INFO2 when i use CONADefinitions.CONAPI_FOLDER_INFO it only gives me the device name and layout but when CONADefinitions.CONAPI_FOLDER_INFO2 is used it gives me freeSize and TotalSize

please, help

0


source to share


2 answers


I'm not sure what this means, but if you want to get the size of the disk you can use



        DriveInfo di = new DriveInfo("f");  //Put your mobile drive name
        long totalBytes = di.TotalSize;
        long freeBytes = di.TotalFreeSpace;

      

+2


source


It is correct that you get an exception when you try to convert the data in the buffer to a structure of a different type than the CONAFileSystem.CONAFindNextFolder originally created.

You are trying to force a data structure of type CONADefinitions.CONAPI_FOLDER_INFO into a structure of type CONADefinitions.CONAPI_FOLDER_INFO2. They are almost certainly of different lengths and so on, so this method is highly unlikely to work.



From C ++ development experience on Symbian OS, Nokia's model is likely to be used here, where they subsequently developed a new version of the API and therefore created a newer version of the CONADefinitions.CONAPI_FOLDER_INFO structure (i.e. CONADefinitions.CONAPI_FOLDER_INFO2).

Assuming this is correct, there are three probabilities:
1) The enum parameter to the first function determines which version of the output structure should be generated.
2) There is a new function that returns a new structure eg. CONAFileSystem.CONAFindFirstFolder2, CONAFileSystem.CONAFindNextFolder2
3) Nokia has developed a new version, but has not yet published it publicly.

0


source







All Articles