从iOS上的本地方法运行时创建委托 [英] Create delegate at runtime from native method on iOS
问题描述
这是一个特定的MonoTouch - 的问题。
我目前正在开发的OpenGL的包装是从像OpenTK包装完全不同。这种包装是用来启用OpenGL的更快发展
I'm currently developing a wrapper for OpenGL which is quite different from wrappers like OpenTK. This wrapper is used to enable faster development with OpenGL.
方法不声明如下:无效glGenTextures(的Int32 N,UInt32的[]纹理) ;
,它们被声明像无效glGenTextures(的Int32算,[出] TextureHandle []纹理)
,其中 TextureHandle
是相同尺寸为 UInt32的
。
Methods are not declared like this: void glGenTextures(Int32 n, UInt32[] textures);
, they are declared like void glGenTextures(Int32 count, [Out]TextureHandle[] textures)
where TextureHandle
is a structure with the same size as a UInt32
.
在Windows上,我可以使用 GetProcAddress的
, wglGetProcAddress
和 Marshal.GetDelegateForFunctionPointer
从方法指针创建委托,但如何与MonoTouch的做iOS上。有什么办法来这还是它不受MonoTouch的被支持
On Windows i can use GetProcAddress
, wglGetProcAddress
and Marshal.GetDelegateForFunctionPointer
to create a delegate from a method pointer, but how to do this on iOS with MonoTouch. Is there any way to this or is it not supported by monotouch yet?
推荐答案
的用的MonoTouch 5.4开始这是可能的。您需要创建具有相同签名的管理方法的委托,并与 MonoNativeFunctionWrapper
属性装饰它:
Starting with MonoTouch 5.4 this is possible. You need to create a delegate with the same signature as the managed method, and decorate it with the MonoNativeFunctionWrapper
attribute:
[MonoNativeFunctionWrapper]
public delegate void glGenTexturesDelegate (int n, uint[] textures);
现在,你可以调用方法:
Now you can call the method:
var del = (glGenTexturesDelegate) Marshal.GetDelegateForFunctionPointer (pointer);
del (n, textures);
这是说,我相信你正在做这个有很多更复杂的比你需要。只需使用的P / Invoke:
That said, I believe you're doing this a lot more complicated than you need to. Just use a P/Invoke:
[llImport("libGLESv2.dll")]
extern static void glGenTextures (int n, uint[] textures);
然后调用它是这样的:
and then call it like this:
glGenTextures (n, textures);
这篇关于从iOS上的本地方法运行时创建委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!