Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to use MarshalAsAttribute in C#.NET compact Framework

Status
Not open for further replies.

VenkatRastapuram

Programmer
Oct 24, 2003
46
IN
Hi ,

I am sending a sample code, which is running without any problem in Windows Application and it is giving compilation error when it is run as Smart Device Application. Because the MarshalAsAttribute is not supported in Smart Device Application.

I found from the MSDN (search key: Interop Marshaling Support) MarshalAsAttribute is not supported in
Smart Device Appication and the alternative method is to use Marshal class. But I did not found any samples on that.
So if any body knows how to use Marshal class please tell me what changes is to be made to the following code to run in Smart Device Application

using System;
using System.Text;
using System.Runtime.InteropServices;

// Declares a class member for structure element.
[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Auto )]

public class FindData
{
public int fileAttributes = 0;
// creationTime was an embedded FILETIME structure.
public int creationTime_lowDateTime = 0 ;
public int creationTime_highDateTime = 0;
// lastAccessTime was an embedded FILETIME structure.
public int lastAccessTime_lowDateTime = 0;
public int lastAccessTime_highDateTime = 0;
// lastWriteTime was an embedded FILETIME structure.
public int lastWriteTime_lowDateTime = 0;
public int lastWriteTime_highDateTime = 0;
public int nFileSizeHigh = 0;
public int nFileSizeLow = 0;
public int dwReserved0 = 0;
public int dwReserved1 = 0;
[ MarshalAs( UnmanagedType.ByValTStr, SizeConst=256 )]
public String fileName = null;
[ MarshalAs( UnmanagedType.ByValTStr, SizeConst=14 )]
public String alternateFileName = null;
}


public class LibWrap

{

// Declares a managed prototype for the unmanaged function.
[DllImport( "Kernel32.dll", CharSet=CharSet.Auto )]
public static extern IntPtr FindFirstFile( String fileName, [ In, Out ]
FindData findFileData );


[ DllImport( "Kernel32.dll", CharSet=CharSet.Auto )]

public static extern int FindNextFile( IntPtr handle, ref FindData

findFileData );

}

Regards,
R.Venkatesh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top