Hi,
I'm trying to get a RAPI function (CeFindAllFiles) to work in my C# app. I
do get the number
of files found, but I can't get the array of structs that contains the file
names.
I think my problem is with the pointer to the array of structs. The
documentation reads:
"Pointer to the pointer to an array of CE_FIND_DATA structures that receive
information about the found items".
Here's my code:
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)]
public struct CeFindData
{
int dwFileAttributes;
int ftCreationTime;
int ftCreationTime2;
int ftLastAccessTime;
int ftLastAccessTime2;
int ftLastWriteTime;
int ftLastWriteTime2;
int nFileSizeLow;
int nFileSizeHigh;
int iOID;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=260)]
public string cFileName;
}
[DllImport("rapi.dll", CharSet=CharSet.Unicode, SetLastError=true)]
internal extern static bool CeFindAllFiles(string lpPathName, int flags, ref
int lpdwFoundCount, out CeFindData[] typFindFileData);
...
public bool FindAllFiles(string szPath)
{
// Dim Int
int result;
int resultcount=0;
// Dim Boolean
bool bresult;
// Dim CeFindData
CeFindData p_myCeFindData = new CeFindData();
// Create a NEW ceFindData Structure
CeFindData []myCeFindDataS = new CeFindData[5];
// Find the Next File
bresult=CeFindAllFiles(szPath, 128, ref resultcount, out myCeFindDataS);
// Set the Return Value
return bresult;
}
Any help appreciated...
Thanks,
michael
Mattias Sj?gren - 12 Apr 2004 15:32 GMT
Michael,
>[DllImport("rapi.dll", CharSet=CharSet.Unicode, SetLastError=true)]
>internal extern static bool CeFindAllFiles(string lpPathName, int flags, ref
>int lpdwFoundCount, out CeFindData[] typFindFileData);
Try changing the last parameter type to out IntPtr, then do womehting
like the following pseudo code
loop FoundCount times
get CE_FIND_DATA pointer at position i with Marshal.ReadIntPtr
dereference it to a CE_FIND_DATA struct with Marshal.PtrToStructure
finally, free the array pointer with CeRapiFreeBuffer
Unfortuantely I don't know enough about .NET CF to say if all this is
possible, or if you have to use some CF specific workarounds instead.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.