fork download
  1. #include <node.h>
  2. #include <v8.h>
  3.  
  4. #ifdef _UNICODE
  5. #undef _UNICODE
  6. #endif
  7.  
  8. #include <windows.h>
  9. #include <stdio.h>
  10. #include <conio.h>
  11. #include <tchar.h>
  12. //#include <iostream>
  13.  
  14. v8::Local<v8::String> LpStrToV8(LPSTR str) {
  15. v8::HandleScope scope;
  16. v8::Local<v8::String> v8str;
  17.  
  18. v8str = v8::String::New(static_cast<char*>(str));
  19.  
  20. return scope.Close(v8str);
  21. }
  22.  
  23. v8::Handle<v8::Value> Method(const v8::Arguments& args){
  24. // v8::Isolate* isolate = v8::Isolate::GetCurrent();
  25. v8::HandleScope scope;
  26.  
  27. DWORD dwSizeNeeded;
  28. DWORD dwNumItems;
  29. LPPRINTER_INFO_2 lpInfo = NULL;
  30.  
  31. EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &dwSizeNeeded, &dwNumItems);
  32.  
  33. lpInfo = (LPPRINTER_INFO_2) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSizeNeeded);
  34. if(lpInfo == NULL)
  35. {
  36. return scope.Close(v8::String::New("{\"error\": \"Not enough memory to enumerate printers.\"}"));
  37. }
  38.  
  39. if(EnumPrintersW(PRINTER_ENUM_LOCAL, // what to enumerate
  40. NULL, // printer name (NULL for all)
  41. 2, // level
  42. (LPBYTE)lpInfo, // buffer
  43. dwSizeNeeded, // size of buffer
  44. &dwSizeNeeded, // returns size
  45. &dwNumItems // return num. items
  46. ) == 0)
  47. {
  48. return scope.Close(v8::String::New("{\"error\": \"EnumPrinters() failed.\"}"));
  49. }
  50.  
  51. v8::Handle<v8::Array> printerList = v8::Array::New(dwNumItems);
  52.  
  53. for(unsigned int i = 0; i < dwNumItems; i++)
  54. {
  55. v8::Handle<v8::Object> printer = v8::Object::New();
  56.  
  57. printer->Set(v8::String::New("printer"), LpStrToV8(lpInfo[i].pPrinterName));
  58. printer->Set(v8::String::New("port"), LpStrToV8(lpInfo[i].pPortName));
  59. printer->Set(v8::String::New("driver"), LpStrToV8(lpInfo[i].pDriverName));
  60. printer->Set(v8::String::New("comments"), LpStrToV8(lpInfo[i].pComment));
  61. printer->Set(v8::String::New("location"), LpStrToV8(lpInfo[i].pLocation));
  62.  
  63. printerList->Set(i, printer);
  64. }
  65.  
  66. // free memory
  67. HeapFree(GetProcessHeap(), 0, lpInfo);
  68.  
  69. return scope.Close(printerList);
  70. }
  71.  
  72. void init(v8::Handle<v8::Object> target){
  73. target->Set(v8::String::NewSymbol("getPrinters"),
  74. v8::FunctionTemplate::New(Method)->GetFunction()
  75. );
  76. }
  77. NODE_MODULE(printers, init)
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:18: error: node.h: No such file or directory
prog.cpp:2:16: error: v8.h: No such file or directory
prog.cpp:8:21: error: windows.h: No such file or directory
prog.cpp:10:19: error: conio.h: No such file or directory
prog.cpp:11:19: error: tchar.h: No such file or directory
prog.cpp:14: error: 'v8' has not been declared
prog.cpp:14: error: expected constructor, destructor, or type conversion before '<' token
prog.cpp:23: error: 'v8' has not been declared
prog.cpp:23: error: expected constructor, destructor, or type conversion before '<' token
stdout
Standard output is empty