How to custom marshal parameter in callback function pointer with source generation?
- Dominant language
- No language data
- Stars
- 4.8k
- Forks
- 6.1k
- Avg merge
- 15h 21m
- Merged PRs (30d)
- 370
Description
### Type of issue
Missing information
### Description
My C API takes a function pointer as callback parameter, and the callback takes a string that needs custom marshalling. However, the document doesn't mention how to apply custom marshaller on delegate.
I did some test and it looks MarshalUsing doesn't work with function pointer delegate.
```
internal delegate void ACallback([MarshalUsing(typeof(Utf32StringMarshaller))] string word);
[LibraryImport("./mylib.so", EntryPoint ="TestFunc")]
internal static partial int TestFunc(ACallback callback);
```
The custom marshaller is not called when ACallback is invoked.
### Page URL
https://learn.microsoft.com/en-us/dotnet/standard/native-interop/custom-marshalling-source-generation
### Content source URL
https://github.com/dotnet/docs/blob/main/docs/standard/native-interop/custom-marshalling-source-generation.md
### Document Version Independent Id
92017668-936b-57b2-4e84-8f545ffcc600
### Article author
@jkoritzinsky
### Metadata
* ID: ff5eeaf7-0696-7d3b-3220-c502aa4ec7da
* Service: **dotnet-fundamentals**
Contributor guide
Assessment
This issue has not been assessed yet.