C# bindings for a c++ library
C# bindings for a c++ library
我已经为libpostal库创建了一个C#绑定(链接到libpostalnet)。
我已经使用cppsharp创建绑定。它有效,但我不如何转换此代码:
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_components长度的字符串数组。
您能帮我解决这个问题吗?
这有点复杂,因为这些指针是指炭列表的指针,与一系列字符串非常相似。
您需要迭代指针,检索内部指针并将其转换为字符串(我假设您可以使用非托管代码):
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.
相关文章:
- Boost Graph Library,修复节点大小
- SFML library: http request
- 解决"ld: library not found for -ltensorflow_framework.2.3.0"
- Linking library C++
- 在VS2019项目中集成ImageMagick:x64-windows-static library
- OpenSSL fips in C++ wrapper Library 如何?错误:指纹不匹配
- C++ class vs a library
- C++ library with Tensorflow on Android
- CMake:尝试在 Jenkins 构建机器上运行时出现"Linked Library"错误 (0xc0000135)
- 将 c++ cmake-library 构建发布到本地存储库时出现 Gradle 错误
- 为什么'allocate in one library and free in the other'是错误的
- 链接 library.lib 使用 setup.py.
- 目标提升::<library>已经有导入的位置 + 链接错误
- Visual Studio 2017 C++,如何定义一个"环境变量"'Additional Library Directory'?
- C++ Boost SML Library
- Windows 套接字和身份验证构建在包含 Poco-Library 时失败
- Qt小部件应用程序"Library not registered"错误
- Xcode/IOS: linking a CMake library
- 如何修复'The procedure entry point SDL_RWclose could not be located in the dynamic link library'
- Creating C++ API Library