GetWindowText and SendMessage return Default IME

Ok so i'm creating a Dll in Visual Studio 2010 Prof. and using GetWindowText and SendMessage both return "Default IME" instead of the Windows Text. OS: Windows 7 (x64) Ultimate. Oh and I am compiling Unicode because thats how the application sends the data to the DLL

<C++ Code>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using namespace std;

std::vector<TCHAR*> wTextArr;
std::vector<TCHAR*> wClassName;

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
	TCHAR lpTitle[1024];
	TCHAR lpClassName[1024];

	ZeroMemory(lpTitle, sizeof(lpTitle));
	ZeroMemory(lpClassName, sizeof(lpClassName));
	
	SendMessage(hwnd,WM_GETTEXT, sizeof(lpTitle), (LPARAM)(void*)lpTitle);
	wTextArr.push_back( (TCHAR *)lpTitle );
	return TRUE;
}

DllExport int fGetWindowsList()
{
	std::vector<TCHAR*>::iterator i;
	for(i=wTextArr.begin(); i<wTextArr.end(); i++){
		delete &i;
	}
	wTextArr.clear();
	//EnumDesktopWindows(NULL, EnumWindowsProc, NULL);
	EnumWindows(EnumWindowsProc, NULL);
	return wTextArr.size();
}

DllExport wchar_t* fGetWindowText(int numWindow, wchar_t *inBuffer)
{
	return wTextArr[numWindow];
}


The Export returns "Default IME" Anyone have any insight. and yes i've googled it but nothing.
Last edited on
Line 23: You're deleting the iterator which leads to undefined behavior.
Change to delete *i; // Note: * instead of &

Better yet: use wstring
Thank you for looking at my code I have performed the following

1. I changed line 23 from &i to *i and recompiled
Result: No Change
2. I Commented out the iterator completely to rule it out
Result: No Change

So if you see anything else let me know

The issue is: What exactly does WM_GETTEXT? Read this:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms632627%28v=vs.85%29.aspx

MSDN wrote:
for non-text static controls this gives you the text with which the control was originally created, that is, the ID number


This might be more what you want:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms633520%28v=vs.85%29.aspx

MSDN wrote:
If the target window is owned by another process and has a caption, GetWindowText retrieves the window caption text
Thanks for looking again. to respond to your previous post in a way you were correct. after looking at my code and not having been up for the last 20 hrs straight and then getting up again after just 6hrs of sleep lol. I realized that the information that I was POINTING to was incorrect.

So many times browse the forums and I find a thread that just ends and the admin set it to resolved. So i'm gonna post my NEW working code in the event that someone runs into the same issue

<C++ CODE>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using namespace std;

std::vector<TCHAR*> wTextArr;
std::vector<TCHAR*> wClassName;

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
	int txtLength = ::GetWindowTextLength(hwnd);
	TCHAR lpTitle[1024];
	TCHAR lpClassName[1024];
	LPTSTR lpText;

	ZeroMemory(lpTitle, sizeof(lpTitle));
	ZeroMemory(lpClassName, sizeof(lpClassName));
	
	lpText = (LPTSTR)LocalAlloc(LMEM_FIXED, (txtLength + 1) * sizeof(TCHAR));
	SendMessage(hwnd,WM_GETTEXT, txtLength + 1, (LPARAM)lpText);

	if(txtLength != 0){
		if(lstrcmp(lpText, _T("Default IME")) != 0){
			wTextArr.push_back( lpText );
		}
	}
	return TRUE;
}

DllExport int fGetWindowsList()
{
	std::vector<TCHAR*>::iterator i;
	for(i=wTextArr.begin(); i<wTextArr.end(); i++){
		delete *i;
	}
	wTextArr.clear();
	EnumWindows(EnumWindowsProc, NULL);
	return wTextArr.size();
}

DllExport wchar_t* fGetWindowText(int numWindow, wchar_t *inBuffer)
{
	return wTextArr[numWindow];
}
I'd say that line 16 is a problem. Either use new on line 16 or LocalFree(...) on line 31
Registered users can post here. Sign in or register to post.