123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- // stdafx.cpp : source file that includes just the standard includes
- // UPhoneBox.pch will be the pre-compiled header
- // stdafx.obj will contain the pre-compiled type information
- #include "stdafx.h"
- DWORD g_dwCSPort = 5678;
- TCHAR g_szModulePath[MAX_PATH] = {0};
- TCHAR g_szModuleFileName[MAX_PATH] = {0};
- TCHAR g_szHostComputerIP[MAX_PATH] = {0};
- BOOL g_bStdOut = FALSE;
- //************************************//
- // 数据库地址;
- // 数据库端口;
- // 数据库管理员账号;
- // 数据库管理员密码;
- // 数据库名称;
- //
- // [函数]:GetIniInfo
- // [描述]:获取指定ini信息;
- // [参数]:
- // szPath:ini所在目录;
- // szIniName:ini名;
- // [返回]:void
- //************************************//
- int GetSysIniInfo(const char *szPath, const char *szIniName)
- {
- TCHAR szDrive[_MAX_DRIVE] = { 0 };
- TCHAR szDir[_MAX_DIR] = { 0 };
- TCHAR szFna[_MAX_DIR] = { 0 };
- TCHAR szExt[_MAX_DIR] = { 0 };
- ::GetModuleFileName(NULL, g_szModuleFileName, sizeof(g_szModuleFileName) / sizeof(TCHAR));
- #ifndef VC60
- sprintf(g_szModulePath, _T("%s"), g_szModuleFileName);
- _tsplitpath(g_szModulePath, szDrive, szDir, szFna, szExt);
- _tcscpy(g_szModulePath, szDrive);
- _tcscat(g_szModulePath, szDir);
- #else
- _stprintf_s(g_szModulePath, MAX_PATH, _T("%s"), g_szModuleFileName);
- _tsplitpath_s(g_szModulePath, szDrive, _MAX_DRIVE, szDir, _MAX_DIR, szFna, _MAX_DIR, szExt, _MAX_DIR);
- _tcscpy_s(g_szModulePath, MAX_PATH, szDrive);
- _tcscat_s(g_szModulePath, MAX_PATH, szDir);
- #endif
- // -----------------------------------------------------//
- TCHAR szFile[MAX_PATH + 1] = "";
- if (szPath != NULL && szIniName != NULL)
- wsprintf(szFile, _T("%s\\%s"), szPath, szIniName);
- else
- wsprintf(szFile, _T("%s\\HostInfo.ini"), g_szModulePath);
- TRACE("szFile =%s\n", szFile);
- OFSTRUCT ofStruct;
- OpenFile(szFile, &ofStruct, OF_EXIST); // Jeff 这是为了兼容16位系统遗留的函数,不应该使用;
- if (ERROR_FILE_NOT_FOUND == GetLastError())
- {
- // 如果没找到,使用默认连接;
- strcpy(g_szHostComputerIP, _T("."));
- g_dwCSPort = 5678;
- // 不存在则创建;
- CFile fp;
- if( fp.Open(szFile,CFile::modeCreate|CFile::modeWrite) )
- {
- fp.Close();
- }
- WritePrivateProfileString(_T("NetWorkInfo"),_T("Host"),_T("127.0.0.1"),szFile);
- WritePrivateProfileString(_T("NetWorkInfo"),_T("CSPort"),_T("5678"),szFile);
- }
- // 获取服务器端TCP信息;
- GetPrivateProfileString(_T("NetWorkInfo"), _T("Host"), _T(""), g_szHostComputerIP, MAX_PATH, szFile);
- g_dwCSPort = GetPrivateProfileInt(_T("NetWorkInfo"), _T("CSPort"), 0, szFile);
- int nIndex = 0;
- g_bStdOut = GetPrivateProfileInt(_T("NetWorkInfo"), _T("StdOut"), 0, szFile);
- if ( g_bStdOut )
- {
- AllocConsole(); // 开辟控制台;
- SetConsoleTitle(_T("lyfz来电精灵调试输出")); // 设置控制台窗口标题;
- freopen("CONOUT$", "w+t", stdout); // 重定向输出;
- freopen("CONIN$", "r+t", stdin); // 重定向输入;
- HWND hWnd = NULL;
- again:
- hWnd = ::FindWindow(NULL, _T("lyfz来电精灵调试输出"));
- if( hWnd )
- {
- if (!::SetWindowPos(hWnd, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE))
- {
- printf(_T("前置设置失败\n"));
- }
- else
- {
- printf(_T("前置设置成功\n"));
- }
- }
- else
- {
- if ( nIndex <= 10 )
- goto again;
- }
- }
- return 0;
- }
|