Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8978499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:37:43+00:00 2026-06-15T19:37:43+00:00

The MSDN document that I am trying to follow is located here . Basically

  • 0

The MSDN document that I am trying to follow is located here. Basically I am trying to figure out in C# how to read that pointer into a list of the DHCP_OPTION_DATA structures.

I have the following code but I don’t think that it is the proper way to do this.

DHCP_OPTION_ARRAY optionArray = (DHCP_OPTION_ARRAY)Marshal.PtrToStructure(options, typeof(DHCP_OPTION_ARRAY));
List<DHCP_OPTION> allOptions = new List<DHCP_OPTION>();
for (int i = 0; i < optionArray.NumElements; i++) {
    DHCP_OPTION option = (DHCP_OPTION)Marshal.PtrToStructure(optionArray.Options, typeof(DHCP_OPTION));
    allOptions.Add(option);
    optionArray.Options = (IntPtr)((int)optionArray.Options + (int)Marshal.SizeOf(option));
}

Since I can’t Marshal the pointer into a generic list collection I tried this way. My problem is that I am getting skewed results based on how much I increase the IntPtr to. Initially I was doing this.

optionArray.Options = (IntPtr)((int)optionArray.Options + (int)Marshal.SizeOf(typeof(DHCP_OPTION_DATA)));

However, I then realized that the next element would be located after the size of the actual option.

So the question still remains, how do I Marshal a Ptr to a list of structures?

EDIT 1

I posted the wrong article it is fixed now.

EDIT 2

Although both answers were great, I chose the answer to my problem because it addressed my lack of understanding of how the data was being handled on the back end of marshaling the information.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:37:45+00:00Added an answer on June 15, 2026 at 7:37 pm

    Is the first option object you get correct?
    If so, the reason for the rest being skewed most likely is the alignment of the structure.

    You could try to find the correct alignment, for example:

    var offset = (int)Marshal.SizeOf(typeof(DHCP_OPTION_DATA));
    var alignment = 4; 
    var remainder = offset % alignment;
    if(remainder != 0)
        offset += alignment - remainder;
    
    optionArray.Options = (IntPtr)((int)optionArray.Options + offset);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I'm trying to replicate MSDN pseudoframes here. Their pages are laid out like
I read this MSDN document regarding the operator overloading. In that example, the operators
I am trying to follow this example: http://msdn.microsoft.com/en-us/library/aa179614%28SQL.80%29.aspx# It says to add the following
It blows my mind that the official document at MSDN doesn't say anything about
I am trying to figure out how to click a button on a web
From the MSDN document, we can see that, we should not call LoadLibrary/FreeLibrary in
From MSDN document i understand ( I am not sure,i understand perfectly ) :
I got a strange compilation error when I followed the MSDN document to use
MSDN states that String.Intern retrieves the system's reference to the specified String and String.IsInterned
MSDN docs say that only value types need boxing, but this does not apply

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.