| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011 |
- #include "stdafx.h"
- #include <tlhelp32.h>
- #include "SysLib.h"
- #include <io.h>
- #include <odbcinst.h>
- #include <afxdb.h>
- #include "resource.h"
- #include "crc32.h"
- #include "Client2SrvType.h"
- #include "..\ChineseRes\ChineseRes\resource.h"
- #include <psapi.h>
- #pragma comment ( lib, "psapi.lib" )
- //*********************************************************
- //Functiopn: LogEvent
- //Description: 记录服务事件
- //Calls:
- //Called By:
- //Table Accessed:
- //Table Updated:
- //Input:
- //Output:
- //Return:
- //Others:
- //History:
- // <author>niying <time>2006-8-10 <version> <desc>
- //*********************************************************
- void LogEvent(LPCTSTR pFormat, ...)
- {
- TCHAR chMsg[256];
- HANDLE hEventSource;
- LPTSTR lpszStrings[1];
- va_list pArg;
- va_start(pArg, pFormat);
- _vstprintf(chMsg, pFormat, pArg);
- va_end(pArg);
- lpszStrings[0] = chMsg;
-
- hEventSource = RegisterEventSource(NULL, g_szServiceName);
- if (hEventSource != NULL)
- {
- ReportEvent(hEventSource, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (LPCTSTR*) &lpszStrings[0], NULL);
- DeregisterEventSource(hEventSource);
- }
- }
- //增加自动启动注册表项
- INT AddAutoSysRun(CHAR *strExeFile, INT iAutoRunSystem)
- {
- HKEY hKey = NULL;
- DWORD dwErrorCode = 0;
-
- //创建注册表,有该键则读取,无则创建
- dwErrorCode = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
- "Software\\Microsoft\\Windows\\CurrentVersion\\Run",
- 0,
- NULL,
- REG_OPTION_NON_VOLATILE,
- KEY_ALL_ACCESS,
- NULL, //Security
- &hKey,
- NULL);
- if (dwErrorCode == ERROR_SUCCESS)
- {
- if (iAutoRunSystem)
- dwErrorCode = RegSetValueEx(hKey, "SToneU-isP-CMS", NULL, REG_SZ, (BYTE*)strExeFile, (DWORD)strlen(strExeFile));
- else
- dwErrorCode = RegDeleteKey(hKey, "SToneU-isP-CMS");
- }
- if (NULL != hKey)
- RegCloseKey(hKey);
- hKey = NULL;
- return 0;
- }
- //软件时间限制代码
- INT ProgramEncrypt(HWND hWnd)
- {
- SYSTEMTIME systemtime;
- HKEY hKey = NULL;
- CHAR strKeyName[50] = "";
- CHAR strFirstDate[20] = "";
- CHAR strMaxDate[20] = "";
- CHAR strMinDate[20] = "";
- CHAR strNowDate[20] = "";
- DWORD dwErrorCode = 0;
- INT iNumberOfDays = 0;
- DWORD dwType = 0;
- DWORD dwSize = 0;
- if (g_bEnableTimeLimited == FALSE)
- return 1;
-
- //创建注册表,有该键则读取,无则创建
- strcpy(strKeyName, "Software\\stoneu");
- dwErrorCode = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
- strKeyName,
- 0,
- NULL,
- REG_OPTION_NON_VOLATILE,
- KEY_ALL_ACCESS,
- NULL, //Security
- &hKey,
- NULL);
- if (dwErrorCode == ERROR_SUCCESS)
- {
- dwType = REG_BINARY;
- dwSize = sizeof(strFirstDate);
- dwErrorCode = RegQueryValueEx(hKey,
- "Date",
- NULL,
- &dwType,
- (BYTE*)strFirstDate,
- &dwSize
- );
- if (dwErrorCode == ERROR_SUCCESS && strcmp(strFirstDate, ""))
- {
- ::GetLocalTime(&systemtime);
- CTime NowDate(systemtime.wYear, systemtime.wMonth, systemtime.wDay, systemtime.wHour, systemtime.wMinute, systemtime.wSecond);
- CTime MaxDate(systemtime.wYear, systemtime.wMonth, systemtime.wDay, systemtime.wHour, systemtime.wMinute, systemtime.wSecond);
- CTime MinDate(systemtime.wYear, systemtime.wMonth, systemtime.wDay, systemtime.wHour, systemtime.wMinute, systemtime.wSecond);
- iNumberOfDays = 90;
- MaxDate = MaxDate + CTimeSpan(iNumberOfDays, 0, 0, 0);
- MinDate = MinDate - CTimeSpan(iNumberOfDays, 0, 0, 0);
- sprintf(strMaxDate, "%04d%02d%02d", MaxDate.GetYear(), MaxDate.GetMonth(), MaxDate.GetDay());
- sprintf(strMinDate, "%04d%02d%02d", MinDate.GetYear(), MinDate.GetMonth(), MinDate.GetDay());
- if (atoi(strMaxDate) >= atoi(strFirstDate) && atoi(strMinDate) <= atoi(strFirstDate))
- {
- if (NULL != hKey)
- RegCloseKey(hKey);
- hKey = NULL;
- return 1;
- }
- else
- {
- LOG4C((LOG_NOTICE, "软件试用天数已经到期!"));
- //MessageBox(hWnd, "软件试用天数已经到期!", "提示", MB_OK+MB_ICONINFORMATION);
- ////超过x天,则禁止运行
- //::InvalidateRect(hWnd, NULL, TRUE);
- //::UpdateWindow(hWnd);
- }
- }
- else
- {
- if (NULL == hWnd)
- {
- ::GetLocalTime(&systemtime);
- sprintf(strFirstDate, "%04d%02d%02d", systemtime.wYear, systemtime.wMonth, systemtime.wDay);
- dwErrorCode = RegSetValueEx(hKey,
- "Date",
- NULL,
- REG_BINARY,
- (BYTE*)strFirstDate,
- sizeof(strFirstDate)
- );
- if (dwErrorCode == ERROR_SUCCESS)
- {
- if (NULL != hKey)
- RegCloseKey(hKey);
- hKey = NULL;
- return 1;
- }
- }
- }
- }
- if (NULL != hKey)
- RegCloseKey(hKey);
- hKey = NULL;
- return 0;
- }
- //
- // FindProcess
- // 这个函数唯一的参数是你指定的进程名,如:你的目标进程
- // 是 "Notepad.exe",返回值是该进程的ID,失败返回0
- //
- int FindProcessCount(char *strProcessName)
- {
- int nCount = 0;
- DWORD aProcesses[1024], cbNeeded, cbMNeeded;
- HMODULE hMods[1024];
- HANDLE hProcess;
- char szProcessName[MAX_PATH];
- if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) return 0;
- for(int i=0; i< (int) (cbNeeded / sizeof(DWORD)); i++)
- {
- //_tprintf(_T("%d\t"), aProcesses[i]);
- hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, aProcesses[i]);
- EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbMNeeded);
- GetModuleFileNameEx( hProcess, hMods[0], szProcessName,sizeof(szProcessName));
-
- if(strstr(szProcessName, strProcessName))
- {
- //_tprintf(_T("%s;"), szProcessName);
- nCount++;
- }
- //_tprintf(_T("\n"));
- }
- return nCount;
- }
- //
- // Function: ErrorForce
- // 此函数中用上面的 FindProcess 函数获得你的目标进程的ID
- // 用WIN API OpenPorcess 获得此进程的句柄,再以TerminateProcess
- // 强制结束这个进程
- //
- VOID KillProcess(DWORD dwProcess)
- {
- // When the all operation fail this function terminate the "winlogon" Process for force exit the system.
- HANDLE hTargetProcess = OpenProcess(PROCESS_QUERY_INFORMATION | // Required by Alpha
- PROCESS_CREATE_THREAD | // For CreateRemoteThread
- PROCESS_VM_OPERATION | // For VirtualAllocEx/VirtualFreeEx
- PROCESS_VM_WRITE, // For WriteProcessMemory
- FALSE, dwProcess);
- if(hTargetProcess == NULL)
- {
- return;
- }
- TerminateProcess(hTargetProcess, 0);
- return;
- }
- //
- // FindProcess
- // 这个函数唯一的参数是你指定的进程名,如:你的目标进程
- // 是 "Notepad.exe",返回值是该进程的ID,失败返回0
- //
- DWORD FindAndKillProcess(char *strProcessName)
- {
- DWORD aProcesses[1024], cbNeeded, cbMNeeded;
- HMODULE hMods[1024];
- HANDLE hProcess;
- char szProcessName[MAX_PATH];
- if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) return 0;
- for(int i=0; i< (int) (cbNeeded / sizeof(DWORD)); i++)
- {
- //_tprintf(_T("%d\t"), aProcesses[i]);
- hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, aProcesses[i]);
- EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbMNeeded);
- GetModuleFileNameEx( hProcess, hMods[0], szProcessName,sizeof(szProcessName));
-
- if(strstr(szProcessName, strProcessName))
- {
- //_tprintf(_T("%s;"), szProcessName);
- KillProcess(aProcesses[i]);
- //return(aProcesses[i]);
- }
- //_tprintf(_T("\n"));
- }
- return 0;
- }
- int Handle_DeleteTrayNullIcon( BOOL &bNullBeDel )
- {
- bNullBeDel = FALSE;
- HWND hStatus=::FindWindow("Shell_TrayWnd",NULL); //得到任务栏句柄
- if (hStatus==NULL)
- {
- //AfxMessageBox ( "Get Shell_TrayWnd error!" );
- return -1;
- }
- HWND hNotify=FindWindowEx(hStatus,NULL,"TrayNotifyWnd",NULL); //右下角区域
- if (hNotify==NULL)
- {
- //AfxMessageBox ( "Get TrayNotifyWnd error!" );
- return -1;
- }
- HWND hNotify1=FindWindowEx(hNotify,NULL,"SysPager",NULL);
- if (hNotify==NULL)
- {
- //AfxMessageBox ( "Get SysPager error!" );
- return -1;
- }
- HWND hNotify1_0=FindWindowEx(hNotify1,NULL,"ToolBarWindow32",NULL);//右下角区域(不包括时间)
- if (hNotify1_0==NULL)
- {
- //AfxMessageBox ( "Get ToolBarWindow32 error!" );
- return -1;
- }
- //-------------------以上是得到任务栏右下脚一块地方的句柄
- DWORD pid = 0;
- GetWindowThreadProcessId(hNotify1_0,&pid);
- if (pid==NULL)
- {
- //AfxMessageBox ( "Get pid error!" );
- return -1;
- }
-
- HANDLE hProcess=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_ALL_ACCESS,true,pid);
- if (hProcess==NULL)
- {
- //AfxMessageBox ( "Get hd error!" );
- return -1;
- }
- ::SendMessage(hNotify1_0,WM_PAINT ,NULL,NULL);
- CRect rect;
- ::GetWindowRect(hNotify1_0,&rect);
- ::InvalidateRect(hNotify1_0,&rect,false);
- int iNum = (int)::SendMessage(hNotify1_0,TB_BUTTONCOUNT ,NULL,NULL); //获取任务栏上图标个数
-
- unsigned long n = 0;
- TBBUTTON *pButton = new TBBUTTON;
- CString strInfo = _T("");
- wchar_t name[256] = {0};
- TBBUTTON BButton;
- unsigned long whd,proid;
- CString x;
-
- for(int i=0; i<iNum; i++)
- {
- ::SendMessage(hNotify1_0,TB_GETBUTTON,i,(LPARAM)(&BButton));
- ReadProcessMemory(hProcess,&BButton,pButton,sizeof(TBBUTTON),&n);
- if (pButton->iString != 0xffffffff)
- {
- try
- {
- ReadProcessMemory(hProcess,(void *)pButton->iString,name,255,&n);
- }
- catch(...)
- {
- }
- strInfo.Format("%d : %s\n",i+1,CString(name));
- //TRACE(strInfo);
- }
-
- try
- {
- whd=0;
- ReadProcessMemory(hProcess,(void *)pButton->dwData,&whd,4,&n);
- }
- catch(...)
- {
- }
- proid=NULL;
- GetWindowThreadProcessId((HWND)whd,&proid);
- if(proid==NULL)
- {
- bNullBeDel = TRUE;
- ::SendMessage(hNotify1_0,TB_DELETEBUTTON,i,0);
- }
- }
- delete pButton;
- return 0;
- }
- int GetSysData()
- {
- CHAR strFile[MAX_FILE_LENGTH + 1] = "";
- CHAR strValue[MAX_VALUE_LENGTH + 1] = "";
- int iPosFile = 0;
- int iLenghtFile = 0;
- ////////////////////////////////////////////////////////////////////////////
- //获取应用名
- //GetModuleFileName(AfxGetApp()->m_hInstance, g_strDirectory, MAX_PATH);
- GetModuleFileName(NULL, g_strDirectory, MAX_PATH);
- iLenghtFile = (int)strlen(g_strDirectory);
- for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
- {
- if (g_strDirectory[iPosFile] == '\\')
- {
- memset(g_strAppName, 0, sizeof(g_strAppName));
- memcpy(g_strAppName, g_strDirectory + iPosFile + 1, iLenghtFile - iPosFile - 1);
- break;
- }
- }
-
- iLenghtFile = strlen(g_strDirectory);
- for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
- {
- if (g_strDirectory[iPosFile] == '\\')
- {
- g_strDirectory[iPosFile] = '\0';
- break;
- }
- }
- wsprintf(strFile, "%s\\set.ini", g_strDirectory);
- //是否自动启动系统
- GetPrivateProfileString("Other", "AutoRunSystem", "", strValue, sizeof(strValue), strFile);
- if (strcmp(strValue, ""))
- g_iAutoRunSystem = atoi(strValue);
- else
- g_iAutoRunSystem = 0;
- if (g_iAutoRunSystem <= 0)
- g_iAutoRunSystem = 0;
- else
- g_iAutoRunSystem = 1;
- //WatchService
- GetPrivateProfileString("WatchServer", "ServerIP", "", g_strWatchServerIP, sizeof(g_strWatchServerIP), strFile);
- GetPrivateProfileString("WatchServer", "Port", "", g_strWatchServerPort, sizeof(g_strWatchServerPort), strFile);
- //语言
- GetPrivateProfileString("Other", "Language", "", g_strLanguage, sizeof(g_strLanguage), strFile);
- //Database
- GetPrivateProfileString("Database", "DBType", "", g_strDBType, sizeof(g_strDBType), strFile);
-
- GetPrivateProfileString("Database", "AccessFile", "", g_strAccessFile, sizeof(g_strAccessFile), strFile);
-
- GetPrivateProfileString("Database", "ServerName", "", g_strServerName, sizeof(g_strServerName), strFile);
-
- GetPrivateProfileString("Database", "DataBaseName", "", g_strDataBaseName, sizeof(g_strDataBaseName), strFile);
-
- GetPrivateProfileString("Database", "UserName", "", g_strUserName, sizeof(g_strUserName), strFile);
-
- GetPrivateProfileString("Database", "Password", "", g_strPassword, sizeof(g_strPassword), strFile);
- //数据库连接串
- if (!_stricmp(g_strDBType, "SQL SERVER"))
- sprintf(g_strConnectString, "Provider=sqloledb;Data Source=%s;Initial Catalog=%s;User Id=%s;Password=%s; ",
- g_strServerName, g_strDataBaseName, g_strUserName, g_strPassword);
- else if (!_stricmp(g_strDBType, "ACCESS97"))
- sprintf(g_strConnectString, "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=%s", g_strAccessFile);
- else if (!_stricmp(g_strDBType, "ACCESS2000"))
- sprintf(g_strConnectString, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s", g_strAccessFile);
- else if(!_stricmp(g_strDBType, "PGSQL"))
- sprintf(g_strConnectString, "DRIVER={PostgreSQL ODBC Driver(UNICODE)}; SERVER=%s; port=5432; DATABASE=%s; UID=%s; PWD=%s;",
- g_strServerName, g_strDataBaseName, g_strUserName, g_strPassword);
- else
- sprintf(g_strConnectString, "Provider=sqloledb;Data Source=%s;Initial Catalog=%s;User Id=%s;Password=%s; ",
- g_strServerName, g_strDataBaseName, g_strUserName, g_strPassword);
- //Common
- g_nLevelWav = GetPrivateProfileInt("Common", "LevelWav", 3, strFile);
- g_nLevelSms = GetPrivateProfileInt("Common", "LevelSms", 3, strFile);
- g_nLevelEmail = GetPrivateProfileInt("Common", "LevelEmail", 3, strFile);
- g_nLevelDevInterrupt = GetPrivateProfileInt("Common", "LevelDevInterrupt", 8, strFile);
- g_nLevelDlg = GetPrivateProfileInt("Common", "LevelDlg", 1, strFile);
- g_nLevelLocalWav = GetPrivateProfileInt("Common", "LevelLocalWav", 1, strFile);
- g_nDBRecordDate = GetPrivateProfileInt("Common", "DbRecordDate", 365, strFile);
- //Email
- g_nSendEmail = GetPrivateProfileInt("Email", "SendEmail", 0, strFile);
- GetPrivateProfileString("Email", "SMTPServer", "", g_strEmailSMTPSrv, sizeof(g_strEmailSMTPSrv), strFile);
- g_nEmailSMTPPort = GetPrivateProfileInt("Email", "SMTPPort", 25, strFile);
-
- g_nEmailIsNeed = GetPrivateProfileInt("Email", "IsNeed", 1, strFile);
- GetPrivateProfileString("Email", "UserAcc", "", g_strEmailUserAcc, sizeof(g_strEmailUserAcc), strFile);
- GetPrivateProfileString("Email", "UserPwd", "", g_strEmailUserPwd, sizeof(g_strEmailUserPwd), strFile);
- GetPrivateProfileString("Email", "MailFrom", "", g_strEmailFromAddr, sizeof(g_strEmailFromAddr), strFile);
- g_nEmailTimeOut = GetPrivateProfileInt("Email", "TimeOut", 60, strFile);
- GetPrivateProfileString("Email", "Subject", "", g_strEmailSubject, sizeof(g_strEmailSubject), strFile);
- g_nEmailCallTimes = GetPrivateProfileInt("Email", "ReCallTimes", 2, strFile);
- //Sms
- g_nSendSms = GetPrivateProfileInt("Sms", "SendSms", 0, strFile);
- GetPrivateProfileString("Sms", "Port", "", g_strSmsComPort, sizeof(g_strSmsComPort), strFile);
- g_nSmsRate = GetPrivateProfileInt("Sms", "Rate", 115200, strFile);
- g_nSmsDataBit = GetPrivateProfileInt("Sms", "DataBit", 8, strFile);
- g_nSmsStopBit = GetPrivateProfileInt("Sms", "StopBit", 1, strFile);
- g_nSmsParity = GetPrivateProfileInt("Sms", "Parity", 0, strFile);
- g_nSmsInterval = GetPrivateProfileInt("Sms", "Interval", 0, strFile);
- g_nSmsLanguageTrans = GetPrivateProfileInt("Sms", "LanguageTrans", 0, strFile);
- g_nSmsMaxChar = GetPrivateProfileInt("Sms", "MaxChar", 0, strFile);
- g_nSmsMakeCall = GetPrivateProfileInt("Sms", "MakeCall", 0, strFile);
- GetPrivateProfileString("Sms", "SMSC", "", g_strSmsSMSC, sizeof(g_strSmsSMSC), strFile);
- g_nSmsTimOut = GetPrivateProfileInt("Sms", "TimeOut", 60, strFile);
- g_nSmsCallTimes = GetPrivateProfileInt("Sms", "ReCallTimes", 2, strFile);
- //Voice
- g_nSendNotice = GetPrivateProfileInt("Voice", "SendNotice", 0, strFile);
- g_nNoticeCardType = GetPrivateProfileInt("Voice", "CardType", 0, strFile);
- GetPrivateProfileString("Voice", "PreTel", "", g_strNoticeTelPre, sizeof(g_strNoticeTelPre), strFile);
- g_nNoticeCallDelay = GetPrivateProfileInt("Voice", "CallRelay", 60, strFile);
- g_nNoticeCallTimes = GetPrivateProfileInt("Voice", "ReCallTimes", 2, strFile);
- //TTS
- g_nTTSType = GetPrivateProfileInt("TTS", "VoiceType", 0, strFile);
- //AlarmMode
- g_nAlarmModeIsDlg = GetPrivateProfileInt("AlarmMode", "Dlg", 0, strFile);
- g_nAlarmModeShowDlgTimes = GetPrivateProfileInt("AlarmMode", "ShowTime", 1, strFile);
- g_nAlarmModeIsSound = GetPrivateProfileInt("AlarmMode", "Sound", 0, strFile);
- g_nAlarmModeSoundNum = GetPrivateProfileInt("AlarmMode", "PlayNum", 1, strFile);
- GetPrivateProfileString("Other", "SummaryLog", "", g_strSummaryLogPath, sizeof(g_strSummaryLogPath), strFile);
- //定时发送短信和电话参数配置
- g_nTimingEnable = GetPrivateProfileInt("Timing", "Enable", 0, strFile);
- g_nTimingWeeks = GetPrivateProfileInt("Timing", "Weeks", 0, strFile);
- g_nTimingHours = GetPrivateProfileInt("Timing", "Hours", 0, strFile);
- g_nTimingMinutes = GetPrivateProfileInt("Timing", "Minutes", 0, strFile);
- //变量输出,特别为上海烟草局做的
- g_nOutputEnable = GetPrivateProfileInt("output", "Enable", 0, strFile);
- GetPrivateProfileString("output", "path", "", g_strOutputPath, sizeof(g_strOutputPath), strFile);
- GetPrivateProfileString("output", "filename", "", g_strOutputFileName, sizeof(g_strOutputFileName), strFile);
- GetPrivateProfileString("output", "clock", "", g_strOutputClock, sizeof(g_strOutputClock), strFile);
- GetPrivateProfileString("output", "line1", "", g_strOutputLine1, sizeof(g_strOutputLine1), strFile);
- GetPrivateProfileString("output", "line2", "", g_strOutputLine2, sizeof(g_strOutputLine2), strFile);
- GetPrivateProfileString("output", "line3", "", g_strOutputLine3, sizeof(g_strOutputLine3), strFile);
- GetPrivateProfileString("output", "line4", "", g_strOutputLine4, sizeof(g_strOutputLine4), strFile);
- GetPrivateProfileString("output", "line5", "", g_strOutputLine5, sizeof(g_strOutputLine5), strFile);
- GetPrivateProfileString("output", "line6", "", g_strOutputLine6, sizeof(g_strOutputLine6), strFile);
- GetPrivateProfileString("output", "line7", "", g_strOutputLine7, sizeof(g_strOutputLine7), strFile);
- GetPrivateProfileString("output", "line8", "", g_strOutputLine8, sizeof(g_strOutputLine8), strFile);
- GetPrivateProfileString("output", "line9", "", g_strOutputLine9, sizeof(g_strOutputLine9), strFile);
- GetPrivateProfileString("output", "line10", "", g_strOutputLine10, sizeof(g_strOutputLine10), strFile);
- g_nOutputLineCount1 = GetPrivateProfileInt("output", "lineCount1", 0, strFile);
- g_nOutputLineCount2 = GetPrivateProfileInt("output", "lineCount2", 0, strFile);
- g_nOutputLineCount3 = GetPrivateProfileInt("output", "lineCount3", 0, strFile);
- g_nOutputLineCount4 = GetPrivateProfileInt("output", "lineCount4", 0, strFile);
- g_nOutputLineCount5 = GetPrivateProfileInt("output", "lineCount5", 0, strFile);
- g_nOutputLineCount6 = GetPrivateProfileInt("output", "lineCount6", 0, strFile);
- g_nOutputLineCount7 = GetPrivateProfileInt("output", "lineCount7", 0, strFile);
- g_nOutputLineCount8 = GetPrivateProfileInt("output", "lineCount8", 0, strFile);
- g_nOutputLineCount9 = GetPrivateProfileInt("output", "lineCount9", 0, strFile);
- g_nOutputLineCount10 = GetPrivateProfileInt("output", "lineCount10", 0, strFile);
- GetPrivateProfileString("output", "lineUid1", "", g_strOutputLineUid1, sizeof(g_strOutputLineUid1), strFile);
- GetPrivateProfileString("output", "lineUid2", "", g_strOutputLineUid2, sizeof(g_strOutputLineUid2), strFile);
- GetPrivateProfileString("output", "lineUid3", "", g_strOutputLineUid3, sizeof(g_strOutputLineUid3), strFile);
- GetPrivateProfileString("output", "lineUid4", "", g_strOutputLineUid4, sizeof(g_strOutputLineUid4), strFile);
- GetPrivateProfileString("output", "lineUid5", "", g_strOutputLineUid5, sizeof(g_strOutputLineUid5), strFile);
- GetPrivateProfileString("output", "lineUid6", "", g_strOutputLineUid6, sizeof(g_strOutputLineUid6), strFile);
- GetPrivateProfileString("output", "lineUid7", "", g_strOutputLineUid7, sizeof(g_strOutputLineUid7), strFile);
- GetPrivateProfileString("output", "lineUid8", "", g_strOutputLineUid8, sizeof(g_strOutputLineUid8), strFile);
- GetPrivateProfileString("output", "lineUid9", "", g_strOutputLineUid9, sizeof(g_strOutputLineUid9), strFile);
- GetPrivateProfileString("output", "lineUid10", "", g_strOutputLineUid10, sizeof(g_strOutputLineUid10), strFile);
- g_nSnmpEnable = GetPrivateProfileInt("Snmp", "Enable", 0, strFile);
- GetPrivateProfileString("Snmp", "ObjOid", "", g_strSnmpObjOid, sizeof(g_strSnmpObjOid), strFile);
- GetPrivateProfileString("Snmp", "IP", "", g_strSnmpIP, sizeof(g_strSnmpIP), strFile);
- GetPrivateProfileString("Snmp", "Field", "", g_strSnmpField, sizeof(g_strSnmpField), strFile);
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- //增加自动启动注册表项
- #if 0
- wsprintf(strFile, "%s\\%s", g_strDirectory, g_strAppName);
- AddAutoSysRun(strFile, g_iAutoRunSystem);
- #endif
- return 0;
- }
- int GetResourceString()
- {
- g_strServiceName.LoadString(IDS_SERVICE_NAME);
- g_strHintSysRun.LoadString(IDS_HINT_SYS_RUN);
- g_strHintAlarmWelcome.LoadString(IDS_HINT_ALARM_WELCOME);
- g_strHintVoiceEnd.LoadString(IDS_HINT_VOICE_END);
- g_strHintReturnNormal.LoadString(IDS_HINT_RETURN_NORMAL);
- g_strHintUpperLimit.LoadString(IDS_HINT_UPPER_LIMIT);
- g_strHintLowerLimit.LoadString(IDS_HINT_LOWER_LIMIT);
- g_strHintCurrValue.LoadString(IDS_HINT_CURR_VALUE);
- return 0;
- }
- VOID TerminateLastProcess()
- {
- HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- if (hSnapShot != NULL)
- {
- PROCESSENTRY32 ProcessInfo = {0};//声明进程信息变量
- ProcessInfo.dwSize = sizeof(ProcessInfo);//设置ProcessInfo的大小
- //返回系统中第一个进程的信息
- BOOL bStatus = Process32First(hSnapShot, &ProcessInfo);
- while (bStatus)
- {
- if (!_stricmp(g_strAppName, ProcessInfo.szExeFile))//映像名称
- {
- HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessInfo.th32ProcessID);
- ::TerminateProcess(hProcess, 1);
- hProcess = NULL;
- Sleep(1000);
- break;
- }
- else
- //获取下一个进程的信息
- bStatus = Process32Next(hSnapShot, &ProcessInfo);
- }
- }
- }
- //-------------------------------------------------------------------------------------
- //Description:
- // This function maps a character string to a wide-character (Unicode) string
- //
- //Parameters:
- // lpcszStr: [in] Pointer to the character string to be converted
- // lpwszStr: [out] Pointer to a buffer that receives the translated string.
- // dwSize: [in] Size of the buffer
- //
- //Return Values:
- // TRUE: Succeed
- // FALSE: Failed
- //
- //Example:
- // MByteToWChar(szA,szW,sizeof(szW)/sizeof(szW[0]));
- //---------------------------------------------------------------------------------------
- BOOL MByteToWChar(LPCSTR lpcszStr, LPWSTR lpwszStr, DWORD dwSize)
- {
- // Get the required size of the buffer that receives the Unicode
- // string.
- DWORD dwMinSize;
- dwMinSize = MultiByteToWideChar (CP_ACP, 0, lpcszStr, -1, NULL, 0);
- if(dwSize < dwMinSize)
- {
- return FALSE;
- }
-
- // Convert headers from ASCII to Unicode.
- MultiByteToWideChar (CP_ACP, 0, lpcszStr, -1, lpwszStr, dwMinSize);
- return TRUE;
- }
- //-------------------------------------------------------------------------------------
- //Description:
- // This function maps a wide-character string to a new character string
- //
- //Parameters:
- // lpcwszStr: [in] Pointer to the character string to be converted
- // lpszStr: [out] Pointer to a buffer that receives the translated string.
- // dwSize: [in] Size of the buffer
- //
- //Return Values:
- // TRUE: Succeed
- // FALSE: Failed
- //
- //Example:
- // MByteToWChar(szW,szA,sizeof(szA)/sizeof(szA[0]));
- //---------------------------------------------------------------------------------------
- BOOL WCharToMByte(LPCWSTR lpcwszStr, LPSTR lpszStr, DWORD dwSize)
- {
- DWORD dwMinSize;
- dwMinSize = WideCharToMultiByte(CP_OEMCP,NULL,lpcwszStr,-1,NULL,0,NULL,FALSE);
- if(dwSize < dwMinSize)
- {
- return FALSE;
- }
- WideCharToMultiByte(CP_OEMCP,NULL,lpcwszStr,-1,lpszStr,dwSize,NULL,FALSE);
- return TRUE;
- }
- //////////////////////////////////////////////////////////////////////////////
- //名称:GetExcelDriver
- //功能:获取ODBC中Excel驱动
- //作者:徐景周(jingzhou_xu@163.net)
- //组织:未来工作室(Future Studio)
- //日期:2002.9.1
- /////////////////////////////////////////////////////////////////////////////
- CString GetExcelDriver()
- {
- char szBuf[2001];
- WORD cbBufMax = 2000;
- WORD cbBufOut;
- char *pszBuf = szBuf;
- CString sDriver;
-
- // 获取已安装驱动的名称(涵数在odbcinst.h里)
- if (!SQLGetInstalledDrivers(szBuf, cbBufMax, &cbBufOut))
- return "";
-
- // 检索已安装的驱动是否有Excel...
- do
- {
- if (strstr(pszBuf, "Excel") != 0)
- {
- //发现 !
- sDriver = CString(pszBuf);
- break;
- }
- pszBuf = strchr(pszBuf, '\0') + 1;
- }
- while (pszBuf[1] != '\0');
-
- return sDriver;
- }
- ///////////////////////////////////////////////////////////////////////////////
- // BOOL MakeSurePathExists( CString &Path,bool FilenameIncluded)
- // 参数:
- // Path 路径
- // FilenameIncluded 路径是否包含文件名
- // 返回值:
- // 文件是否存在
- // 说明:
- // 判断Path文件(FilenameIncluded=true)是否存在,存在返回TURE,不存在返回FALSE
- // 自动创建目录
- //
- ///////////////////////////////////////////////////////////////////////////////
- BOOL MakeSurePathExists( CString &Path,
- bool FilenameIncluded)
- {
- int Pos=0;
- while((Pos=Path.Find('\\',Pos+1))!=-1)
- CreateDirectory(Path.Left(Pos),NULL);
- if(!FilenameIncluded)
- CreateDirectory(Path,NULL);
- // return ((!FilenameIncluded)?!_access(Path,0):
- // !_access(Path.Left(Path.ReverseFind('\\')),0));
-
- return !_access(Path,0);
- }
- int GetSensorType( CString strSensorType )
- {
- /*int nSensorType;
- if( !strSensorType.Compare((char*)(LPCTSTR)g_strTempTypeDesc) )
- {
- nSensorType = 1;
- }
- else if( !strSensorType.Compare((char*)(LPCTSTR)g_str4To20TypeDesc) )
- {
- nSensorType = 2;
- }
- else if( !strSensorType.Compare((char*)(LPCTSTR)g_strHumidityTypeDesc) )
- {
- nSensorType = 3;
- }
- else if( !strSensorType.Compare("Water") )
- {
- nSensorType = 4;
- }
- else if( !strSensorType.Compare((char*)(LPCTSTR)g_strDCTypeDesc) )
- {
- nSensorType = 5;
- }
- else if( !strSensorType.Compare((char*)(LPCTSTR)g_strSecurityTypeDesc) )
- {
- nSensorType = 6;
- }
- else if( !strSensorType.Compare("Airflow") )
- {
- nSensorType = 8;
- }
- else if( !strSensorType.Compare("Siren") )
- {
- nSensorType = 9;
- }
- else if( !strSensorType.Compare((char*)(LPCTSTR)g_strDryTypeDesc) )
- {
- nSensorType = 10;
- }
- else if( !strSensorType.Compare("AC Voltage") )
- {
- nSensorType = 12;
- }
- else if( !strSensorType.Compare((char*)(LPCTSTR)g_strRelayTypeDesc) )
- {
- nSensorType = 13;
- }
- else if( !strSensorType.Compare(SENSOR_AI_DESC) )
- {
- nSensorType = 20;
- }
- else if( !strSensorType.Compare(SENSOR_DI_DESC) )
- {
- nSensorType = 21;
- }
- else if( !strSensorType.Compare(SENSOR_DO_DESC) )
- {
- nSensorType = 22;
- }
- else
- {
- nSensorType = 0;
- }
- return nSensorType;*/
- return true;
- }
- CString GetSensorType( int nSensorType )
- {
- /* CString strSensorType = "";
- switch( nSensorType )
- {
- case 1:
- strSensorType = CString(" ") + g_strTempTypeDesc;
- break;
- case 2:
- strSensorType = CString(" ") + g_str4To20TypeDesc;
- break;
- case 3:
- strSensorType = CString(" ") + g_strHumidityTypeDesc;
- break;
- case 4:
- strSensorType = " Water";
- break;
- case 5:
- strSensorType = CString(" ") + g_strDCTypeDesc;
- break;
- case 6:
- strSensorType = CString(" ") + g_strSecurityTypeDesc;
- break;
- case 8:
- strSensorType = " Airflow";
- break;
- case 9:
- strSensorType = " Siren";
- break;
- case 10:
- strSensorType = CString(" ") + g_strDryTypeDesc;
- break;
- case 12:
- strSensorType = " AC Voltage";
- break;
- case 13:
- strSensorType = CString(" ") + g_strRelayTypeDesc;
- break;
- case 14:
- strSensorType = " Motion";
- break;
- case 20:
- strSensorType = " AI";
- break;
- case 21:
- strSensorType = " DI";
- break;
- case 22:
- strSensorType = " DO";
- break;
- }
- return strSensorType;*/
- return "";
- }
- CString InterceptString(int qlen, CString strSource)
- {
- int len,i,y;
- CString sTemp,sreturn;
- strSource.TrimLeft();
- strSource.TrimRight();
- len=strSource.GetLength();
- y=0;
- sTemp=strSource.Right(len-qlen);
- for(i=0;i<len;i++)
- {
- //if(sTemp[y]<0 || sTemp[y]>255)
- //if(sTemp[i]<0 || sTemp[i]>=128)
- //if(sTemp.GetAt(y) & 0x80 )
- if(::IsDBCSLeadByte(sTemp.GetAt(y)))
- y=y+2;
- else
- y=y+1;
- if(y>=70)
- break;
- }
- sreturn=sTemp.Left(y);
- return sreturn;
- }
- //显示选择文件夹窗口
- //参数 sFolderPath:用于返回用户选择的文件夹的路径
- //参数 sTitle:用于指定选择文件夹窗口的标题
- //返回值 :操作结果,用户取消选择或操作失败返回FALSE,否则TRUE
- BOOL BrowseForFolder(CString & sFolderPath, CString sTitle)
- {
- BROWSEINFO bi;
- char Buffer[_MAX_PATH];
- bi.hwndOwner = NULL;
- bi.pidlRoot = NULL;
- bi.pszDisplayName = Buffer;
- bi.lpszTitle = sTitle;
- bi.ulFlags = 0;
- bi.lpfn = NULL;
- LPITEMIDLIST pIDList = SHBrowseForFolder(& bi);
- if (!pIDList)
- return FALSE;
- SHGetPathFromIDList(pIDList, Buffer);
- sFolderPath = Buffer;
- LPMALLOC lpMalloc;
- if (FAILED(SHGetMalloc(& lpMalloc)))
- return FALSE;
-
- //释放内存
- lpMalloc->Free(pIDList);
- lpMalloc->Release();
-
- return TRUE;
- }
- void TimeTicksToInt(CString strSrc, unsigned long &nDest)
- {
- CString strLeft;
- int nIndex = strSrc.Find(":");
- if( nIndex != -1 )
- {
- strLeft = strSrc.Left( nIndex - 1 );
- nDest = atoi(strLeft);
- }
- }
- unsigned int CalcCheckSum( void *pData, unsigned int nSize )
- {
- unsigned int checksum = 0;
- if ( nSize <= sizeof( ProtocolHeader ) )
- {
- return 0;
- }
- unsigned char *pBody = &( ( unsigned char* )pData )[ sizeof( ProtocolHeader ) ];
- nSize -= sizeof( ProtocolHeader );
- if( pBody )
- {
- checksum = crc32( 0, pBody, nSize );
- }
- return checksum;
- }
- int SplitStr(CHAR *strSource, CHAR cChar, int iItem, CHAR *strGet)
- {
- int iIndex = 0;
- int iIndexThis = -1;
- int iIndexNext = -1;
- int iLength = 0;
- int iItemThis = 0;
- CHAR strFileName[MAX_FILE_LENGTH + 1] = "";
-
-
- iLength = strlen(strSource);
- while (iIndex < iLength)
- {
- if (strSource[iIndex] == cChar)
- {
- iItemThis++;
- if (iItemThis == iItem)
- iIndexThis = iIndex;
- else if (iItemThis == iItem + 1)
- {
- iIndexNext = iIndex;
- break;
- }
- }
-
- iIndex++;
- }
-
- if (iIndexNext > 0 && iIndexNext > iIndexThis)
- {
- memcpy(strGet, strSource + iIndexThis + 1, iIndexNext - iIndexThis - 1);
- strGet[iIndexNext - iIndexThis - 1] = '\0';
- }
- else
- strcpy(strGet, "");
-
- return 0;
- }
|