Kernel32.dll 读取卡 SD 之类的文件阅读长篇

问题描述

我像文件一样读取卡 SD。我用这个方法:

    public static int ReadUSBDisk(ref byte[] buffer,int sector,string fileName)
    {
        ushort count = 10;
        bool retValue;
        int address = 512 * sector;
        if (!IsUSBOpen())
            hUSBDisk = OpenUSBDisk(fileName);
        if ((int)hUSBDisk == -1)
            return NISH_ERROR;
        SetFilePointer(hUSBDisk,address,EMoveMethod.Begin);
        retValue = ReadFile(hUSBDisk,buffer,512,ref count,IntPtr.Zero);

        if (retValue)
            return NISH_NO_ERROR;
        else
            return NISH_ERROR;

    }

    [DllImport("kernel32.dll",SetLastError = true)]
    private static extern bool ReadFile(IntPtr handle,byte[] buffer,ushort toRead,ref ushort read,IntPtr lpOverLapped);

    [DllImport("Kernel32.dll",SetLastError = true,CharSet = CharSet.Auto)]
    static extern uint SetFilePointer(
    IntPtr hFile,int lDistanceToMove,int lpDistanceToMoveHigh,EMoveMethod dwMoveMethod);

但是我需要从比 int 更多的空间读取。但是将 lDistanceToMove 更改为 long couses 抛出错误:

对 PInvoke '(className) :: SetFilePointer' 的调用扰乱了 堆栈的平衡。可能的原因是管理对象之间的不匹配 PInvoke 签名和非托管目标签名。检查是否 PInvoke 函数的调用约定和签名参数 匹配非托管目标签名。

老实说,我不知道它到底是如何工作的。也许有人可以告诉我是否可以以某种方式将其更改为从长空间读取。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)