private static Delegate LoadDelegate <T>(IntPtr dllAddress, string functionName) { var address = WinApiHelper.GetProcAddress(dllAddress, functionName); if (address == IntPtr.Zero) { throw new InvalidOperationException($"Failed to get delegate address for {functionName}"); } return(Marshal.GetDelegateForFunctionPointer(address, typeof(T))); }