12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076 |
- #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>
- #include "Shlwapi.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, "DataBase Monitor Service", NULL, REG_SZ, (BYTE*)strExeFile, (DWORD)strlen(strExeFile));
- else
- dwErrorCode = RegDeleteKey(hKey, "DataBase Monitor Service");
- }
- 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\\ServicesInfo.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);
- int nStdOut = GetPrivateProfileInt("WatchServer", "StdOut", 0, strFile);
- if ( nStdOut == 1 )
- {
- AllocConsole(); // 开辟控制台;
- SetConsoleTitle(_T("EMSoftServices调试输出")); // 设置控制台窗口标题;
- freopen("CONOUT$", "w+t", stdout); // 重定向输出;
- freopen("CONIN$", "r+t", stdin); // 重定向输入;
- HWND hWnd = NULL;
- again:
- hWnd = ::FindWindow(NULL, _T("EMSoftServices调试输出"));
- if( hWnd )
- {
- if (!::SetWindowPos(hWnd, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE))
- {
- printf(_T("前置设置失败\n"));
- }
- else
- {
- printf(_T("前置设置成功\n"));
- }
- }
- else
- {
- nStdOut++;
- if ( nStdOut <= 10 )
- goto again;
- }
- }
- // 语言;
- 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);
- g_dwDataBasePort = GetPrivateProfileInt("Database", "DataBasePort", 5432, strFile);
- //数据库连接串;
- if (!_stricmp(g_strDBType, "SQL SERVER"))
- sprintf(g_strConnectString, "Provider=sqloledb;Data Source=%s,1433;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=%d; DATABASE=%s; UID=%s; PWD=%s;",
- g_strServerName, g_dwDataBasePort, 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);
- GetPrivateProfileString("Common", "NoticePre", "", g_strNoticePre, sizeof(g_strNoticePre), strFile);
- GetPrivateProfileString("Common","NoticeDelay","",strValue,sizeof(strValue),strFile);
- g_nNoticeDelay = atoi( strValue );
- if( g_nNoticeDelay<=0 || g_nNoticeDelay>600 )
- g_nNoticeDelay = 20;
- GetPrivateProfileString("Common","EncryptionType","",strValue,sizeof(strValue),strFile);
- g_nEncryptionType = atoi( strValue );
- if( g_nEncryptionType>1 && g_nEncryptionType!=476 )
- g_nEncryptionType = 0;
- //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_bSendVoice = 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);
- g_nTTSRate = GetPrivateProfileInt("TTS", "VoiceRate", 0, strFile);
- g_nTTSVolume = GetPrivateProfileInt("TTS", "VoiceVolume", 0, strFile);
- if( g_nTTSType<0 )
- g_nTTSType = 0;
- if( g_nTTSType>100 )
- g_nTTSType = 0;
- if( g_nTTSRate<-10 )
- g_nTTSRate = -10;
- if( g_nTTSRate>10 )
- g_nTTSRate = 10;
- if( g_nTTSVolume<=0 )
- g_nTTSVolume = 100;
- if( g_nTTSVolume>100 )
- g_nTTSVolume = 100;
- //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);
- //Log文件
- GetPrivateProfileString("Other", "SummaryLog", "", g_strSummaryLogPath, sizeof(g_strSummaryLogPath), strFile);
- g_nLogSaveTimes = GetPrivateProfileInt("Other", "LogSaveTimes", 0, strFile);
- if( g_nLogSaveTimes<=6 )
- g_nLogSaveTimes = 6;
- //定时发送短信和电话参数配置
- 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_nTimingPreiods = GetPrivateProfileInt("Timing", "Preiod", 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", "OidRoot", "", g_strSnmpOidRoot, sizeof(g_strSnmpOidRoot), 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);
- g_strHintBlance.LoadString(IDS_NOTICE_BLANCE);
- g_strHintDateLimit.LoadString(IDS_NOTICE_DATELIMIT);
- 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;
- }
|