MIL_DIG_HOOK_FUNCTION_PTR ProcessingFunctionPtr = new MIL_DIG_HOOK_FUNCTION_PTR(ProcessingFunction);
MIL.MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize, MIL.M_START, MIL.M_DEFAULT, ProcessingFunctionPtr, GCHandle.ToIntPtr(hUserData));
其中
public delegate MIL_INT MIL_DIG_HOOK_FUNCTION_PTR(MIL_INT HookType, MIL_ID EventId, IntPtr UserDataPtr);
但如果是用在winform 應用程式裡面,如果把上面那段放在Form的Initial中,需要把 ProcessingFunctionPtr 定義成在 Form的Class底下的static member
MyForm:Form
{
static MIL_DIG_HOOK_FUNCTION_PTR ProcessingFunctionPtr;
void MyForm()
{
...
ProcessingFunctionPtr = new MIL_DIG_HOOK_FUNCTION_PTR(ProcessingFunction);
MIL.MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize, MIL.M_START, MIL.M_DEFAULT, ProcessingFunctionPtr, GCHandle.ToIntPtr(hUserData));
}
}
否則在執行期ProcessingFunctionPtr會被Gabage collection清掉而產生error
但在C# 2.0 好像可以直接寫成
ProcessingFunctionPtr = ProcessingFunction;