// HookMsg.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "HookMsg.h" #include "HookMsgDlg.h" #include "LogonDlg.h" #include #include "HookMsg_i.c" #include "./UtilClass/LimitSingleInstance.h" CLimitSingleInstance g_SingleInstanceObj(TEXT("{1F80F079-B2CD-49ac-AD84-52160FBDB753}")); #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CHookMsgApp BEGIN_MESSAGE_MAP(CHookMsgApp, CWinApp) //{{AFX_MSG_MAP(CHookMsgApp) ON_COMMAND(ID_APP_ABOUT, OnAppAbout) //}}AFX_MSG_MAP ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CHookMsgApp construction CHookMsgApp::CHookMsgApp() { m_bSuccess = FALSE; m_strLoginServer1 = ""; m_strLoginServer2 = ""; for(int i=0;iSeekToEnd(); } CHookMsgDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } m_bSuccess = TRUE; // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; } // [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings] CString CHookMsgApp::RegReadString(HKEY hKeyName, CString strPath, CString strSubKey) { CString RegKey = ""; HKEY hKey; ::RegOpenKeyEx(hKeyName, strPath, 0, KEY_ALL_ACCESS, &hKey); DWORD dwType; DWORD dwBytes = 10240; char szBuf[10240] = {0,}; LONG lRet = ::RegQueryValueEx(hKey, strSubKey, 0, &dwType, (LPBYTE)szBuf, &dwBytes); if( lRet == ERROR_SUCCESS ) { ::RegCloseKey(hKey); RegKey = szBuf; return RegKey; } else { ::RegCloseKey(hKey); return ""; } } BOOL CHookMsgApp::RegWriteString(HKEY hKeyName, CString strPath, CString strSubKey, CString strValue) { HKEY hKey; ::RegCreateKeyEx(hKeyName, strPath, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL); LONG lRet = ::RegSetValueEx( hKey, strSubKey, 0, REG_SZ, (const unsigned char*)(LPCTSTR)strValue, strValue.GetLength() ); if( lRet == ERROR_SUCCESS ) { ::RegCloseKey(hKey); return TRUE; } else { Message_Box( "·¹Áö½ºÆ®¸® ¾²±â½ÇÆÐ", ::GetLastError() ); ::RegCloseKey(hKey); return FALSE; } } int CHookMsgApp::ExitInstance() { if( m_bSuccess ) { /////////////////////////////////////////////////////////////////// g_ConfigINI.WriteConfigEnvToINI(); SaveAppEnv(); /////////////////////////////////////////////////////////////////// if (m_bATLInited) { _Module.RevokeClassObjects(); _Module.Term(); CoUninitialize(); } if( g_pLogFile ) { g_pLogFile->Flush(); g_pLogFile->Close(); delete g_pLogFile; } } return CWinApp::ExitInstance(); } /////////////////////////////////////////////////////////////////////// CHookMsgModule _Module; BEGIN_OBJECT_MAP(ObjectMap) END_OBJECT_MAP() LONG CHookMsgModule::Unlock() { AfxOleUnlockApp(); return 0; } LONG CHookMsgModule::Lock() { AfxOleLockApp(); return 1; } LPCTSTR CHookMsgModule::FindOneOf(LPCTSTR p1, LPCTSTR p2) { while (*p1 != NULL) { LPCTSTR p = p2; while (*p != NULL) { if (*p1 == *p) return CharNext(p1); p = CharNext(p); } p1++; } return NULL; } BOOL CHookMsgApp::InitATL() { m_bATLInited = TRUE; #if _WIN32_WINNT >= 0x0400 HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED); #else HRESULT hRes = CoInitialize(NULL); #endif if (FAILED(hRes)) { m_bATLInited = FALSE; return FALSE; } _Module.Init(ObjectMap, AfxGetInstanceHandle()); _Module.dwThreadID = GetCurrentThreadId(); LPTSTR lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT TCHAR szTokens[] = _T("-/"); BOOL bRun = TRUE; LPCTSTR lpszToken = _Module.FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, _T("UnregServer"))==0) { _Module.UpdateRegistryFromResource(IDR_HOOKMSG, FALSE); _Module.UnregisterServer(TRUE); //TRUE means typelib is unreg'd bRun = FALSE; break; } if (lstrcmpi(lpszToken, _T("RegServer"))==0) { _Module.UpdateRegistryFromResource(IDR_HOOKMSG, TRUE); _Module.RegisterServer(TRUE); bRun = FALSE; break; } lpszToken = _Module.FindOneOf(lpszToken, szTokens); } if (!bRun) { m_bATLInited = FALSE; _Module.Term(); CoUninitialize(); return FALSE; } hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE); if (FAILED(hRes)) { m_bATLInited = FALSE; CoUninitialize(); return FALSE; } return TRUE; }