Is there better way to do this?

Hi!

I want to tell if current process has window with title "Error". This is how I do it:



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
BOOL CALLBACK enumWindowCallback(HWND hWnd, LPARAM lparam) {
	int length = GetWindowTextLength(hWnd);
	char* buffer = new char[length + 1];
	GetWindowText(hWnd, buffer, length + 1);

	DWORD lpdwProcessId = 0;
	GetWindowThreadProcessId(hWnd, &lpdwProcessId);
	if (IsWindowVisible(hWnd) && length != 0
		&& strcmp(buffer, "Error") == 0
		&& GetCurrentProcessId() == lpdwProcessId
		) {
		memcpy((void*)lparam, &lpdwProcessId, 4);
		return FALSE;
	}
	return TRUE;
}

bool hasError() {
	int pid = 0;
	EnumWindows(enumWindowCallback, (LPARAM)&pid);
	return pid > 0;
}


Is there any better way to get pid out of it? Specially without using memcpy?
I tried using assingnment operators in enumWindowCallback like lparam = pid or *lparam = *pid and so on but I got different errors with arr kinds of assignments that I came up with. Would like to know what is better way to do this?
LPARAM is just an integer. It should be directly assignment-compatible with a PID, which is also an integer.
Topic archived. No new replies allowed.