I've created a test harness for MEX-files, written in C++. It includes the following lines of code:
#include <windows.h> // some lines typedef void (CALLBACK* PFUN)(int, mxArray**, int, mxArray**); HINSTANCE hDLL = LoadLibrary("MyMexFunction.mexw32"); PFUN f; f = (PFUN)GetProcAddress(hDLL,"mexFunction");
Later, "f" is used to call the MEX-function.
While I can call my MEX-file from MATLAB without problem, I receive a runtime error such as:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
when I attempt to run my test harness.
Best Answer