Home > Back-end >  According to the window handle failed to get the application instance handle
According to the window handle failed to get the application instance handle

Time:05-05

As title, calling GetWindowLongPtr (hWnd, GWLP_HINSTANCE) returns 0, general get error code GetLastError, unexpectedly is 0, the complete code is as follows:
 
#include
#include

using namespace std;

Void testGetInstance ()
{
Const char * className="TaskSwitcherWnd";
Const char * windName="task switching";
HWND HWND=FindWindow (className, windName);
Cout & lt; <"Window handle" & lt; Uint64_t tempHandle=GetWindowLongPtr (hWnd GWLP_HWNDPARENT);
HWND hpWnd=* * (HWND) (& amp; TempHandle);
Cout & lt; <"The parent window handle (from GetWindowLongPtr) :" & lt; HpWnd=GetParent (hWnd);
Cout & lt; <"The parent window handle (from GetParent) :" & lt; TempHandle=GetWindowLongPtr (hWnd GWLP_HINSTANCE);
If (tempHandle==0)
{
DWORD errorCode=GetLastError ();
Cout & lt; <"Get the instance handle the error:" & lt; }
The else
{
(HINSTANCE HINSTANCE hInst=* *) (& amp; TempHandle);
Cout & lt; <"The instance handle:" & lt; }
}

Int main (int arg c, char * * argv)
{
TestGetInstance ();
}

There is a problem, it is call GetParent (hWnd); And GetWindowLongPtr (hWnd, GWLP_HWNDPARENT); Obtain the handle to the parent window with Visual Studio 2017 of Spy++ tools see,
The great god, please advice, thank you!
  • Related