I've got it! The problem was that the functions of the API (flycaptureCreateContext, flycaptureModifyCallback and flycaptureDestroyContext) were declared in the C headers as __cdecl, but I haven't considered it in the DllImport statements. There follows corrected C# code:
[DllImport("pgrflycapture.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int flycaptureCreateContext(void** pContext);
[DllImport("pgrflycapture.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int flycaptureDestroyContext(void* context);
[DllImport("pgrflycapture.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int flycaptureModifyCallback(void* context, FlyCaptureCallback pfnCallback, void* pParam, bool bAdd);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void FlyCaptureCallback(void* Param, int Message, uint lParam);
static void Callback(void* Param, int Message, uint lParam)
{
Console.WriteLine(Message.ToString() + "\t" + lParam.ToString());
}
static void Main(string[] args)
{
void *context;
FlyCaptureCallback callback = (FlyCaptureCallback) Callback;
flycaptureCreateContext(&context);
flycaptureModifyCallback(context, callback, null, true);
Thread.Sleep(5000);
flycaptureModifyCallback(context, callback, null, false);
flycaptureDestroyContext(context);
}
Thanks lnmx and Jim Mischel for your valuable help!