logging from AIM windows

This is a discussion on logging from AIM windows within the Windows Programming forums, part of the Platform Specific Boards category; I've been trying to come up with an application that will log my instant messaging conversations (yeah, I know there ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    18

    Angry logging from AIM windows

    I've been trying to come up with an application that will log my instant messaging conversations (yeah, I know there are tons of programs out there that will do it for me, but I'd like the experience). I'd like someone to look at my code and see what might be going wrong. I don't get any errors when I build or compile in MSVC6, but when I run the executable i get a run-time error and it just crashes. When XP asks me if I want to debug it and I click yes, it brings me to this reference in winmain.cpp:

    Code:
    	// Perform specific initializations
    ---->	if (!pThread->InitInstance())
    	{
    		if (pThread->m_pMainWnd != NULL)
    		{
    			TRACE0("Warning: Destroying non-NULL m_pMainWnd\n");
    			pThread->m_pMainWnd->DestroyWindow();
    		}
    		nReturnCode = pThread->ExitInstance();
    		goto InitFailure;
    	}
    	nReturnCode = pThread->Run();
    But here is my source:
    Code:
    #include "stdafx.h"
    #include <fstream.h>
    #include <windows.h>
    
    
    bool goodStuffFound=false;
    
    BOOL CALLBACK EnumChildAIMWindows(HWND hWnd,LPARAM lParam) {
       char buffer[256];
       GetClassName(hWnd,buffer,256);
       char* buf=new char;
       GetWindowText(hWnd,buf,GetWindowTextLength(hWnd));
    
    	if((strcmp(buffer,"WndAte32Class")==0))	{
    
    		if(!goodStuffFound) {
    			goodStuffFound=true;
    			LRESULT theResult;
    
    			theResult=SendMessage(hWnd,WM_GETTEXTLENGTH,0,0);
    			char theStuff[20000];
    			SendMessage(hWnd,WM_GETTEXT,theResult+1,(LPARAM)theStuff);
    
    			fstream file;
    			file.open("output.txt",ios::out,filebuf::openprot);
    			file.write(theStuff,sizeof(theStuff));
    			file.close();
    			// Do whatever we want with the message....
    			}
    	}
    	return true;
    }
    
    BOOL CALLBACK EnumWindowsProc(HWND hWnd,LPARAM lParam) {
    	char buffer[256];
    	GetWindowText(hWnd,buffer,256);
    	if(!strstr(buffer," - Instant Message")==NULL) {
    		EnumChildWindows(hWnd,EnumChildAIMWindows,0);
    		goodStuffFound=false;
    		}
    	return true;
    }
    
    int main(int argc, char* argv[]) {
    	EnumWindows(EnumWindowsProc,0); 
    	return 0;
    }
    Thanks in advance for any help!

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    >>if(!strstr(buffer," - Instant Message")==NULL) {
    Assumable you want:
    if(strstr(buffer," - Instant Message")!=NULL) {
    
    >>   char* buf=new char;
    >>   GetWindowText(hWnd,buf,GetWindowTextLength(hWnd));
    I don't think this is going to work. What do you use
    buf for anyway?
    
    Similar problem when using thestuff below.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > char* buf=new char;
    You need to allocate a bigger buffer:
    char* buf=new char[GetWindowTextLength(hWnd)+1];

    > GetWindowText(hWnd,buf,GetWindowTextLength(hWnd));
    //Delete the memory when you're done.
    delete []buf;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Anyone using Windows 7?
    By Sharke in forum General Discussions
    Replies: 60
    Last Post: 07-12-2009, 08:05 AM
  2. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 02:55 PM
  3. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  4. Dos differences in Windows NT and Windows XP
    By Ruchikar in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 09-17-2003, 11:36 PM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21