CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2011

    Question PInvoke a C++ unsigned char [][] to C#?

    The C++ structure like that:

    typedef struct d_setting
    unsigned short setting1;
    unsigned char name[100][200];

    typedef struct d_config
    unsigned short data;
    D_SETTING setting;

    And i tried to call the C++ function by creating the corresponding structure in C# like:

    public struct D_SETTING
    public ushort setting1;
    public byte[][] name;

    public struct D_CONFIG
    public ushort data;
    public D_SETTING setting;

    But the name is not correct, the program crash..
    How could i create the structure for unsigned char[][] in C++??

  2. #2
    Join Date
    Apr 2014
    in northeast ohio

    Re: PInvoke a C++ unsigned char [][] to C#?

    well i normally stay away from pinvoke questions
    as i in general i don't really like to use it.
    and though its been a very long time since i played around with c++
    don't you have define at least one dimension not 100% on that
    are you sure that code actually compiles in c c++.
    cause wouldn't you be calling a undeclared 2d array of uninitialized references

    you might be able to find a example here that already does it.
    or something close enough you can use to do it.
    this is a pretty tough question. here is a similar one
    and if you read to the bottom of that link, you should also note.
    Please note the "char" type in C takes 1 byte, "char" in C# takes two bytes, therefore you need to use byte in C#
    Last edited by willmotil; July 8th, 2014 at 10:48 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.