.net - What is the correct C# interop code to handle this structure and method? -


I am writing a managed wrap around an unmanaged DLL, and I want to do the following method and structure correctly Marshall I'm unable to Here's what .h file for unmanaged code:

  typedef struct {WORD PI_code; Dedworld's GrafStat [31]; BYTE PTY_code; Four * ps; Four * RT; } RdsData_t; COMPANYNAME_API Zero COMPANY_get_rds_data (RdsData_t * rds_data);  

And here's what I did, P-Invok Interop with some help from assistant:

  [StructLayoutAttribute (LayoutKind.Sequential)] public structure RdsData_t {/// WORD- & gt; Signed small public use PI_code; /// Deedwards [31] [Marshlasatribut (unmanaged type. Bevlarere, Size Knnst = 31, Aeresbteep = unmanaged type U 0.4)] public UIT [] Jiarpitat; /// byte-> Unsigned four public byte PTY_code; /// four * [UnmanagedType.LPStr]] Public String PS; /// four * [UnmanagedType.LPStr]] public string RT; } [DllImport ( "companyname.dll", EntryPoint = "? COMPANYNAME_get_rds_data @@ YAXPAURdsData_t @@@ Z")] private static extern void COMPANYNAME_get_rds_data (ref RdsData_t data);  

However, through it throws a AccessViolationException when called discovery and experimentation, I am able to come up with something that does not take exception, but the data is wrong or Unavailable, to believe me that they are not right or not correct

What should I use the interop code for the above structure? Is there any tool other than Pinevoc Helper that can use to help me?

Thanks in advance!

try the following

  [StructLayoutAttribute (LayoutKind.Sequential)] Public Unsafe Structure RdsData_t {/// WORD- & gt; Signed small public use PI_code; /// Deedwards [31] [Marshlasatrybet (unmanaged type. Bevlarere, size Knent = 31, Arresbteep = unmanaged type U 0.4)] public certain units Grupstat [31]; /// byte-> Unsigned four public byte PTY_code; /// four * [UnmanagedType.LPStr]] Public String PS; /// four * [UnmanagedType.LPStr]] public string RT; }  

Note: However, you will need to have your library / app perform unsecured code so that it does work.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -