-
Notifications
You must be signed in to change notification settings - Fork 142
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 can i convert decimal value to pointer of hWnd #96
Comments
Did you ever figure this out? I also need to do this - I need to send the window handle to another process....obviously I can't send the buffer, because it crashes, so I get the raw address value via ref.address(hWnd), but then how to I convert it back to a usable Buffer object in the target process? |
@repl-chris |
Well, I've come up with something that works... private static bufferAtAddress(address: number): Buffer {
if (address > Number.MAX_SAFE_INTEGER) {
throw new Error('Address too high!');
}
const buff = new Buffer(8);
buff.writeUInt32LE(address % 0x100000000, 0);
buff.writeUInt32LE(Math.trunc(address / 0x100000000), 4);
(buff as any).type = { ...ref.types.void, indirection: 2 };
return ref.deref(buff);
} It's not ideal. I'm convinced there must be a more proper way to do this, but I can't find it. This will only work reliably for addresses <= Number.MAX_SAFE_INTEGER, so it's not a great solution for any random 64-bit address...to make it proper you can't ever call ref.address() (because a javascript number doesn't have the precision to hold any random 64bit address).....and instead use only ref.hexAddress() and then convert this method to use something like bignum. HOWEVER, that limitation probably doesn't apply to you, if you're just using it for win32 handles, like I am....because according to MSDN even on 64 bit windows all handles only contain 32-bits of significant data, so you're guaranteed they'll always be < Number.MAX_SAFE_INTEGER, so this should work just fine.
|
How can i convert number to the typeof HANDLE ?
thanks
The text was updated successfully, but these errors were encountered: