如何从node-ffi调用函数EnumPrinters?

时间:2014-01-27 09:52:23

标签: javascript node.js printing node-ffi

根据MSDN,函数EnumPrinters是Winspool库的一部分:
图书馆 - Winspool.lib
DLL - Winspool.drv
http://msdn.microsoft.com/en-us/library/windows/desktop/dd162692(v=vs.85).aspx

但是没有Winspool.dll。

我尝试使用以下代码在javascript中创建库:

var lib_test = new FFI.Library('Winspool', {
   'EnumPrinters': [ 'bool', [ ] ]
});

但出现以下错误:

D:\print\ffi\node_modules\ffi\lib\dynamic_library.js:74
    throw new Error('Dynamic Linking Error: ' + err)
          ^
Error: Dynamic Linking Error: "Winspool.dll": The specified module could not be found.
    at new DynamicLibrary (D:\print\ffi\node_modules\ffi\lib\dynamic_library.js:74:11)

1 个答案:

答案 0 :(得分:0)

也许尝试像这样指定winspool的完整路径

MyApp::Application.configure do
  config.action_mailer.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/spec/mailer_previews" : nil
  config.autoload_paths += [config.action_mailer.preview_path]

  routes.append do
    get '/rails/mailers'         => "rails/mailers#index"
    get '/rails/mailers/*path'   => "rails/mailers#preview"
  end
end

class ::Rails::MailersController
  before_filter :authenticate_admin!
  def local_request?
    true
  end
  private
  def authenticate_admin!
    ...
  end
end

您可能需要将winspool.drv重命名为winspool.dll。