public Callbacks(Instance instance, ICallbacks callbacks) { _instance = instance; CallbacksImpl = callbacks; _handle = GCHandle.Alloc(this); _functions = new FMI2.fmi2CallbackFunctions { logger = LoggerCallback, allocateMemory = Marshalling.AllocateMemory, freeMemory = Marshalling.FreeMemory, stepFinished = StepFinishedCallback, componentEnvironment = GCHandle.ToIntPtr(_handle) }; Structure = Marshalling.AllocateMemory(1, (ulong)Marshal.SizeOf(_functions)); Marshal.StructureToPtr(_functions, Structure, false); }