home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / dotNETSDK / SETUP.EXE / netfxsd1.cab / FL_Void_cs________.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Encoding:
Text File  |  2001-08-27  |  1.4 KB  |  60 lines

  1. // Copyright
  2. // Microsoft Corporation
  3. // All rights reserved
  4.  
  5. // Void.cs
  6.  
  7. using System;
  8. using System.Text;
  9. using System.Runtime.InteropServices;
  10.  
  11. public class LibWrap
  12. {
  13.     public enum DataType 
  14.     {
  15.         DT_I2 = 1,
  16.         DT_I4,
  17.         DT_R4,
  18.         DT_R8,
  19.         DT_STR
  20.     }
  21.     
  22.     // void SetData(DataType typ, void* object)
  23.     // using AsAny when void* is expected
  24.     
  25.     [ DllImport( "..\\LIB\\PinvokeLib.dll" )]
  26.     public static extern void SetData( DataType t, 
  27.         [ MarshalAs( UnmanagedType.AsAny )] Object o );
  28.     
  29.     // using overloading when void* is expected
  30.     
  31.     [ DllImport( "..\\LIB\\PinvokeLib.dll", EntryPoint="SetData" )]
  32.     public static extern void SetData2( DataType t, ref double i );            
  33.     
  34.     [ DllImport( "..\\LIB\\PinvokeLib.dll", EntryPoint="SetData" )]
  35.     public static extern void SetData2( DataType t, String s );    
  36.     
  37. }
  38.  
  39. public class App
  40. {
  41.     public static void Main()
  42.     {
  43.         Console.WriteLine( "Calling SetData using AsAny... \n" );
  44.         
  45.         LibWrap.SetData( LibWrap.DataType.DT_I2, (short)12 );
  46.         LibWrap.SetData( LibWrap.DataType.DT_I4, (long)12 );
  47.         LibWrap.SetData( LibWrap.DataType.DT_R4, (float)12 );
  48.         LibWrap.SetData( LibWrap.DataType.DT_R8, (double)12 );
  49.         LibWrap.SetData( LibWrap.DataType.DT_STR, "abcd" );    
  50.         
  51.         Console.WriteLine( "\nCalling SetData using overloading... \n" );    
  52.             
  53.         double d = 12;
  54.         LibWrap.SetData2( LibWrap.DataType.DT_R8, ref d );
  55.         LibWrap.SetData2( LibWrap.DataType.DT_STR, "abcd" );
  56.     }
  57. }
  58.  
  59.  
  60.