首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >How to PInvoke SFileFindFirstFile

How to PInvoke SFileFindFirstFile
EN

Stack Overflow用户
提问于 2010-11-19 07:11:22
回答 1查看 200关注 0票数 0

声明是

代码语言:javascript
复制
typedef struct _SFILE_FIND_DATA
{
    char   cFileName[MAX_PATH];         // Full name of the found file
    char * szPlainName;                 // Plain name of the found file
    DWORD  dwHashIndex;                 // Hash table index for the file
    DWORD  dwBlockIndex;                // Block table index for the file
    DWORD  dwFileSize;                  // File size in bytes
    DWORD  dwFileFlags;                 // MPQ file flags
    DWORD  dwCompSize;                  // Compressed file size
    DWORD  dwFileTimeLo;                // Low 32-bits of the file time (0 if not present)
    DWORD  dwFileTimeHi;                // High 32-bits of the file time (0 if not present)
    DWORD  lcLocale;                    // Locale version

} SFILE_FIND_DATA, *PSFILE_FIND_DATA;

HANDLE WINAPI SFileFindFirstFile(HANDLE hMpq, const char * szMask, SFILE_FIND_DATA * lpFindFileData, const char * szListFile)</pre>

我试过了

代码语言:javascript
复制
public unsafe struct SFILE_FIND_DATA
{
    fixed byte cFileName[260];         // Full name of the found file
    byte[] szPlainName;                 // Plain name of the found file
    uint dwHashIndex;                 // Hash table index for the file
    uint dwBlockIndex;                // Block table index for the file
    uint dwFileSize;                  // File size in bytes
    uint dwFileFlags;                 // MPQ file flags
    uint dwCompSize;                  // Compressed file size
    uint dwFileTimeLo;                // Low 32-bits of the file time (0 if not present)
    uint dwFileTimeHi;                // High 32-bits of the file time (0 if not present)
    uint lcLocale;                    // Locale version

}

[DllImport("StormLib.dll")]
public static extern uint SFileFindFirstFile(IntPtr hMpq, [MarshalAs(UnmanagedType.LPStr)] string mask,
    out SFILE_FIND_DATA filedata, [MarshalAs(UnmanagedType.LPStr)] string listfile);

是这样的吗?它不会出错,但不会返回它应该返回的内容。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-11-19 07:28:12

szPlainName不应该是byte[] -运行时如何知道数组有多大?试试这个:

代码语言:javascript
复制
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public unsafe struct SFILE_FIND_DATA
{
    fixed byte cFileName[260];         // Full name of the found file
    string szPlainName;                 // Plain name of the found file
    uint dwHashIndex;                 // Hash table index for the file
    uint dwBlockIndex;                // Block table index for the file
    uint dwFileSize;                  // File size in bytes
    uint dwFileFlags;                 // MPQ file flags
    uint dwCompSize;                  // Compressed file size
    uint dwFileTimeLo;                // Low 32-bits of the file time (0 if not present)
    uint dwFileTimeHi;                // High 32-bits of the file time (0 if not present)
    uint lcLocale;                    // Locale version
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4220610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档