Obtaining Window Location
I have the code below I am trying to use to get a Hwnd window location.
When I compile and link, all is well. When i run I get th e error :
An unhandled exception of type 'System.AccessViolationException' occurred in AutoInspectorX.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
I'm passing the callback handler to a callback handler in a class, so it looks like there are 2 callback handlers! Is this an OK way to do it?
Can anyone explain to me why this fails please as it looks fine to me! :confused:
Code :
// Called from my main function...
EnumWindows(SearchWindowsHandle,(LPARAM)this);
// Callback handler to search HWND's
BOOL CALLBACK SearchWindowsHandle(HWND hWnd, LPARAM lparam)
{
AutoInspectorX *pMe = (AutoInspectorX *)lparam;
return pMe->SearchWindowsCallbackHandler(hWnd); // Call class member for callback
}
bool AutoInspectorX::SearchWindowsCallbackHandler(HWND hWnd)
{
char buff[500];
string temp = "";
bool written_flag = 0;
if (!hWnd)
{ return TRUE; } // Not a window
if (!::IsWindowVisible(hWnd))
{ return TRUE; } // Not a visible window
GetWindowText(hWnd,buff,sizeof(buff)*sizeof(char));
if (strstr(buff,""))
{
if (searchSize< WIND_SRCH_SIZE)
{
string temp(buff);
storeStrings[index] = temp;
index++;
}
myWnd = hWnd; // Add the last Hwnd found in category
LPRECT recta;
GetWindowRect(myWnd , recta);
}
return TRUE;
}

