Reputation: 179
I need to obtain the handle of Excel 2016 64bit.
But Application.Hwnd
returns a long , and there is no Application.HwndPtr
.
Is it reliable?
If it's reliable, why Microsoft add Application.HInstancePtr
instead of use the old Application.HInstance
on 64bit platforms?
Is it possible for a window handle larger than 32bit?
Upvotes: 1
Views: 450
Reputation: 941635
It is fine, the OS ensures that a window handle can never overflow a 32-bit value. You can never have more than 65535 windows on a desktop so it is quite easy to do. That it works this way is something you can see in COM interop declaration for a remotable window handle, visible in the WTypes.idl SDK file:
typedef union _RemotableHandle switch( long fContext ) u
{
case WDT_INPROC_CALL: long hInproc;
case WDT_REMOTE_CALL: long hRemote;
} RemotableHandle;
typedef [unique] RemotableHandle * wireHWND;
typedef [unique] RemotableHandle * wireHMENU;
// etc..
Note how it is long
for an out-of-process call, a 32-bit value.
A HINSTANCE is a very different kind of handle, a kernel handle, it certainly is 64-bit value under the hood. Equal to the base address in memory of the module, so they were forced to add this property.
Upvotes: 3