C+的C#绑定+;图书馆
我已经为libpostal库()创建了一个c#绑定 我使用CppSharp创建绑定。它可以工作,但我不知道如何转换此代码:C+的C#绑定+;图书馆,c#,c++,.net,binding,cppsharp,C#,C++,.net,Binding,Cppsharp,我已经为libpostal库()创建了一个c#绑定 我使用CppSharp创建绑定。它可以工作,但我不知道如何转换此代码: typedef struct libpostal_address_parser_response { size_t num_components; char** components; char** labels; } libpostal_address_parser_response_t; CppSharp以这种方式转换代码: public sb
typedef struct libpostal_address_parser_response
{
size_t num_components;
char** components;
char** labels;
}
libpostal_address_parser_response_t;
CppSharp以这种方式转换代码:
public sbyte** Components
{
get
{
return (sbyte**)((global::LibPostalNet.LibpostalAddressParserResponse.__Internal*)__Instance)->components;
}
set
{
((global::LibPostalNet.LibpostalAddressParserResponse.__Internal*)__Instance)->components = (global::System.IntPtr)value;
}
}
public sbyte** Labels
{
get
{
return (sbyte**)((global::LibPostalNet.LibpostalAddressParserResponse.__Internal*)__Instance)->labels;
}
set
{
((global::LibPostalNet.LibpostalAddressParserResponse.__Internal*)__Instance)->labels = (global::System.IntPtr)value;
}
}
代码应返回长度为num_的字符串数组
你能帮我解决这个问题吗?这有点复杂,因为它们是指向字符指针列表的指针,非常类似于字符串数组 您需要迭代指针,检索内部指针并将其转换为字符串(我假设您可以使用非托管代码):
libpostal\u address\u parser\u response=(从库中检索);
列表组件=新列表();
列表标签=新列表();
//不确定num_组件的名称,因为您尚未将其添加到问题中
//检查名称是否正确
对于(int-buc=0;buc
主持人注意:虽然谈话开始时目的正当,但似乎已沦为不友好的争论。我已经删除了这里的所有评论,并锁定了帖子。请休息几分钟。
libpostal_address_parser_response response = (retrieve from the library);
List<string> components = new List<string>();
List<string> labels = new List<string>();
//Not sure the name of num_components as you haven't added it to the question
//check if the name is 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 you have the components and the labels in their respective lists ready for usage.