Created
October 5, 2012 21:55
-
-
Save springmeyer/3842653 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: include/mapnik/datasource_cache.hpp | |
=================================================================== | |
--- include/mapnik/datasource_cache.hpp (revision 2515) | |
+++ include/mapnik/datasource_cache.hpp (working copy) | |
@@ -47,7 +47,7 @@ | |
datasource_cache& operator=(const datasource_cache&); | |
static std::map<std::string,boost::shared_ptr<PluginInfo> > plugins_; | |
static bool registered_; | |
- static bool insert(const std::string& name,const lt_dlhandle module); | |
+ static bool insert(const std::string& name, const TDynamicLibraryHandle module); | |
public: | |
static std::vector<std::string> plugin_names (); | |
static void register_datasources(const std::string& path); | |
Index: include/mapnik/plugin.hpp | |
=================================================================== | |
--- include/mapnik/plugin.hpp (revision 2515) | |
+++ include/mapnik/plugin.hpp (working copy) | |
@@ -28,8 +28,23 @@ | |
#include <boost/utility.hpp> | |
// stl | |
#include <string> | |
-// ltdl | |
+ | |
+#ifdef _WIN32 | |
+#include <windows.h> | |
+#include <tchar.h> | |
+typedef HINSTANCE TDynamicLibraryHandle; | |
+#define lt_dlopen ::LoadLibrary | |
+#define lt_dlclose ::FreeLibrary | |
+#define lt_dlsym ::GetProcAddress | |
+#define lt_dlerror() GetWinError() | |
+#define lt_dlexit() (void)0 | |
+#define lt_dlinit() (void)0 | |
+std::string GetWinError(); | |
+#else | |
+// On all other platforms, use ltdl | |
#include <ltdl.h> | |
+typedef lt_dlhandle TDynamicLibraryHandle; | |
+#endif | |
namespace mapnik | |
{ | |
@@ -37,12 +52,12 @@ | |
{ | |
private: | |
std::string name_; | |
- lt_dlhandle module_; | |
+ TDynamicLibraryHandle module_; | |
public: | |
- PluginInfo (const std::string& name,const lt_dlhandle module); | |
+ PluginInfo (const std::string& name,const TDynamicLibraryHandle module); | |
~PluginInfo(); | |
const std::string& name() const; | |
- lt_dlhandle handle() const; | |
+ TDynamicLibraryHandle handle() const; | |
}; | |
} | |
Index: src/datasource_cache.cpp | |
=================================================================== | |
--- src/datasource_cache.cpp (revision 2515) | |
+++ src/datasource_cache.cpp (working copy) | |
@@ -32,7 +32,7 @@ | |
#include <boost/algorithm/string.hpp> | |
// ltdl | |
-#include <ltdl.h> | |
+#include <mapnik/plugin.hpp> | |
// stl | |
#include <algorithm> | |
@@ -108,7 +108,7 @@ | |
return ds; | |
} | |
- bool datasource_cache::insert(const std::string& type,const lt_dlhandle module) | |
+ bool datasource_cache::insert(const std::string& type, const TDynamicLibraryHandle module) | |
{ | |
return plugins_.insert(make_pair(type,boost::shared_ptr<PluginInfo> | |
(new PluginInfo(type,module)))).second; | |
@@ -149,7 +149,7 @@ | |
{ | |
try | |
{ | |
- lt_dlhandle module=lt_dlopen(itr->string().c_str()); | |
+ TDynamicLibraryHandle module=lt_dlopen(itr->string().c_str()); | |
if (module) | |
{ | |
datasource_name* ds_name = | |
Index: src/plugin.cpp | |
=================================================================== | |
--- src/plugin.cpp (revision 2515) | |
+++ src/plugin.cpp (working copy) | |
@@ -23,12 +23,11 @@ | |
//$Id: plugin.cpp 17 2005-03-08 23:58:43Z pavlenko $ | |
#include <mapnik/plugin.hpp> | |
-#include <ltdl.h> | |
namespace mapnik | |
{ | |
- PluginInfo::PluginInfo (const std::string& name,const lt_dlhandle module) | |
+ PluginInfo::PluginInfo (const std::string& name, const TDynamicLibraryHandle module) | |
:name_(name),module_(module) {} | |
PluginInfo::~PluginInfo() | |
@@ -44,9 +43,35 @@ | |
return name_; | |
} | |
- lt_dlhandle PluginInfo::handle() const | |
+ TDynamicLibraryHandle PluginInfo::handle() const | |
{ | |
return module_; | |
} | |
} | |
+ | |
+#ifdef _WIN32 | |
+/* | |
+ * This function assumes a Multi-Byte Character Set build environment. | |
+ * For a unicode build, some additional wcstombs() may be necessary. | |
+ */ | |
+std::string GetWinError() | |
+{ | |
+ LPTSTR s; | |
+ if(!::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, | |
+ NULL, ::GetLastError(), 0, (LPTSTR)&s, 0, NULL)) | |
+ { | |
+ /* Unknown error code. */ | |
+ return "Unknown error."; | |
+ } else { | |
+ /* FormatMessage adds a newline for no good reason, strip it out. */ | |
+ LPTSTR p = _tcschr(s, _T('\r')); | |
+ if(p != NULL) { | |
+ *p = _T('\0'); | |
+ } | |
+ std::string result(s); | |
+ ::LocalFree(s); | |
+ return result; | |
+ } | |
+} | |
+#endif // _WIN32 | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment