When try pass only one delegate as parameter, all work fine.
But I need call function, that take as parameter array of function
pointers. From C++ code I used such code:
static void* aFuncPtrs[] =
{
&Function1,
&Function2,
&Function3,
};
UnmanagedFunction( aFuncPtrs );
How can I do same in C# ? I try next (suppose all methods have same
prototype ):
delegate void UnmanagedFunctionDelegate();
void Function1(){};
void Function2(){};
void Function3(){};
[DllImport(...)]
private static extern void UnmanagedFunction(
[MarshalAs(UnmanagedType.LPArray,
ArraySubType=UnmanagedType.FunctionPtr)]
UnmanagedFunctionDelegate[] v_aFunctions );
UnmanagedFunctionDelegate[] aFuncPtrs=
{
new UnmanagedFunctionDelegate( Function1 ),
new UnmanagedFunctionDelegate( Function2 ),
new UnmanagedFunctionDelegate( Function3 )
};
UnmanagedFunction( aFuncPtrs );
But this not work (access violation). Using ClrSpy I see:
"Marshaling from UnmanagedFunctionDelegate[] to native array of
IUnknown * (size not specified by a parameter) in method
UnmanagedFunction."
In same time if try pass only one delegate (thats work fine), ClrSpy
show:
"Marshaling from UnmanagedFunctionDelegate to Delegate in method
UnmanagedFunction2."
How say C# to marshal array items as Delegate, not IUnknown * ?