guifunc.cpp

Go to the documentation of this file.
00001 
00009 #include <cstdlib> // for getenv
00010 
00011 #include "dynload.h"
00012 
00013 
00021 int (* GetGuiFunc(LIBHANDLE* pGuiLibHandle))(int, char**)
00022 {
00023 #ifdef LINUX
00024   *pGuiLibHandle = NULL;
00025 
00026   // Check for environnement variable DISPLAY
00027   if (!getenv("DISPLAY"))
00028     {
00029       return NULL;
00030     }
00031 
00032   // Check for X11
00033   void *X11handle = LoadLibrary("libX11.so");
00034   if (!X11handle)
00035     {
00036       return NULL;
00037     }
00038 
00039   void* (*XOpenDisplayFunc)(char *) =
00040     (void* (*)(char *)) GetProcAddress(X11handle, "XOpenDisplay");
00041   void (*XCloseDisplayFunc)(void *) =
00042     (void (*)(void *)) GetProcAddress(X11handle, "XCloseDisplay");
00043 
00044   if (!XOpenDisplayFunc || !XCloseDisplayFunc)
00045     {
00046       FreeLibrary(X11handle);
00047       return NULL;
00048     }
00049 
00050   // Check for connection to X server
00051   void *pDisplay = XOpenDisplayFunc(NULL);
00052   if (!pDisplay)
00053     {
00054       FreeLibrary(X11handle);
00055       return NULL;
00056     }
00057 
00058   XCloseDisplayFunc(pDisplay);
00059   FreeLibrary(X11handle);
00060 
00061   char libstring[] = "./libraygui.so.1";
00062 
00063 #elif defined WIN32
00064 
00065   char libstring[] = "./gui.dll";
00066 
00067 #else
00068 #error OS not supported
00069 #endif
00070 
00071   // Try to load the GUI lib
00072   int (*guifunc)(int, char**);
00073 
00074   *pGuiLibHandle = LoadLibrary(libstring);
00075   if (!*pGuiLibHandle)
00076     {
00077       return NULL;
00078     }
00079 
00080   guifunc = (int (*)(int, char **)) GetProcAddress(*pGuiLibHandle, "StartGui");
00081   if (guifunc == NULL)
00082     {
00083       FreeLibrary(*pGuiLibHandle);
00084       *pGuiLibHandle = NULL;
00085     }
00086 
00087   return guifunc;
00088 }

Generated on Fri Dec 5 03:20:33 2008 for Mathematical Ray-tracer by  doxygen 1.5.4