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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:25:34+00:00 2026-05-26T15:25:34+00:00

Hi I writing a wrapper in c# and i have some problem. I have

  • 0

Hi I writing a wrapper in c# and i have some problem. I have this struct in c++.

typedef struct pjmedia_format
{
    pj_uint32_t id;
    pjmedia_type type;
    pjmedia_format_detail_type detail_type;
    union
    {
    pjmedia_audio_format_detail aud;
    pjmedia_video_format_detail vid;
    char user[PJMEDIA_FORMAT_DETAIL_USER_SIZE];
    } det;
} pjmedia_format;

This is link to this struct pjmedia_format

in c# I have this:

[StructLayout(LayoutKind.Sequential)]
public struct pjmedia_format
{
    public uint id;
    public pjmedia_type type;
    public pjmedia_format_detail_type detail_type;
    public det_t det;
}

[StructLayout(LayoutKind.Explicit)]
public struct det_t
{
    [FieldOffset(0)]
    [MarshalAs(UnmanagedType.Struct)]
    public pjmedia_audio_format_detail aud;
    [FieldOffset(36)]
    [MarshalAs(UnmanagedType.Struct)]
    public pjmedia_video_format_detail vid;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
    [FieldOffset(60)]
    public char[] user;
}

[StructLayout(LayoutKind.Sequential)]
public struct pjmedia_audio_format_detail
{
    public uint clock_rate;
    public uint channel_count;
    public uint frame_time_usec;
    public uint bits_per_sample;
    public int avg_bps;
    public int max_bps;
}

[StructLayout(LayoutKind.Sequential)]
public struct pjmedia_video_format_detail
{
    public pjmedia_rect_size size;
    public pjmedia_ratio fps;
    public int avg_bps;
    public int max_bps;
}

and when i want to use this struct i get this error

System.Runtime.InteropServices.MarshalDirectiveException was unhandled.
Message=”A method signature is not PInvoke compatible with the element.”

I try to use some attributes like size or pack but it doesn’t help (probably i use it wrong). I tested singly other struct e.g. pjmedia_video_format_detail and they works well. Any advice?

Best regards
Andrzej

  • 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-26T15:25:35+00:00Added an answer on May 26, 2026 at 3:25 pm

    As this is a union, shouldn’t that be:

    [StructLayout(LayoutKind.Explicit)]
    public struct det_t
    {
        [FieldOffset(0)]
        [MarshalAs(UnmanagedType.Struct)]
        public pjmedia_audio_format_detail aud;
        [FieldOffset(0)]
        [MarshalAs(UnmanagedType.Struct)]
        public pjmedia_video_format_detail vid;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
        [FieldOffset(0)]
        public char[] user;
    }
    

    i.e. overlapping? Also, you might need user to be a fixed buffer rather than an array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From this question here , I was writing an enum wrapper to have some
I am writing a Windows Api wrapper and I have run into a problem.
I am currently writing an open source wrapper for a COM object. I have
I'm writing a silverlight app which does some real-time charting. Basically, I just have
I am writing a wrapper to automate some android ADB shell commands via Python
I am having an problem writing unit tests for an simple session wrapper. The
I have a small hobby project where I'm writing a 'wrapper'-daemon in linux, in
Im currently writing a C# wrapper for a C++ API, but a specific struct
I am writing a wrapper for plot that automates some tasks that I find
I'm in the process of writing a wrapper for some OpenGL functions. The goal

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.