How to get phone disk size (free, full) using Nokia API?

I want to get the phone disk size. I use "Nokia-PC-Connectivity". And regarding the file system API, I found a CONADifinition function called CONA_Folder_Info, but this function does not support FreeSize and Total Size, but there is CONA_Folder.Info2 and its instance supports these variables.

But when I used CONA_Folder.Info2 as follows:

CONADefinitions.CONAPI_FOLDER_INFO2 FolderInfo; int iResult = 0;// Allocate memory for buffer 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)); if (FolderInfo.pstrName[0].ToString() != "C" && level == 0) { } 

I get this exception:

FatalExecutionEngineError detected Message: The runtime encountered a fatal error. The error address was at 0x7a0ba769, on stream 0x1278. Error Code: 0xc0000005. This error may be an error in the CLR or in unsafe or unverifiable portions of the user code. Common sources for this error include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.

Note. I am using the S60 software platform. The application language is C #.

For more explanations, please ask me.

+4
source share
2 answers

It is true that you get an exception when you try to convert the data in the buffer to a structure of a different type than what 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 almost certainly have different lengths and so on, so it is highly unlikely that this method will work.

From the experience of developing C ++ on Symbian OS, the Nokia 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 for the first function determines which version of the output structure should be created.
2) There is a new function that returns a new structure, for example. CONAFileSystem.CONAFindFirstFolder2, CONAFileSystem.CONAFindNextFolder2
3) Nokia has developed a new version, but has not yet published it publicly.

+1
source

I don't know anything about the Nokia API, but overall I see the following:

  • The search API typically has FindFirst, followed by iterations of FindNext and then FindClose. I see that you are calling FindNext with hFindHandle, but I do not see it initializing anywhere (which usually happens when FindFirst is called). If it is zero, it can lead to access violation.
  • Without your while () loop, it looks like an infinite loop - I assume you have another FindNext somewhere?
  • Often, searching for calls requires the incoming structure to do some initialization β€” for example, setting a length member. Check your API docs to see if it is required here.
  • I don’t see you free the Buffer variable or close the find descriptor (considering it valid).
0
source

All Articles