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!