Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compatible with regular JavaScript? #38

Open
gittyup2018 opened this issue Jul 13, 2022 · 7 comments
Open

compatible with regular JavaScript? #38

gittyup2018 opened this issue Jul 13, 2022 · 7 comments

Comments

@gittyup2018
Copy link

gittyup2018 commented Jul 13, 2022

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.

@gittyup2018 gittyup2018 changed the title normal Javascript? regular Javascript? Jul 13, 2022
@gittyup2018 gittyup2018 changed the title regular Javascript? compatible with regular JavaScript? Jul 13, 2022
@waitingsong
Copy link
Owner

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)

@waitingsong
Copy link
Owner

const point = StructFactory<M.POINT>(DS.POINT)
point.x = 100

to

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

@gittyup2018
Copy link
Author

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

@waitingsong
Copy link
Owner

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')

@waitingsong
Copy link
Owner

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

@gittyup2018
Copy link
Author

gittyup2018 commented Jul 15, 2022

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.

@waitingsong
Copy link
Owner

see demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants