Index: code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h
===================================================================
--- code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h	(revision 10475)
+++ code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h	(revision 10476)
@@ -37,47 +37,66 @@
 #include "NetworkFunction.h"
 #include "NetworkFunctionManager.h"
+#include "core/module/StaticallyInitializedInstance.h"
+
+#define registerStaticNetworkFunction( functionPointer ) \
+    static orxonox::NetworkFunctionBase& BOOST_PP_CAT( NETWORK_FUNCTION_, __UNIQUE_NUMBER__ ) \
+        = (new orxonox::SI_NF(orxonox::registerStaticNetworkFunctionFct( functionPointer, #functionPointer )))->getFunction()
+
+#define registerMemberNetworkFunction( class, function ) \
+    static orxonox::NetworkFunctionBase& BOOST_PP_CAT( NETWORK_FUNCTION_##class, __UNIQUE_NUMBER__ ) \
+        = (new orxonox::SI_NF(orxonox::registerMemberNetworkFunctionFct<class>( &class::function, #class "_" #function)))->getFunction()
+
+// call it with functionPointer, clientID, args
+#define callStaticNetworkFunction( functionPointer, ...) \
+    { \
+        NetworkFunctionPointer p1; \
+        copyPtr( functionPointer, p1 ); \
+        FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunctionByFunctionPointer(p1)->getNetworkID(), OBJECTID_UNKNOWN, __VA_ARGS__); \
+    }
+
+// call it with class, function, objectID, clientID, args
+#define callMemberNetworkFunction( class, function, objectID, ...) \
+    { \
+        NetworkFunctionPointer p1; \
+        copyPtr( &class::function, p1 ); \
+        FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunctionByFunctionPointer(p1)->getNetworkID(), objectID, __VA_ARGS__); \
+    }
 
 namespace orxonox
 {
-    #define registerStaticNetworkFunction( functionPointer ) \
-        static void* BOOST_PP_CAT( NETWORK_FUNCTION_, __UNIQUE_NUMBER__ ) = registerStaticNetworkFunctionFct( functionPointer, #functionPointer );
+    class _CoreExport StaticallyInitializedNetworkFunction : public StaticallyInitializedInstance
+    {
+        public:
+            StaticallyInitializedNetworkFunction(NetworkFunctionBase* function) : function_(function) {}
 
-    #define registerMemberNetworkFunction( class, function ) \
-        static void* BOOST_PP_CAT( NETWORK_FUNCTION_##class, __UNIQUE_NUMBER__ ) = registerMemberNetworkFunctionFct<class>( &class::function, #class "_" #function);
+            virtual void load()
+                { NetworkFunctionManager::getInstance().registerFunction(this->function_); }
+            virtual void unload()
+                { NetworkFunctionManager::getInstance().unregisterFunction(this->function_); }
 
-    // call it with functionPointer, clientID, args
-    #define callStaticNetworkFunction( functionPointer, ...) \
-        { \
-            NetworkFunctionPointer p1; \
-            copyPtr( functionPointer, p1 ); \
-            FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunctionByFunctionPointer(p1)->getNetworkID(), OBJECTID_UNKNOWN, __VA_ARGS__); \
-        }
+            inline NetworkFunctionBase& getFunction()
+                { return *this->function_; }
 
-    // call it with class, function, objectID, clientID, args
-    #define callMemberNetworkFunction( class, function, objectID, ...) \
-        { \
-            NetworkFunctionPointer p1; \
-            copyPtr( &class::function, p1 ); \
-            FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunctionByFunctionPointer(p1)->getNetworkID(), objectID, __VA_ARGS__); \
-        }
+        private:
+            NetworkFunctionBase* function_;
+    };
 
-    template<class T> inline void* registerStaticNetworkFunctionFct( T ptr, const std::string& name )
+    typedef StaticallyInitializedNetworkFunction SI_NF;
+
+    template<class T> inline NetworkFunctionBase* registerStaticNetworkFunctionFct( T ptr, const std::string& name )
     {
         BOOST_STATIC_ASSERT( sizeof(T)<=sizeof(NetworkFunctionPointer) ); // if this fails your compiler uses bigger pointers for static functions than defined above
         NetworkFunctionPointer destptr;
         copyPtr( ptr, destptr );
-        new NetworkFunctionStatic( createFunctor(ptr), name, destptr );
-        return 0;
+        return new NetworkFunctionStatic( createFunctor(ptr), name, destptr );
     }
 
-    template<class T, class PT> inline void* registerMemberNetworkFunctionFct( PT ptr, const std::string& name )
+    template<class T, class PT> inline NetworkFunctionBase* registerMemberNetworkFunctionFct( PT ptr, const std::string& name )
     {
         BOOST_STATIC_ASSERT( sizeof(PT)<=sizeof(NetworkFunctionPointer) ); // if this fails your compiler uses bigger pointers for a specific kind of member functions than defined above
         NetworkFunctionPointer destptr;
         copyPtr( ptr, destptr );
-        new NetworkMemberFunction<T>( createFunctor(ptr), name, destptr );
-        return 0;
+        return new NetworkMemberFunction<T>( createFunctor(ptr), name, destptr );
     }
-
 }
 
