I would like to build an extension for Gig Perform, but I have no knowledge of C og C++. I am going to build it using C#. Can anyone point me to an example of how to use the C api in C#?
I doubt anybody has tried that - C# doesn’t use C headers directly - but if you have used C#, then using C++ isn’t really that much different.
Ok. I might give it a go.
In principle
It’s possible. I wrote in-between-assemblies for several not-GP-related projects of my own. But because extensions live on doing callbacks, it’s rather complicated, especially if you want to route the callbacks to c# class members. Furthermore, the marshaling you need to do is cumbersome.
My usual approach
Write a c++ translation assembly with the clr enabled.
- Create a .cpp and .h where the class in managed code is going to reside.
- Also create a separate .cpp and .h where a class in unmanaged code is going to live.
- Then write code to forward the calls to the managed class to the unmanaged class. And vice versa: Callbacks to the unmanaged class must be forwarded to the managed class.
- In Visual studio, make sure that only the managed cpp/h files are compiled with /clr. You can force that in the properties dialogue of these files.
- Then, in a normal c# project, reference the resulting assembly.
Don’t forget to take a some pain killers to fight the upcoming headache ![]()
But
I wouldn’t do this for extensions for GP. Thing is that the .Net garbage collector has a mind of it’s own and you also don’t have much control on allocating memory. I’m not sure whether this will affect the audio thread or not, but if it does, it could lead to crackling, dropouts and stuttering in the audio.
Plain c++ would be easier in the end.