C type의 소스를 C#으로 변경중 하기 HookFunction을 어떻게 처리해야 하는지 고민하다..

알게된 사실... 2번째 인자를 이벤트로 처리해서 MappHookFunction 발생시 연결된

이벤트가 호출되도록 하면 된다는것..

 

MIL.MappHookFunction(MIL.M_ERROR_CURRENT, DisplayDrv_eDisplayErrorExt, MIL.M_NULL);

 

상기 함수의 원형은 이렇다.

///////////////////////////////////////////////////////////////////////////

void MappHookFunction(

MIL_APP_HOOK_FUNCTION_PTR HookHandlerPtr,

)

///////////////////////////////////////////////////////////////////////////

여기서, MIL_APP_HOOK_FUNCTION_PTR 의 원형은 이렇다.

///////////////////////////////////////////////////////////////////////////

namespace Matrox.MatroxImagingLibrary
{
public delegate MIL_INT MIL_APP_HOOK_FUNCTION_PTR
(

MIL_INT HookType,

MIL_ID EventId,

IntPtr UserDataPtr );

}

///////////////////////////////////////////////////////////////////////////

즉, delegate로 선언되어있기때문에, event로 인스턴스 선언하고 event 등록시키면 된다.

요렇게..

선언.

public event MIL_APP_HOOK_FUNCTION_PTR eDisplayErrorExt;

처음 로딩되는 부분에서 이벤트 등록

eDisplayErrorExt += new MIL_APP_HOOK_FUNCTION_PTR(DisplayDrv_eDisplayErrorExt);

실제 사용하는 부분

// user-defined function to a specified application event

MIL.MappHookFunction (

MIL.M_ERROR_CURRENT,

DisplayDrv_eDisplayErrorExt,

MIL.M_NULL );

hook 발생시 실행되는 함수 원형

// MIL Application Hooking Function(event-function)
MIL_INT DisplayDrv_eDisplayErrorExt(MIL_INT HookType, MIL_ID EventId, IntPtr UserDataPtr) {
StringBuilder szbFunction = new StringBuilder(MIL.M_ERROR_MESSAGE_SIZE);
// M_CURRENT_FCT : Returns the opcode associated with the last function

called, when it returns an error.
MIL.MappGetHookInfo(EventId,

MIL.M_MESSAGE + MIL.M_CURRENT_FCT,

szbFunction );

return MIL.M_NULL;

}

+ Recent posts