From 4174158dc75b5ed892b293b18b7dd5c85aa36f2f Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 5 Oct 2014 12:39:14 +0200 Subject: added void * userdata to initModule --- tests/modules/UserData.hpp | 9 +++++++++ tests/modules/test4.MUST | 2 +- tests/modules/test4.cpp | 6 +++++- tests/modules/testmod4/TestMod4.cpp | 12 ++++++++++-- 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 tests/modules/UserData.hpp (limited to 'tests') diff --git a/tests/modules/UserData.hpp b/tests/modules/UserData.hpp new file mode 100644 index 0000000..83b301d --- /dev/null +++ b/tests/modules/UserData.hpp @@ -0,0 +1,9 @@ +#ifndef _USER_DATA_INCLUDED +#define _USER_DATA_INCLUDED + +struct UserData { + int version; + string text; +}; + +#endif diff --git a/tests/modules/test4.MUST b/tests/modules/test4.MUST index a675dba..1d14a0c 100644 --- a/tests/modules/test4.MUST +++ b/tests/modules/test4.MUST @@ -1,5 +1,5 @@ Created common object -test4: Module 4 initModule called +test4: Module 4 initModule called with user data: 47 hello there test4: hello from main test4: hello world from module test4: Module 4 destroyModule called diff --git a/tests/modules/test4.cpp b/tests/modules/test4.cpp index 8e1bfbe..4e71295 100755 --- a/tests/modules/test4.cpp +++ b/tests/modules/test4.cpp @@ -1,6 +1,7 @@ #include "ModuleLoader.hpp" #include "Base.hpp" #include "Common.hpp" +#include "UserData.hpp" #include #include @@ -20,7 +21,10 @@ int main( void ) #else modules.push_back( ".\\testmod4\\mod_test4.dll" ); #endif - ModuleLoader loader( modules ); + UserData user_data; + user_data.version = 47; + user_data.text.assign( "hello there" ); + ModuleLoader loader( modules, (void *)&user_data ); Base *obj = loader.create( "testmod4" ); c.print( "hello from main" ); diff --git a/tests/modules/testmod4/TestMod4.cpp b/tests/modules/testmod4/TestMod4.cpp index cd0578e..de8b1b6 100755 --- a/tests/modules/testmod4/TestMod4.cpp +++ b/tests/modules/testmod4/TestMod4.cpp @@ -1,10 +1,12 @@ #include "TestMod4.hpp" #include "Common.hpp" +#include "UserData.hpp" #include #include #include +#include using namespace std; @@ -21,9 +23,15 @@ void Derived::hello( ) Common::instance( ).print( "hello world from module" ); } -static void initModule( ) +static void initModule( void *user_data ) { - Common::instance( ).print( "Module 4 initModule called" ); + UserData *data = (UserData *)user_data; + ostringstream ss; + + ss << "Module 4 initModule called with user data: " + << data->version << " " << data->text; + + Common::instance( ).print( ss.str( ) ); } static void destroyModule( ) -- cgit v1.2.3-54-g00ecf