C# bindings for a c++ library -


i've created c# bindings libpostal library (link libpostalnet).

i've used cppsharp create bindings. works don't how convert code :

typedef struct libpostal_address_parser_response {     size_t num_components;     char** components;     char** labels; } libpostal_address_parser_response_t; 

cppsharp converts code in way :

public sbyte** components {         {         return (sbyte**)((global::libpostalnet.libpostaladdressparserresponse.__internal*)__instance)->components;     }      set     {         ((global::libpostalnet.libpostaladdressparserresponse.__internal*)__instance)->components = (global::system.intptr)value;     } }  public sbyte** labels {         {         return (sbyte**)((global::libpostalnet.libpostaladdressparserresponse.__internal*)__instance)->labels;     }      set     {         ((global::libpostalnet.libpostaladdressparserresponse.__internal*)__instance)->labels = (global::system.intptr)value;     } } 

code should return string array of num_components length.

can me solve this?

this bit complex pointer list of pointers of chars, similar array of strings.

you need iterate pointers, retrieve internal pointers , convert strings (i'm assuming can use unmanaged code):

libpostal_address_parser_response response = (retrieve library);  list<string> components = new list<string>(); list<string> labels = new list<string>();  //not sure name of num_components haven't added question //check if name correct for(int buc = 0; buc < response.numcomponents; buc++) {     sbyte* plabel = response.labels[buc];     sbyte* pcomponent = response.components[buc];      labels.add(marshal.ptrtostringauto((intptr)plabel));     components.add(marshal.ptrtostringauto((intptr)pcomponent)); }  //now have components , labels in respective lists ready usage. 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -