I'm trying to call an C function from a .NET application. Indeed I do the following:
public unsafe class Simd
{
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate void MatrixMultiplyDelegate(float* left, float* right);
public static MatrixMultiplyDelegate MatrixMultiply;
public static void LoadSimdExtensions()
{
string assemblyPath = "Derm.Simd.dll";
// Really calls 'LoadLibrary', 'GetProcAddress', 'FreeLibrary' from Kernel32.dll
IntPtr address = GetProcAddress.GetAddress(assemblyPath, "Matrix4x4_Multiply_SSE");
if (address != IntPtr.Zero) {
MatrixMultiply = (MatrixMultiplyDelegate)Marshal.GetDelegateForFunctionPointer(address, typeof(MatrixMultiplyDelegate));
}
}
}
The function loaded is declared as follow:
extern "C" {
void __declspec(dllexport) Matrix4x4_Multiply_SSE(float *left, float *right);
}
Sadly, I get the following exception when calling GetDelegateForFunctionPointer:
InvalidFunctionPointerInDelegate:
Invalid function pointer 0xb81005 was passed into the runtime to be converted to a delegate.
What am I doing wrong?