# Automatic wrapper functions

Path: /sdk/add_on/autowrapper/aswrappedcall.h

This header file declares some macros and template functions that will let the application developer automatically generate wrapper functions using the generic calling convention with a simple call to a preprocessor macro. This is useful for those platforms where the native calling conventions are not yet supported.

The macros are defined as

    #define asDECLARE_FUNCTION_WRAPPER(wrapper_name,func)
    #define asDECLARE_FUNCTION_WRAPPERPR(wrapper_name,func,params,rettype)
    #define asDECLARE_METHOD_WRAPPER(wrapper_name,cl,func)
    #define asDECLARE_METHOD_WRAPPERPR(wrapper_name,cl,func,params,rettype)

where wrapper_name is the name of the function that you want to generate, and func is a function pointer to the function you want to wrap, cl is the class name, params is the parameter list, and rettype is the return type.

Unfortunately the template functions needed to perform this generation are quite complex and older compilers may not be able to handle them. One such example is Microsoft Visual C++ 6, though luckily it has no need for them as AngelScript already supports native calling conventions for it.

## Example usage

    #include "aswrappedcall.h"

    // The application function that we want to register
    void DoSomething(std::string param1, int param2);

    // Generate the wrapper for the function
    asDECLARE_FUNCTION_WRAPPER(DoSomething_Generic, DoSomething);

    // Registering the wrapper with AngelScript
    void RegisterWrapper(asIScriptEngine *engine)
    {
      int r;

      r = engine->RegisterGlobalFunction("void DoSomething(string, int)", asFUNCTION(DoSomething_Generic), asCALL_GENERIC); assert( r >= 0 );
    }