我在使用 c# 为 iPhone 构建应用程序时发现了这个错误错误。这个应用程序有一个将 System.Object 实例传递给 c 的插件我得到了这个,我不确定缺少什么部分!
这是 C# 代码:
public static void Call( System.IntPtr L, System.Delegate pDelegate)
{
MonoDelegateToPtr( L, 0, pDelegate.Method.Target, pDelegate.Method.Name, pDelegate.Method.GetParameters().Length);
}
[System.Runtime.InteropServices.DllImport("__Internal")]
static extern void MonoDelegateToPtr( System.IntPtr L, int pN, System.Object pObj, string pMethod, int pParamCount);
这是C代码:
extern "C" void MonoDelegateToPtr( lua_State* L, int pN, MonoObject* pObj, const char* pMethod, int pParamCount)
{
MonoMethod *method;
MonoObject *pObject;
method = GetCSMethod( pObject, pMethod, pParamCount);
lua_CFunction func = (lua_CFunction)[MonoUtility MonoDelToPtr: method];
if( func==0)
{
printf("****ERROR DELEGATE TO FUNCTION PTR IS NULL%s\n", pMethod);
return;
}
lua_pushcclosure( L, func, pN);
}
MonoMethod* GetCSMethod( MonoObject *pObj, const char* pMethod, int pParamsTotal)
{
MonoClass *class = mono_object_get_class( pObj);
MonoMethod *methodDef = mono_class_get_method_from_name( class, pMethod, pParamsTotal);
return mono_object_get_virtual_method((MonoObject*)objectInstance, methodDef);
}
这是错误消息:
MarshalDirectiveException
在(包装器托管到本机)CSharpToMonoClass:MonoDelegateToPtr (intptr,int,object,string,int)