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 720767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:47:47+00:00 2026-05-14T05:47:47+00:00

I have such a C++ structure: typedef struct _FILE_OP_BLOCK { unsigned short fid; //

  • 0

I have such a C++ structure:

typedef struct _FILE_OP_BLOCK
{                                                                                                                          
    unsigned short fid;     // objective file ID 
    unsigned short offset;  // operating offset
    unsigned char len;      // buffer length(update)
                            // read length(read)        
    unsigned char buff[240];
} FILE_OP_BLOCK;

And now I want to map it in .Net. The tricky thing is that the I should pass a 2 byte array for fid, and integer for len, even though in C# fid is an unsigned short and len is an unsigned char

I wonder whether my structure ( in C#) below is correct?

   [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Auto)]
   public struct File_OP_Block 
    {
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
        public byte[] fid;

        public ushort offset;

        public byte length;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 240)]
        public char[] buff;
    }
  • 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-05-14T05:47:47+00:00Added an answer on May 14, 2026 at 5:47 am

    Your CharSet property on the [DllImport] attribute is definitely wrong, you need CharSet.Ansi to get the P/Invoke marshaller to convert it to a char[]. Declare the buff member as a string for easier usage. While declaring the fid member as a byte[] isn’t wrong, I really don’t see the point of it. That the unmanaged code copies a char[] into it is an implementation detail. Thus:

    [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
    public struct File_OP_Block 
    {
        public ushort fid;
        public ushort offset;
        public byte length;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 240)]
        public string buff;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a structure such as typedef struct _people { char *name; bool
Assuming I have a structure such as: typedef struct { char * string1; char
I have a structure such as typedef struct FT_Bitmap_ { int rows; int width;
I have this structure which I want to write to a file: typedef struct
I have xml file with such structure: ... <outer> ... <inner/> ... </outer> ...
I have to parse a 1Gb XML file with a structure such as below
Suppose I have a structure in C or C++, such as: struct ConfigurableElement {
I have a C structure that looks like this typedef struct event_queue{ Event* event;
Lets say, I have the following text file: Listing 1: Endianess=little AddressModel=32 typedef struct{
I have the following data structure in C: typedef struct { void* buffer; ...

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.