Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / April 2004

Tip: Looking for answers? Try searching our database.

Pointer to the pointer to an array ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael Senf - 09 Apr 2004 19:45 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.