Pointer problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Blip

    #1

    Pointer problems


    Here is the relevant part of my structure...

    [StructLayout(La youtKind.Sequen tial)]
    public unsafe struct PPF_FILTER_DESC RIPTOR
    {


    public int* SrcAddr;
    public int* SrcMask;
    public int* DstAddr;
    public int* DstMask;

    }

    private PPF_FILTER_DESC RIPTOR filter;


    I'm trying to fill the field, SrcAddr -
    an int* PPF_FILTER_DESC RIPTOR.SrcAddr
    as filter.SrcAddr

    I can't seem to do this w/o errors...
    Obviously, this is a hobby project.

    Here's what I've been trying

    IPAddress sip = IPAddress.Parse ("10.1.1.1") ;
    Unsafe {
    src = BitConverter.To Int32(sip.GetAd dressBytes(), 0);
    filter.SrcAddr = &src;
    }

    This errors w/: You can only take the address of an unfixed expression
    inside of a fixed statement initializer


    I've tried:
    fixed(filter.Sr cAddr = &src;)

    This errors w/: Type or namespace name expected, but fieldname found.

    Not sure what to try next. Any suggestions?

    Thanks
  • Mattias Sjögren

    #2
    Re: Pointer problems

    >Not sure what to try next. Any suggestions?

    fixed (int* p = &src)
    {
    filter.SrcAddr = p;
    // ...
    }


    Mattias

    --
    Mattias Sjögren [C# MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    • Blip

      #3
      Re: Pointer problems

      On Sun, 02 Dec 2007 20:04:16 +0100, Mattias Sjögren
      <mattias.dont.w ant.spam@mvps.o rgwrote:
      >>Not sure what to try next. Any suggestions?
      >
      >fixed (int* p = &src)
      >{
      > filter.SrcAddr = p;
      > // ...
      >}
      >
      >
      >Mattias
      Doh...

      Thank you...

      Comment

      Working...