PDA

View Full Version : HinstancePtr vs Hwnd?



johnywhy
07-21-2021, 12:22 PM
How are they different?

In Excel 2016:

?Application.Hwnd
67444
https://docs.microsoft.com/en-us/office/vba/api/excel.application.hwnd

?Application.HinstancePtr
140700483846144
https://docs.microsoft.com/en-us/office/vba/api/excel.application.hinstanceptr

?Application.Hinstance
"Automation error
Catastrophic failure"
https://docs.microsoft.com/en-us/office/vba/api/excel.application.hinstance

Paul_Hossler
07-21-2021, 03:09 PM
1. HInstance / HInstancePt --


Returns a handle to the instance of Excel represented by the Application object. Read-only Long.


This property returns a correct handle only in the 32-bit version of Excel. In Excel, the HinstancePtr (https://docs.microsoft.com/en-us/office/vba/api/excel.application.hinstanceptr) property was introduced, which works correctly in both 32-bit and 64-bit versions of Excel.




2. Hwnd --


Returns a Long indicating the top-level window handle of the Microsoft Excel window. Read-only.




Basically I believe that the first is the handle of the application that was started by the O/S and which you see in ask Manager, and the second is the window and replated items that you see on the screen.





Over simplified, but Task Manager closed the first, and Minimize, etc. changes the second (or so I think

SamT
07-21-2021, 06:09 PM
Bump to myself

johnywhy
07-22-2021, 12:38 PM
Bump to myself
@SamT, what does it mean to bump to yourself?
Also, you forgot a comma in your signature. :)

johnywhy
07-22-2021, 12:43 PM
1. HInstance / HInstancePt -- the instance of Excel started by the O/S, represented by the Application object.

2. Hwnd -- the top-level window of Excel and replated items


Great answer!

Questions:


Started by the O/S? You mean started by the user? What if started by VBA? Does it matter what started it?
"replated"?


thx

Paul_Hossler
07-22-2021, 02:27 PM
A1 - Probably doesn't matter what started it: User, CreateObject, etc.

A2 - related