Shoutbox

[?] Detect x64 through JScript & EM_SETSEL on x64 - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [?] Detect x64 through JScript & EM_SETSEL on x64 (/showthread.php?tid=93722)

[?] Detect x64 through JScript & EM_SETSEL on x64 by SmokingCookie on 01-31-2010 at 07:11 PM

Is it possible to detect whether MPL is running on a 64-bit version of Windows? I've tried conditional compilation, but @if(@_win32) seems to always return true, even on my x64 machine.

Second problem: EM_SETSEL does not set the selection to the specified start and stop indexes, but deselects all text. This seems to be an x64 problem (which is why I posted in the first place :P ). How can I solve this?


RE: [?] Detect x64 through JScript & EM_SETSEL on x64 by Mnjul on 01-31-2010 at 07:30 PM

Try IsWow64Process although I really don't think the EM_SETSEL thing has much to do with x64 :p


RE: [?] Detect x64 through JScript & EM_SETSEL on x64 by SmokingCookie on 01-31-2010 at 07:35 PM

I'll try have the IsWow64Process thingy.

About EM_SETSEL: I concluded it is an x64 problem after reading this: http://support.microsoft.com/kb/109550.


RE: [?] Detect x64 through JScript & EM_SETSEL on x64 by TheBlasphemer on 02-02-2010 at 12:03 PM

It's far more likely that it's a bug in how you use it than it being related to x64.
Messenger is a x86 (32-bit) program, and as such is run in a x86 enviroment with x86 APIs. x86 processes do not have access to x64 APIs, and as such EM_SETSEL would just take 32-bit parameters.
The article you mentioned is about 16-bit vs 32-bit, not about 32-bit to 64-bit, and on top of that it checks on-compile time, meaning that if you'd compile your app as 16-bit, it'd have used the 16-bit methods. Messenger is compiled as 32-bit, and as such should just use 32-bit APIs.
Furthermore, changing your programs behaviour on x64 windows even though you're a x86 process would only introduce weird bugs.

I'd suggest you read up on EM_SETSEL here and try to find out where you went wrong.
Also I suggest you test your script on a 32-bit machine, and I can almost assure you that the same bug will appear, as it's most definitely not related to your 64-bit OS ;)


RE: [?] Detect x64 through JScript & EM_SETSEL on x64 by SmokingCookie on 02-02-2010 at 07:39 PM

:wall: Gotta get some reading lessons :S

Anyways, I started at the MSDN article. I guess I'd post some code?

JScript code:
// Example
var Text = "Hello world!";
var pText = "Hello world";
 
var SetSel = function(Start,End) {
    Interop.Call("User32.dll","SendMessageW",hWnd,EM_SETSEL,Start,End);
}
 
(...)
 
SetSel(Text.length,pText.length);


NB: the hWnd parameter is known.
RE: [?] Detect x64 through JScript & EM_SETSEL on x64 by matty on 02-02-2010 at 08:35 PM

Just out of curiosity, I would have to test this myself but:

Javascript code:
SetSel(12, 11)

Is essentially what you are doing... I dont know what the ramifications of that are or how long the text in the edit control you are testing is.
RE: [?] Detect x64 through JScript & EM_SETSEL on x64 by SmokingCookie on 02-02-2010 at 08:40 PM

Well, I've put a longer string in the edit box and tried indexes 4 and 12 (and reversed), but it still doesn't work: no text is selected. The edit control is basically a combo box with the AllowEdit attribute set to true.

Btw, what does "ramifications" mean? :P


RE: [?] Detect x64 through JScript & EM_SETSEL on x64 by matty on 02-02-2010 at 08:46 PM

Ramifications: what sideeffects or what would happen by doing it.

Have you tried EM_GETSEL to see where the starting position is?

Stupid question but what do you have EM_SETSEL defined as? should be 0xB1

Is it an Edit or Rich Edit control? You cannot use that message for a control other than an edit or rich edit control.

quote:
Originally posted by http://msdn.microsoft.com/en-us/library/bb761661%28VS.85%29.aspx
EM_SETSEL

Selects a range of characters in an edit control. You can send this message to either an edit control or a rich edit control.

Look at the CB_SETEDITSEL message instead

wParam isn't used in this message. You will need to make a word consisting of the low and high bytes.

Javascript code:
var makeword = function (a,b) { return a | (b << 8); }

Where A is the LowByte and B is the HighByte.
RE: [?] Detect x64 through JScript & EM_SETSEL on x64 by SmokingCookie on 02-02-2010 at 08:53 PM

Well, I've double-checked the EM_SETSEL, it is properly defined. I've just tried EM_GETSEL, starting and ending positions are both 0.

And thanks for adding a new word to my vocab :P

Seen your bump, reading now

Seen :p


I've been messing around with those macros, but can barely read them, due to all those casts :S :P Thanks for making it clear now ;)

Well you got me at least one step further: now all text is selected, and I know why:

JScript code:
Number.prototype.LOWORD = function() {
    return this & 0xFFFF;
}
 
Number.prototype.HIWORD = function() {
    return (this >> 16) & 0xFFFF;
}
 
var MAKEWORD = function (a,b) {
    return a | (b << 8);
}
 
var D = MAKEWORD(4,12);
Debug.Trace((4).toString(2));
Debug.Trace((12).toString(2));
Debug.Trace(D.toString(2));
 
Debug.Trace(D.LOWORD());
Debug.Trace(D.HIWORD());


Output:

quote:
100
1100
110000000100
3076
0

RE: [?] Detect x64 through JScript & EM_SETSEL on x64 by TheBlasphemer on 02-02-2010 at 10:15 PM

quote:
Originally posted by SmokingCookie
Well, I've double-checked the EM_SETSEL, it is properly defined. I've just tried EM_GETSEL, starting and ending positions are both 0.

And thanks for adding a new word to my vocab :P

Seen your bump, reading now

Seen :p


I've been messing around with those macros, but can barely read them, due to all those casts :S :P Thanks for making it clear now ;)

Well you got me at least one step further: now all text is selected, and I know why:

JScript code:
Number.prototype.LOWORD = function() {
    return this & 0xFFFF;
}
 
Number.prototype.HIWORD = function() {
    return (this >> 16) & 0xFFFF;
}
 
var MAKEWORD = function (a,b) {
    return a | (b << 8);
}
 
var D = MAKEWORD(4,12);
Debug.Trace((4).toString(2));
Debug.Trace((12).toString(2));
Debug.Trace(D.toString(2));
 
Debug.Trace(D.LOWORD());
Debug.Trace(D.HIWORD());


Output:

Are you perhaps confusing MAKEWORD with MAKELONG ?
BYTE = 8-bit
WORD = 16-bit
DWORD/long = 32-bit

MAKEWORD takes two BYTEs and turns it into a WORD
MAKELONG takes two WORDs and turns it into a DWORD/LONG
LOWORD gets a WORD from a DWORD/LONG (first one passed to MAKELONG)
HIWORD " " " second one

I think in your code you intended to use MAKELONG instead of MAKEWORD, MAKELONG would be:
var MAKELONG = function(a,b) { return a|(b<<16); };
RE: [?] Detect x64 through JScript & EM_SETSEL on x64 by SmokingCookie on 02-03-2010 at 05:14 PM

Yes, the 16/8 thingy was indeed the problem. But it's pretty much solved now; thanks anyway.