waitingsong / node-win32-api

win32 api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

compatible with regular JavaScript?

gittyup2018 opened this issue · comments

Is this compatible with regular or plain JavaScript? or is there a plain JavaScript version? if so can you show an example because I'm not familiar with typescript, coffeescript, all the pointless JavaScript variations, etc. and I prefer normal / regular / original JavaScript.

Yes, it supports plan js.

  1. change import syntax to require()
  2. remove type def

simple example

import ref from 'ref-napi'
import { DModel as M } from 'win32-api'
import { Kernel32, User32 } from 'win32-api/promise'

const knl32 = Kernel32.load()
const user32 = User32.load()

const lpszClass = Buffer.from('guard64\0', 'ucs2')
const hInstanceBuffer = ref.alloc(W.HANDLE_PVOID)
const hInstanceAddr = ref.address(hInstanceBuffer)

await knl32.GetModuleHandleExW(0, lpszClass, hInstanceAddr)

to

const ref = require('ref-napi')
const { DModel as M } = require('win32-api')
const { Kernel32, User32  }  = require('win32-api/promise')  // <--- not sure this syntax

const knl32 = Kernel32.load()
const user32 = User32.load()

const lpszClass = Buffer.from('guard64\0', 'ucs2')
const hInstanceBuffer = ref.alloc(W.HANDLE_PVOID)
const hInstanceAddr = ref.address(hInstanceBuffer)

await knl32.GetModuleHandleExW(0, lpszClass, hInstanceAddr)
const point = StructFactory<M.POINT>(DS.POINT)
point.x = 100

to

const point = StructFactory(DS.POINT)
point.x = 100

Thanks for the quick reply!

I tried your code but I get the error:

App threw an error during load
ReferenceError: W is not defined

const hInstanceBuffer = ref.alloc(W.HANDLE_PVOID)

I don't know if makes a difference but I'm trying to use it to make an electron app,

Also I downloaded your repo (to try typescript version) and tried to run "npm run bootstrap" but it could not find lerna command.

And I'm not too familiar with Win32 API but would this module let me send text to Notepad? Can you show a SendMessage example? In regular javascript please

try :

import {
  DModel as M,
  DTypes as W,
  DStruct as DS,
} from 'win32-api'
// to
const {
  DModel as M,
  DTypes as W,
  DStruct as DS,
} = require('win32-api')

Also I downloaded your repo (to try typescript version) and tried to run "npm run bootstrap" but it could not find lerna command.

You can install lerna as global pkg

npm i -g lerna

const {
DModel as M,
DTypes as W,
DStruct as DS,
} = require('win32-api')

as syntax is not supported

This works though :)

const ref = require('ref-napi')
const { DModel,DTypes,DStruct} = require('win32-api')
//const {DModel as M, DTypes as W,DStruct as DS} = require('win32-api')

const M=DModel;
const W=DTypes;
const DS=DStruct;

const { Kernel32, User32 } = require('win32-api/promise')

const knl32 = Kernel32.load()
const user32 = User32.load()

const lpszClass = Buffer.from('guard64\0', 'ucs2')
const hInstanceBuffer = ref.alloc(W.HANDLE_PVOID)
const hInstanceAddr = ref.address(hInstanceBuffer)

async function main() {
await knl32.GetModuleHandleExW(0, lpszClass, hInstanceAddr);
}

Could you show me a send text to notepad example please?? that's all I really need to use this class for to hopefully replace AHK (autohotkey)I think it's the SendMessage (or PostMessage) API but not familiar with it.

see demo