Trying to Display HWND as String
-
I am a beginner. I am trying to display the HWND when i use certain Win32 functions such as GetForegroundWindow() for debugging purposes. When i use MessageBox or OutputDebugString such as below... m_foreHwnd1 = GetForegroundWindow(); MessageBox(NULL, (LPCSTR)m_foreHwnd1, "INFO", MB_OK); OutputDebugString("ForeHwnd1: "); OutputDebugString((LPCSTR)m_foreHwnd1); OutputDebugString("\n"); ... I get errors like the following: First-chance exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Unhandled exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Can i display the HWND so i can see what the heck is going on in my code? What is the How To?
-
I am a beginner. I am trying to display the HWND when i use certain Win32 functions such as GetForegroundWindow() for debugging purposes. When i use MessageBox or OutputDebugString such as below... m_foreHwnd1 = GetForegroundWindow(); MessageBox(NULL, (LPCSTR)m_foreHwnd1, "INFO", MB_OK); OutputDebugString("ForeHwnd1: "); OutputDebugString((LPCSTR)m_foreHwnd1); OutputDebugString("\n"); ... I get errors like the following: First-chance exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Unhandled exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Can i display the HWND so i can see what the heck is going on in my code? What is the How To?
First thing you need to learn is that you do not cast things without knowing exactly what you are doing as you can shoot yourself in the foot, like what you have done here.
m_foreHwnd1 = GetForegroundWindow();
CString szMessage;
szMessage.Format(_T("ForeHwnd1: 0x%08X\r\n"), m_foreHwnd1);
OutputDebugString(szMessage); -
I am a beginner. I am trying to display the HWND when i use certain Win32 functions such as GetForegroundWindow() for debugging purposes. When i use MessageBox or OutputDebugString such as below... m_foreHwnd1 = GetForegroundWindow(); MessageBox(NULL, (LPCSTR)m_foreHwnd1, "INFO", MB_OK); OutputDebugString("ForeHwnd1: "); OutputDebugString((LPCSTR)m_foreHwnd1); OutputDebugString("\n"); ... I get errors like the following: First-chance exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Unhandled exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Can i display the HWND so i can see what the heck is going on in my code? What is the How To?
-
I am a beginner. I am trying to display the HWND when i use certain Win32 functions such as GetForegroundWindow() for debugging purposes. When i use MessageBox or OutputDebugString such as below... m_foreHwnd1 = GetForegroundWindow(); MessageBox(NULL, (LPCSTR)m_foreHwnd1, "INFO", MB_OK); OutputDebugString("ForeHwnd1: "); OutputDebugString((LPCSTR)m_foreHwnd1); OutputDebugString("\n"); ... I get errors like the following: First-chance exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Unhandled exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Can i display the HWND so i can see what the heck is going on in my code? What is the How To?
GetForegroundWindow() API will return handle to active window with which user is interacting, so in debugging mode you constantly switch between your app and debug window. so its difficult to know window handle. Not sure what are you trying to do, but try this to display window handle in output window.
CString str; str.Format("%x",m_foreHwnd1); OutputDebugString(str);
Hope this helps -
I am a beginner. I am trying to display the HWND when i use certain Win32 functions such as GetForegroundWindow() for debugging purposes. When i use MessageBox or OutputDebugString such as below... m_foreHwnd1 = GetForegroundWindow(); MessageBox(NULL, (LPCSTR)m_foreHwnd1, "INFO", MB_OK); OutputDebugString("ForeHwnd1: "); OutputDebugString((LPCSTR)m_foreHwnd1); OutputDebugString("\n"); ... I get errors like the following: First-chance exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Unhandled exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Can i display the HWND so i can see what the heck is going on in my code? What is the How To?
-
I am a beginner. I am trying to display the HWND when i use certain Win32 functions such as GetForegroundWindow() for debugging purposes. When i use MessageBox or OutputDebugString such as below... m_foreHwnd1 = GetForegroundWindow(); MessageBox(NULL, (LPCSTR)m_foreHwnd1, "INFO", MB_OK); OutputDebugString("ForeHwnd1: "); OutputDebugString((LPCSTR)m_foreHwnd1); OutputDebugString("\n"); ... I get errors like the following: First-chance exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Unhandled exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Can i display the HWND so i can see what the heck is going on in my code? What is the How To?