main.h

Go to the documentation of this file.
00001 
00008 /*
00009     This library is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU Lesser General Public
00011     License as published by the Free Software Foundation; either
00012     version 2.1 of the License, or (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public
00020     License along with this library; if not, write to the Free Software
00021     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 */
00023 
00024 #ifndef OMGUI_MAIN_H
00025 #define OMGUI_MAIN_H
00026 
00027 #include <omgui/app.h>
00028 #include <omgui/dllimpexp.h>
00029 
00030 #ifdef OMGUI_WIN32
00031 #include <windows.h>
00032 #endif
00033 
00034 namespace omgui {
00035 
00040 omgui::App *main(const omgui::App::cmd_line &cmd);
00041 typedef omgui::App *(main_ptr)(const omgui::App::cmd_line &);
00042 
00043 // win32 has a different entry function, and omgui::entry function than other ports
00044 #ifdef OMGUI_WIN32
00045     int OMGUI_API entry(main_ptr, HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
00046 #else // !OMGUI_WIN32
00047     int OMGUI_API entry(main_ptr, int argc, char *argv[]);
00048 #endif // OMGUI_WIN32
00049 
00050 } // omgui
00051 
00052 // platform specific entry function
00053 // only include this part in user applications
00054 
00055 /*
00056 Explanation for the following code:
00057 
00058   The plan is to avoid requiring an IMPLEMENT_APP macro which declares the entry functions.
00059   Instead of the macro, omgui uses omgui::main() as an applications
00060   first entry point. omgui::main() is expected to create a omgui::App derivative and give that
00061   object to omgui. This omgui::App object is the actual application, and all further code execution
00062   is routed through this class.
00063 
00064   Because win32 dll's are not capable of calling a function defined in an application dll and prototyped
00065   in the dll headers, I cannot put the entry functions into the omgui library itself. To work around this
00066   restriction, I declare and implement them here, heavily if guarded. I realize this file could be included
00067   in two different source files, which causes multiply defined sybmols, but that is the fault of the programmer
00068   as this file is only required to be included once.
00069 
00070   The purpose of omgui::entry is to avoid implementing more code than is neccessary in this header file,
00071   allowing for at least slight binary compatability between changes so long as this header file is not modified.
00072   entry will call app->init(), and app->run() to actually run the application.
00073 
00074   omgui::entry is given a pointer to the omgui::main() function, as well as native entry function arguments.
00075 */
00076 #if !defined(OMGUI_ENTRY_IMPLEMENTED) && !defined(OMGUI_BUILDING)
00077 #define OMGUI_ENTRY_IMPLEMENTED
00078 
00079 #ifdef OMGUI_WIN32
00080     int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
00081     {
00082         return omgui::entry(omgui::main, hInstance, hPrevInstance, lpCmdLine, nCmdShow);
00083     }
00084 #else // !OMGUI_WIN32
00085     int main(int argc, char *argv[])
00086     {
00087         return omgui::entry(omgui::main, argc, argv);
00088     }
00089 #endif // OMGUI_WIN32
00090 
00091 #endif // !defined(OMGUI_ENTRY_IMPLEMENTED) && !defined(OMGUI_BUILDING)
00092 
00093 #endif // OMGUI_MAIN_H

doxygen SourceForge.net Logo