Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Improve Windows experience #119

Merged
merged 13 commits into from Mar 22, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 45 additions & 2 deletions binding.cc
Expand Up @@ -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
Expand Down Expand Up @@ -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)
33 changes: 29 additions & 4 deletions binding.gyp
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -3,7 +3,7 @@
*/

var EventEmitter = require('events').EventEmitter
, zmq = require('../build/Release/binding');
, zmq = require('../build/Release/zmq');

/**
* Expose bindings as the module.
Expand Down