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

How to send WM_COPYDATA message with a string #25

Open
TerryChan opened this issue Apr 2, 2020 · 7 comments
Open

How to send WM_COPYDATA message with a string #25

TerryChan opened this issue Apr 2, 2020 · 7 comments

Comments

@TerryChan
Copy link

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
image

And when I used another win32 applciation to send the WM_COPYDATA message, it can received the message and the string
send WM_COPYDATA :
image
received the message:
image

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.

@waitingsong
Copy link
Owner

Is it working?

rest = user32.sendMessageW(hWnd, 74, 100, Buffer.from([100]))
// or
rest = user32.sendMessageW(hWnd, 74, 100, Buffer.from(['foo\0', 'ucs2']))

@TerryChan
Copy link
Author

@waitingsong No ,they doesn't work.
image
Looks like the type of the argument is not correct

@waitingsong
Copy link
Owner

@TerryChan Would you like to provide the code.

@TerryChan
Copy link
Author

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

@waitingsong
Copy link
Owner

pls try this demo with version ^9.4.0

@scil
Copy link

scil commented May 5, 2021

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?

@waitingsong
Copy link
Owner

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

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

3 participants