//======================================================================== // Begins testing. //======================================================================== void cdecl_begin() { // ----------------------------- // Call the original functions. // ----------------------------- cdecl_function1(); cdecl_function2(22, 32, 43); printf("\nResult of cdecl_function3: %d", cdecl_function3()); printf("\nResult of cdecl_function4: %d", cdecl_function4(22, 32, 43)); // ----------------------------- // Hook cdecl_functions! // ----------------------------- printf("\n\n********************************************************"); printf("\n* Phase 1: *"); printf("\n* Single hook. Call functions like normal. *"); printf("\n********************************************************\n"); AddCallBack(&cdecl_function1, "v)v", Convention_CDECL, &function1_hook); AddCallBack(&cdecl_function2, "iii)v", Convention_CDECL, &function2_hook); // ----------------------------- // Now call the hooked functions. // The hooks should call them // after finishing. // ----------------------------- cdecl_function1(); cdecl_function2(1,2,3); // ----------------------------- // Now add the override callback. // ----------------------------- printf("\n\n********************************************************"); printf("\n* Phase 2: *"); printf("\n* Two hooks. Do not call the original function. *"); printf("\n********************************************************"); AddCallBack(&cdecl_function1, "v)v", Convention_CDECL, &function1_override); AddCallBack(&cdecl_function2, "iii)v", Convention_CDECL, &function2_override); // ----------------------------- // Call cdecl_function1. // The override should prevent // the original function from // being called. // ----------------------------- cdecl_function1(); // ----------------------------- // Test to make sure we don't // crash. // ----------------------------- printf("\n\nI made it!\n"); }
/* SetFunction function Setup function. */ SUIMLIB_API int SetFunction(const int *S, const char *pchFuncName, CallBack pclCallBack) { if(S== NULL) return (ERR_S_NULL); int inFlag = IsNullOrEmpty(pchFuncName); if(inFlag!= 0) return (ERR_NAME); if(pclCallBack== NULL) return (ERR_S_NULL); int inLength = strlen(pchFuncName); if(inLength>= MAX_KEY_LENGTH - 1) return (ERR_SET_NAME); struct ST_SUIM *pS = (struct ST_SUIM *)S; int inErrCode = AddCallBack(pS, pchFuncName, pclCallBack); return (inErrCode); }