node-win32-api
node-win32-api copied to clipboard
How to send WM_COPYDATA message with a string
With node-win32-api, I tried to send a WM_COPYDATA message to another win32 application with window, but it failed, the win32 application didn't receive the messsage. But when I send WM_QUIT and WM_COMMAND mesage, it worked very well
And when I used another win32 applciation to send the WM_COPYDATA message, it can received the message and the string
send WM_COPYDATA :
received the message:
Do you know how to send WM_COPYDATA with a string by node-win32-api? Or do you know is there any other method that I can send a string to another win32 application in NodeJS? Thank you in advance.
Is it working?
rest = user32.sendMessageW(hWnd, 74, 100, Buffer.from([100]))
// or
rest = user32.sendMessageW(hWnd, 74, 100, Buffer.from(['foo\0', 'ucs2']))
@waitingsong No ,they doesn't work.
Looks like the type of the argument is not correct
@TerryChan Would you like to provide the code.
Here is the code:
var { Kernel32, User32 } = require('win32-api')
// import * as ref from 'ref-napi'
const knl32 = Kernel32.load()
const user32 = User32.load() // load all apis defined in lib/{dll}/api from user32.dll
const title = 'WindowsDesktop\0' // null-terminated string
const lpszWindow = Buffer.from(title, 'ucs2')
const hWnd = user32.FindWindowExW(0, 0, null, lpszWindow)
if (typeof hWnd === 'number' && hWnd > 0
|| typeof hWnd === 'bigint' && hWnd > 0
|| typeof hWnd === 'string' && hWnd.length > 0
) {
console.log('window handle: ', hWnd)
// Send WM_QUIT message, success
// res = user32.SendMessageW(hWnd, 2, 0, 0)
// Send WM_COMMAND message, success
res = user32.SendMessageW(hWnd, 273, 1000, 3)
console.log('WM_COMMAND', res)
// send WM_COPYDATA (74) message, fail
res = user32.PostMessageW(hWnd, 74, 100, 100)
// rest = user32.SendMessageW(hWnd, 74, 100, Buffer.from([100]))
// rest = user32.SendMessageW(hWnd, 74, 100, Buffer.from(['foo\0', 'ucs2']))
// res = user32.PostMessageW(hWnd, 74, 100, 100)
console.log('WM_COPYDATA', res)
}
pls try this demo with version ^9.4.0
Is there any way to receive WM_COPYDATA?
browserWindow.hookWindowMessage(0x4A /* = WM_COPYDATA */, (wParam, lParam) => {
console.log('wParam = ', wParam);
console.log('lParam = ', lParam);
});
only sth like
wParam = <Buffer@0x0000018C305F7160 00 00 00 00 00 00 00 00>
lParam = <Buffer@0x0000018C305F6EC0 a0 f2 cf 42 8a 00 00 00>
How to get the data from WM_COPYDATA?
Is there any way to receive WM_COPYDATA?
browserWindow.hookWindowMessage(0x4A /* = WM_COPYDATA */, (wParam, lParam) => { console.log('wParam = ', wParam); console.log('lParam = ', lParam); });
only sth like
wParam = <Buffer@0x0000018C305F7160 00 00 00 00 00 00 00 00> lParam = <Buffer@0x0000018C305F6EC0 a0 f2 cf 42 8a 00 00 00>
How to get the data from WM_COPYDATA?
retrieveStructFromPtrAddress()
may help you: demo