Plugin_win.cpp
Go to the documentation of this file.
00001 /*
00002  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
00003  *
00004  * Copyright 2007-2012 VTT Technical Research Centre of Finland
00005  *
00006  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
00007  *          <http://www.vtt.fi/multimedia/alvar.html>
00008  *
00009  * ALVAR is free software; you can redistribute it and/or modify it under the
00010  * terms of the GNU Lesser General Public License as published by the Free
00011  * Software Foundation; either version 2.1 of the License, or (at your option)
00012  * any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful, but WITHOUT
00015  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00016  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00017  * for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public License
00020  * along with ALVAR; if not, see
00021  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
00022  */
00023 
00024 #include "Plugin_private.h"
00025 
00026 #include "AlvarException.h"
00027 
00028 #include <windows.h>
00029 #include <sstream>
00030 
00031 namespace alvar {
00032 
00033 class PluginPrivateData
00034 {
00035 public:
00036     PluginPrivateData()
00037         : mHandle(NULL)
00038     {
00039     }
00040     
00041     HINSTANCE mHandle;
00042 };
00043 
00044 PluginPrivate::PluginPrivate()
00045     : d(new PluginPrivateData())
00046 {
00047 }
00048 
00049 PluginPrivate::~PluginPrivate()
00050 {
00051     delete d;
00052 }
00053 
00054 void PluginPrivate::load(const std::string filename)
00055 {
00056     d->mHandle = LoadLibrary(filename.data());
00057     if (!d->mHandle) {
00058         std::stringstream message;
00059         message << "could not load " << filename
00060                 << ", error code " << GetLastError();
00061         throw AlvarException(message.str().data());
00062     }
00063 }
00064 
00065 void PluginPrivate::unload()
00066 {
00067     FreeLibrary(d->mHandle);
00068 }
00069 
00070 void *PluginPrivate::resolve(const char *symbol)
00071 {
00072     void *address = (void *)GetProcAddress(d->mHandle, symbol);
00073     if (!address) {
00074         std::stringstream message;
00075         message << "could not resolve " << symbol;
00076         throw AlvarException(message.str().data());
00077     }
00078     return address;
00079 }
00080 
00081 } // namespace alvar


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Thu Feb 16 2017 03:23:02