Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SetWindowLong/GetWindowLong and 32-bit/64-bit CPUs

I'm using the following code:

const int GWL_STYLE = (-16);

const UInt32 WS_POPUP = 0x80000000;
const UInt32 WS_CHILD = 0x40000000;

[DllImport("user32.dll", SetLastError = true)]
static extern UInt32 GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, UInt32 dwNewLong);

and somewhere...

SetWindowLong(this.Handle, GWL_STYLE,
             ((GetWindowLong(this.Handle, GWL_STYLE) & ~(WS_POPUP)) | WS_CHILD));

Will this run properly on both 32-bit and 64-bit machines?

If not, if I compile my application to be ran as a x86 process, will it still work fine on a 64-bit machine?

And how can I rewrite the following code to be OK in both 32-bit and 64-bit machines?

like image 398
Żubrówka Avatar asked Feb 14 '12 18:02

Żubrówka


1 Answers

I guess you are wondering if you chose the type UInt32 correctly. The answer is yes. The docs explicitly say it is always 32 bit value: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633591(v=vs.85).aspx

Your code is correct.

like image 114
usr Avatar answered Oct 20 '22 13:10

usr