Calling DLL functions with CDECL callback function parameters

Knowledge Base Article # Q200179

Read Prior Article Read Next Article
Summary How to call a DLL and pass in a CDECL type ATEasy function as a parameter
ATEasy can interface with DLL functions that accept call back function pointers as parameters.
When dealing with function pointers, you should keep in mind that there are two types of x86 calling convention, CDECL and STDCALL.

CDECL –The caller will clean up the stack when the function returns.
STDCALL – The called function will clean up the stack when it returns.

If the two calling conventions are missmatched (between the DLL’s function pointer parameter declaration and the passed in parameter’s function declaration), the stack could become corrupted resulting in an ATEasy run-time error.

By default ATEasy will pass in a STDCALL function pointer that wraps around the native ATEasy procedure. This behavior can be changed to CDECL by changing certain options in the procedure’s properties page.

First, you must create the procedure in either the System module or in a Driver module.

Then you must set the procedure’s properties such that the export checkbox is set and CDECL is selected from the drop down menu. Once these properties have been set, the procedure can be passed into the DLL function.

Calling DLL functions with CDECL callback function parameters

Note: Make sure your procedure's prototype is equivalent to the function pointer prototype of the DLL function's callback parameter.
Article Date 12/21/2009 5:13:31 PM
Keywords ATEasy, CDECL, call back, function, procedure

0 ratings | 0 out of 5
Read Prior Article Read Next Article