Permalink
Browse files

Merge pull request #119 from mscdex/master

Improve Windows experience
  • Loading branch information...
2 parents 6f8237a + 954c444 commit 66fd2f6c4963ba846b9ec29861aa3f76c61c263e @ronkorving ronkorving committed Mar 22, 2013
View
@@ -34,7 +34,20 @@
#include <stdexcept>
#ifdef _WIN32
-#define snprintf _snprintf_s
+# define snprintf _snprintf_s
+ typedef BOOL (WINAPI* SetDllDirectoryFunc)(wchar_t *lpPathName);
+ class SetDllDirectoryCaller {
+ public:
+ explicit SetDllDirectoryCaller() : func_(NULL) { }
+ ~SetDllDirectoryCaller() {
+ if (func_)
+ func_(NULL);
+ }
+ // Sets the SetDllDirectory function pointer to activates this object.
+ void set_func(SetDllDirectoryFunc func) { func_ = func; }
+ private:
+ SetDllDirectoryFunc func_;
+ };
#endif
#define ZMQ_CAN_DISCONNECT (ZMQ_VERSION_MAJOR == 3 && ZMQ_VERSION_MINOR >= 2) || ZMQ_VERSION_MAJOR > 3
@@ -945,11 +958,41 @@ namespace zmq {
}
} // namespace zmq
+
// module
extern "C" void
init(Handle<Object> target) {
+#ifdef _MSC_VER
+ // On Windows, inject the windows/lib folder into the DLL search path so that
+ // it will pick up our bundled DLL in case we do not have zmq installed on
+ // this system.
+ HMODULE kernel32_dll = GetModuleHandleW(L"kernel32.dll");
+ SetDllDirectoryCaller caller;
+ SetDllDirectoryFunc set_dll_directory;
+ wchar_t path[MAX_PATH] = L"";
+ wchar_t pathDir[MAX_PATH] = L"";
+ if (kernel32_dll != NULL) {
+ set_dll_directory =
+ (SetDllDirectoryFunc)GetProcAddress(kernel32_dll, "SetDllDirectoryW");
+ if (set_dll_directory) {
+ GetModuleFileNameW(GetModuleHandleW(L"zmq.node"), path, MAX_PATH - 1);
+ wcsncpy(pathDir, path, wcsrchr(path, '\\') - path);
+ path[0] = '\0';
+ pathDir[wcslen(pathDir)] = '\0';
+# ifdef _WIN64
+ wcscat(pathDir, L"\\..\\..\\windows\\lib\\x64");
+# else
+ wcscat(pathDir, L"\\..\\..\\windows\\lib\\x86");
+# endif
+ _wfullpath(path, pathDir, MAX_PATH);
+ set_dll_directory(path);
+ caller.set_func(set_dll_directory);
+ LoadLibrary("libzmq-v100-mt-3_2_2");
+ }
+ }
+#endif
zmq::Initialize(target);
}
-NODE_MODULE(binding, init)
+NODE_MODULE(zmq, init)
View
@@ -1,12 +1,37 @@
{
'targets': [
{
- 'target_name': 'binding',
+ 'target_name': 'zmq',
'sources': [ 'binding.cc' ],
- 'libraries': ['-lzmq'],
- 'cflags!': ['-fno-exceptions'],
- 'cflags_cc!': ['-fno-exceptions'],
'conditions': [
+ ['OS=="win"', {
+ 'include_dirs': ['windows/include'],
+ 'link_settings': {
+ 'libraries': [
+ 'Delayimp.lib',
+ ],
+ 'conditions': [
+ ['target_arch=="ia32"', {
+ 'libraries': [
+ '<(PRODUCT_DIR)/../../windows/lib/x86/libzmq-v100-mt-3_2_2.lib',
+ ]
+ },{
+ 'libraries': [
+ '<(PRODUCT_DIR)/../../windows/lib/x64/libzmq-v100-mt-3_2_2.lib',
+ ]
+ }]
+ ],
+ },
+ 'msvs_settings': {
+ 'VCLinkerTool': {
+ 'DelayLoadDLLs': ['libzmq-v100-mt-3_2_2.dll']
+ }
+ },
+ }, {
+ 'libraries': ['-lzmq'],
+ 'cflags!': ['-fno-exceptions'],
+ 'cflags_cc!': ['-fno-exceptions'],
+ }],
['OS=="mac"', {
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
View
@@ -3,7 +3,7 @@
*/
var EventEmitter = require('events').EventEmitter
- , zmq = require('../build/Release/binding');
+ , zmq = require('../build/Release/zmq');
/**
* Expose bindings as the module.
Oops, something went wrong.

0 comments on commit 66fd2f6

Please sign in to comment.