Valhalla Legends Archive

Programming => General Programming => .NET Platform => Topic started by: TheMinistered on April 27, 2004, 06:08 PM

Title: Pointer to a Structure? [VB.NET]
Post by: TheMinistered on April 27, 2004, 06:08 PM
Is there any other method of retrieving a pointer to a structure other than the Marshall.StructureToPtr function?
Title: Re:Pointer to a Structure? [VB.NET]
Post by: K on April 27, 2004, 07:12 PM
Not that I know of in VB.NET.

However, in C#:


public struct TestStruct
{
   public int i;
   public double d;
};

public class cTmp
{
   static unsafe void Main(string[] args)
   {
      TestStruct s;

      // this may need to be in a fixed() {} block if you allocate
      // s with new() since the CLR can move items around in memory
      TestStruct* pointer = &s;
         
      int i = (int)pointer;
      Console.WriteLine(i);
   }
}