2010-11-18 9 views
0

La déclaration estComment Pinvoke SFileFindFirstFile

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> 

J'ai essayé

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); 

Est-ce exact? Il ne fait pas erreur mais il ne retourne pas ce qu'il devrait.

+1

Que retourne-t-il et qu'est-ce que vous attendez qu'il revienne? –

+0

Est-ce que cela fonctionne si vous changez 'byte [] szPlainName' en' IntPtr szPlainName'? – dtb

Répondre

1

szPlainName ne devrait pas être byte[] - comment le runtime sait-il la taille du tableau? Essayez ceci:

[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 
} 
+0

L'avez-vous essayé ou pensez-vous simplement? – dtb

+0

Comment puis-je l'essayer si je n'ai pas le code à la fonction? Quoi, est-ce faux? – wj32

Questions connexes