Archived

This topic is now archived and is closed to further replies.

EM_GETLINE

This topic is 5503 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, Anyone know whats wrong with this code:
      
char szBuff[256];
*(WORD*)szBuff = (WORD)5;
nLen = ::SendMessage(m_hWndMessages,EM_GETLINE,1,(LPARAM)szBuff);
      
I'm trying to get a line from the messages window in MSN. I know the handle is correct, and i know theres 20 lines in it (from EM_GETLINECOUNT - which works fine). When the program gets to the ::SendMessage() line, i get an access violation. [edited by - Evil Bill on November 21, 2002 6:28:58 PM]

Share this post


Link to post
Share on other sites
Maybe its obvious, but m_hWndMessages is in another process. Dunno if that affects anything. Also, it works fine if i do:
*(WORD*)szBuff = (WORD)0;

Any ideas?




[edited by - Evil Bill on November 21, 2002 6:29:09 PM]

Share this post


Link to post
Share on other sites
Ok, i think i'm getting somewhere. Because its another process, the pointer isn't valid, right? So, new question: How do i allocate memory under a different process? I've seen it done somewhere, but i can;t find where now

Edit: Ok, i've got CreateRemoteThread(), but GetLastError() says "This function is only valid in Win32 mode.", as does VirtualAllocEx(). My app is an MFC app.
Eek!

Edit2: D'oh! CreateRemoteThread only works under Win2k / NT

Edit3: Does anyone know of any other ways to get a pointer to *global* memory?




[edited by - Evil Bill on November 21, 2002 8:06:39 PM]

[edited by - Evil Bill on November 21, 2002 8:30:47 PM]

[edited by - Evil Bill on November 21, 2002 9:16:36 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i can tell you a couple of different ways to solve this, but i need to know why you need that line first.

Share this post


Link to post
Share on other sites
I saw a thread in the GDNet Lounge forum about someone who plugged Eliza into AOL IM. I''m trying to write my own version to plug into MSN. It works fine at the mo, but i currently send a WM_GETTEXT message to the message window. This means that i have to have a huge buffer to accomodate att the text - since only the last line is important.

No, its not some shifty MSN spy program

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
okay already! something like this should work for 9x OSs:

void afunc( HWND hWndMSN )
{
char szBuff[256];
HANDLE hFileMap = CreateFileMapping((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE, 0, sizeof(szBuff), "MyMapping";
if( hFileMap ) {
LPVOID pFileMap = MapViewOfFile(hFileMap, FILE_MAP_WRITE, 0, 0, 0);
if( pFileMap ) {
*((WORD*)pFileMap) = sizeof(szBuff) - 1;
int nLen = ::SendMessage(hWndMSN,EM_GETLINE,1,(LPARAM)pFileMap);
if( nLen ) {
CopyMemory(szBuff, pFileMap, nLen+1);
}
UnmapViewOfFile(pFileMap);
}
CloseHandle(hFileMap);
}
}


Share this post


Link to post
Share on other sites
Thanks for the reply. Unfortunately, same problem: "ELIZA caused a general protection fault in module USER.EXE" (ok, its not an access violation, but its pretty much the same thing).

Edit:
Just found out why:
The MapViewOfFile function maps a view of a file into the address space of the calling process
But i need it in MSNs address space...

Damn HTTP500 errors...





[edited by - Evil Bill on November 22, 2002 6:42:21 PM]

Share this post


Link to post
Share on other sites

  
/*
HANDLE hMSNProcess = MSN Process
HWND hWnd = Edit Control Handle
int nLine = Line Number
*/

#define STRING_SIZE 1024

LPVOID lpData = NULL;
int nSize = 0;
DWORD dwDummy = 0;
char szString[STRING_SIZE];

/*
NOTE: EM_GETLINE does not include the NULL terminator, so setting the string to all zeros is nice to do
*/

memset(szString, 0, STRING_SIZE);

if (lpData = ::VirtualAllocEx(hProcess, NULL, STRING_SIZE, MEM_COMMIT, PAGE_READWRITE))
{
if (nSize = ::SendMessage(hWnd, EM_GETLINE, nLine, (LPARAM)lpData))
{
if (!ReadProcessMemory(hProcess, lpData, (LPVOID)szString, nSize, &dwDummy))
{
//Error

}
}

::VirtualFreeEx(hProcess, lpData, STRING_SIZE, MEM_RELEASE);
}


Since EM_GETLINE requires a buffer in the process''s address space in which the window was created, you have to allocate your buffer in that address space.

Share this post


Link to post
Share on other sites
Cheers, but:
Ok, i've got CreateRemoteThread(), but GetLastError() says "This function is only valid in Win32 mode.", as does VirtualAllocEx().

Edit: i'm going to start a new topic, since the title isnot exactly accurate...




[edited by - Evil Bill on November 22, 2002 7:07:27 PM]

Share this post


Link to post
Share on other sites