コード例 #1
0
        /// <summary>
        /// Creates a wrapper function that transforms our own C# function into an arbitrary calling convention; with pointer to transformed C# function.
        /// Basically, this creates a function pointer to a C# function.
        /// Note: You must keep an instance of this class as long as you're using the function pointer.
        /// </summary>
        /// <param name="function">The function to create a function pointer to.</param>
        public static X64ReverseFunctionWrapper <TFunction> CreateReverseWrapper(TFunction function)
        {
            // Set our C# function.
            var reverseFunctionWrapper = new X64ReverseFunctionWrapper <TFunction>();

            reverseFunctionWrapper.CSharpFunctionCopy = function;

            // Take fast path for CDECL, otherwise assemble wrapper.
            var reloadedFunctionAttribute = FunctionCommon.GetX64ReloadedFunctionAttribute <TFunction>();

            reverseFunctionWrapper.Pointer = CreateX64WrapperFunctionInternal <TFunction>(Marshal.GetFunctionPointerForDelegate(function), reloadedFunctionAttribute);

            return(reverseFunctionWrapper);
        }