"Peter Seaman" <Peter MS Seaman at StableSoftware. com> wrote in message
news:uI******** *****@TK2MSFTNG P11.phx.gbl...
Well, the first thing to do is test whether it is still possible in
*managed* C++ - and then run ildasm on the created assembly and see
what's in it.
No doubt this is good advice but unfortunately I only have C# Standard.
Though this product does contain Visual Studio 2003 and compilers for
JScript .NET and VB .NET, it does not allow me to compile C++ .NET as far
as
I can see.
It seems to me that arrays and structures and combinations of such
aggregates are pretty fundamental to programming, so on the face of this
inability for structures to contain embedded arrays is a severe
restriction.
Is there an easy way round it? How does C# cope with the many such
structures in the WIN32 API e.g. LPWIN32_FIND_DA TA?
Peter Seaman
This is not such a problem in C#, following is a sample using FindNexttFile
and WIN32_FIND_DATA .
using System;
using System.Runtime. InteropServices ;
namespace Willys
{
[StructLayout(La youtKind.Sequen tial, CharSet = CharSet.Unicode )]
public struct _WIN32_FIND_DAT AW
{
public uint dwFileAttribute s;
public FILETIME ftCreationTime;
public FILETIME ftLastAccessTim e;
public FILETIME ftLastWriteTime ;
public uint nFileSizeHigh;
public uint nFileSizeLow;
public uint dwReserved0;
public uint dwReserved1;
// TCHAR array 260 (MAX_PATH) entries, 520 bytes in unicode
[MarshalAs(Unman agedType.ByValT Str, SizeConst=520)]
public string cFileName;
// TCHAR array 14 TCHAR's alternate filename 28 byes in unicode
[MarshalAs(Unman agedType.ByValT Str, SizeConst=28)]
public string cAlternateFileN ame;
}
[StructLayout(La youtKind.Sequen tial)]
public struct FILETIME
{
public uint dwLowDateTime;
public uint dwHighDateTime;
}
class Tester
{
[DllImport("kern el32.dll", EntryPoint="Fin dFirstFileW", SetLastError=tr ue,
CharSet = CharSet.Unicode )]
public static extern IntPtr FindFirstFileW( string lpFileName, ref
_WIN32_FIND_DAT AW lpFindFileData) ;
static void Main()
{
string file = "*.exe";
_WIN32_FIND_DAT AW fndData = new _WIN32_FIND_DAT AW();
IntPtr hFile = FindFirstFileW( file, ref fndData);
if(hFile.ToInt3 2() == -1)
Console.WriteLi ne("FindFirst: " + Marshal.GetLast Win32Error());
else
Console.WriteLi ne("Filename: " + fndData.cFileNa me_260);
}
}
}
Willy.