mono / CppSharp

Tools and libraries to glue C/C++ APIs to high-level languages
MIT License
3.12k stars 514 forks source link

Disable string Marshaller usage in C# #1818

Open bmassemin opened 10 months ago

bmassemin commented 10 months ago
Brief Description

👋 Is there a way to disable the usage of a string marshaller in C#? I would like to provide my string pointer directly to the native call. Thanks 🙏

OS: Windows

deadlocklogic commented 10 months ago

This should work:

public void SetupPasses(Driver driver)
{
    TypeMapDatabase.TypeMapsByKind(driver.Context.TypeMaps.GlobalTypeMaps, GeneratorKind.CSharp).Remove("basic_string<char, char_traits<char>, allocator<char>>");
}

It just disable the C# string typemap, but not totally sure about its usage.

bmassemin commented 10 months ago

I've overridden the const char* typemap and now I can use an IntPtr. But now I would like to be able to use a byte* instead. It works, but the generated struct still have an __IntPtr type, I'm not sure how to tell CppSharp to use byte* for const char*.