如何使用诺基亚 API 获取手机驱动器的大小(免费、总计)?

发布于 2024-07-11 21:09:19 字数 1215 浏览 10 评论 0原文

我想获取手机驱动器的大小。 我正在使用“Nokia-PC-Connectivity”。关于文件系统 API,我在名为 CONA_Folder_Info 的 CONADifinition 函数上找到,但该函数不支持 FreeSize 和 Total Size,但有 CONA_Folder.Info2 及其实例支持这些变量。

但是当我按如下方式使用 CONA_Folder.Info2 时:

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) 
  {
  }

我收到此异常:

检测到 FatalExecutionEngineError 消息:运行时遇到了 致命错误。 错误的地址 位于 0x7a0ba769,线程 0x1278。 错误代码为0xc0000005。 这 错误可能是 CLR 中的错​​误或 不安全或不可验证的部分 用户代码。 此的常见来源 bug 包括用户编组错误 COM 互操作或 PInvoke,这可能 损坏堆栈。

注意:我使用S60软件平台。 应用语言是C#。

如需更多解释请询问我。

I want to get the size of the phone drive.
I'm using "Nokia-PC-Connectivity"., and with respect to File System API I found on CONADifinition function called CONA_Folder_Info but this function doens't support FreeSize and Total Size but there is CONA_Folder.Info2 and its instance support 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 was detected
Message: The runtime has encountered a
fatal error. The address of the error
was at 0x7a0ba769, on thread 0x1278.
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.

Note: I use the S60 software platform. Application language is C#.

For more explanations please ask me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

野の 2024-07-18 21:09:19

当您尝试将缓冲区中的数据转换为与 CONAFileSystem.CONAFindNextFolder 最初创建的结构类型不同的结构类型时,出现异常是正确的。

您试图将 CONADefinitions.CONAPI_FOLDER_INFO 类型的数据结构强制转换为 CONADefinitions.CONAPI_FOLDER_INFO2 类型的结构。 它们几乎肯定具有不同的长度等等,因此这种方法极不可能起作用。

根据 Symbian 操作系统上的 C++ 开发经验,诺基亚可能在这里使用的模式是他们随后开发了更新版本的 API,因此创建了更新版本的 CONADefinitions.CONAPI_FOLDER_INFO 结构(即 CONADefinitions.CONAPI_FOLDER_INFO2) )。

假设这是正确的,则有 3 种可能性:

1) 第一个函数有一个枚举参数,它指定要创建哪个版本的输出结构。

2)有一个新函数返回新结构,例如 CONAFileSystem.CONAFindFirstFolder2、CONAFileSystem.CONAFindNextFolder2

3) 诺基亚已在内部开发了新版本,但尚未公开发布。

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

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 its extremely unlikely this method would ever work.

From experience with C++ development on the Symbian OS, the pattern Nokia are likely to be using here is one where they have subsequently developed a newer version of the API and so have created a newer version of the CONADefinitions.CONAPI_FOLDER_INFO structure (i.e. CONADefinitions.CONAPI_FOLDER_INFO2).

Assuming this is correct there are 3 likelihoods:

1) There is an enum parameter to the first function which specifies which version of the output structure is to be created.

2) There is a new function which returns the new structure e.g. CONAFileSystem.CONAFindFirstFolder2, CONAFileSystem.CONAFindNextFolder2

3) Nokia have developed the new version internally but not yet released it publicly.

深爱不及久伴 2024-07-18 21:09:19

我对诺基亚 API 一无所知,但总的来说,我看到以下内容:

  1. 查找 API 通常有一个 FindFirst,然后是 FindNext 的迭代,然后是 FindClose。 我看到您使用 hFindHandle 调用 FindNext,但我没有看到它在任何地方初始化(这通常发生在 FindFirst 调用中)。 如果该值为零,则肯定会导致访问冲突。
  2. 如果没有更多的 while() 循环,它看起来就像一个无限循环 - 我假设你在某个地方还有另一个 FindNext ?
  3. 通常 Find 调用要求传入的结构完成一些初始化 - 例如设置长度成员。 检查您的 API 文档,看看此处是否需要这样做。
  4. 我没有看到您释放 Buffer 变量或关闭查找句柄(假设它是有效的)。

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

  1. Find APIs usually have a FindFirst, followed by iterations of FindNext and then a FindClose. I see you calling FindNext with hFindHandle, but I don't see it getting initialized anywhere (which usually happens in a FindFirst call). If this is zero, that could certainly give an access violation.
  2. Without more of your while() loop it looks like an endless loop - I assume you have another FindNext somewhere?
  3. Often Find calls require that the incoming struct have some initialization done - like setting a length member. Check your API docs to see if that's required here.
  4. I don't see you freeing your Buffer variable or closing the find handle (assuming it's valid).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文