Re: Re: trouble modifying passthru sample

Home Forums Discussions Support trouble modifying passthru sample Re: Re: trouble modifying passthru sample

#6842
asmercer2004
Participant

    A quick update:

    I modified my code based on your last comments (thanks for the response by the way), and ended up with this:

    byte[] newPacket = new byte[sizeof(ETHER_HEADER) + sizeof(IPHeader) + sizeof(UdpHeader) + sizeof(PlatformHeader) + dataLength + sizeof(GPSHeader)];

    INTERMEDIATE_BUFFER outgoingBuffer = new INTERMEDIATE_BUFFER();
    outgoingBuffer = PacketBuffer;
    outgoingBuffer.m_Length = PacketBuffer.m_Length + (uint)sizeof(GPSHeader);
    outgoingBuffer.m_IBuffer = newPacket;

    IntPtr outgoingPacket = Marshal.AllocHGlobal(Marshal.SizeOf(outgoingBuffer));
    Marshal.StructureToPtr(outgoingBuffer, outgoingPacket, false);

    ETH_REQUEST outgoingRequest = new ETH_REQUEST();
    outgoingRequest.hAdapterHandle = Request.hAdapterHandle;
    outgoingRequest.EthPacket.Buffer = outgoingPacket;

    // put the modified packet on the network card for sending
    Ndisapi.SendPacketToAdapter(hNdisapi, ref outgoingRequest);

    When it gets to the line Marshal.StructureToPtr(…) I get the following error:
    Type could not be marshaled because the length of an embedded array instance does not match the declared
    length in the layout.

    I assume that this is a problem with the data length or something but I can’t figure it out. Any idea as to why I would be getting this error?