StdAfx.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // stdafx.cpp : source file that includes just the standard includes
  2. // UPhoneBox.pch will be the pre-compiled header
  3. // stdafx.obj will contain the pre-compiled type information
  4. #include "stdafx.h"
  5. DWORD g_dwCSPort = 5678;
  6. TCHAR g_szModulePath[MAX_PATH] = {0};
  7. TCHAR g_szModuleFileName[MAX_PATH] = {0};
  8. TCHAR g_szHostComputerIP[MAX_PATH] = {0};
  9. BOOL g_bStdOut = FALSE;
  10. //************************************//
  11. // 数据库地址;
  12. // 数据库端口;
  13. // 数据库管理员账号;
  14. // 数据库管理员密码;
  15. // 数据库名称;
  16. //
  17. // [函数]:GetIniInfo
  18. // [描述]:获取指定ini信息;
  19. // [参数]:
  20. // szPath:ini所在目录;
  21. // szIniName:ini名;
  22. // [返回]:void
  23. //************************************//
  24. int GetSysIniInfo(const char *szPath, const char *szIniName)
  25. {
  26. TCHAR szDrive[_MAX_DRIVE] = { 0 };
  27. TCHAR szDir[_MAX_DIR] = { 0 };
  28. TCHAR szFna[_MAX_DIR] = { 0 };
  29. TCHAR szExt[_MAX_DIR] = { 0 };
  30. ::GetModuleFileName(NULL, g_szModuleFileName, sizeof(g_szModuleFileName) / sizeof(TCHAR));
  31. #ifndef VC60
  32. sprintf(g_szModulePath, _T("%s"), g_szModuleFileName);
  33. _tsplitpath(g_szModulePath, szDrive, szDir, szFna, szExt);
  34. _tcscpy(g_szModulePath, szDrive);
  35. _tcscat(g_szModulePath, szDir);
  36. #else
  37. _stprintf_s(g_szModulePath, MAX_PATH, _T("%s"), g_szModuleFileName);
  38. _tsplitpath_s(g_szModulePath, szDrive, _MAX_DRIVE, szDir, _MAX_DIR, szFna, _MAX_DIR, szExt, _MAX_DIR);
  39. _tcscpy_s(g_szModulePath, MAX_PATH, szDrive);
  40. _tcscat_s(g_szModulePath, MAX_PATH, szDir);
  41. #endif
  42. // -----------------------------------------------------//
  43. TCHAR szFile[MAX_PATH + 1] = "";
  44. if (szPath != NULL && szIniName != NULL)
  45. wsprintf(szFile, _T("%s\\%s"), szPath, szIniName);
  46. else
  47. wsprintf(szFile, _T("%s\\HostInfo.ini"), g_szModulePath);
  48. TRACE("szFile =%s\n", szFile);
  49. OFSTRUCT ofStruct;
  50. OpenFile(szFile, &ofStruct, OF_EXIST); // Jeff 这是为了兼容16位系统遗留的函数,不应该使用;
  51. if (ERROR_FILE_NOT_FOUND == GetLastError())
  52. {
  53. // 如果没找到,使用默认连接;
  54. strcpy(g_szHostComputerIP, _T("."));
  55. g_dwCSPort = 5678;
  56. // 不存在则创建;
  57. CFile fp;
  58. if( fp.Open(szFile,CFile::modeCreate|CFile::modeWrite) )
  59. {
  60. fp.Close();
  61. }
  62. WritePrivateProfileString(_T("NetWorkInfo"),_T("Host"),_T("127.0.0.1"),szFile);
  63. WritePrivateProfileString(_T("NetWorkInfo"),_T("CSPort"),_T("5678"),szFile);
  64. }
  65. // 获取服务器端TCP信息;
  66. GetPrivateProfileString(_T("NetWorkInfo"), _T("Host"), _T(""), g_szHostComputerIP, MAX_PATH, szFile);
  67. g_dwCSPort = GetPrivateProfileInt(_T("NetWorkInfo"), _T("CSPort"), 0, szFile);
  68. int nIndex = 0;
  69. g_bStdOut = GetPrivateProfileInt(_T("NetWorkInfo"), _T("StdOut"), 0, szFile);
  70. if ( g_bStdOut )
  71. {
  72. AllocConsole(); // 开辟控制台;
  73. SetConsoleTitle(_T("lyfz来电精灵调试输出")); // 设置控制台窗口标题;
  74. freopen("CONOUT$", "w+t", stdout); // 重定向输出;
  75. freopen("CONIN$", "r+t", stdin); // 重定向输入;
  76. HWND hWnd = NULL;
  77. again:
  78. hWnd = ::FindWindow(NULL, _T("lyfz来电精灵调试输出"));
  79. if( hWnd )
  80. {
  81. if (!::SetWindowPos(hWnd, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE))
  82. {
  83. printf(_T("前置设置失败\n"));
  84. }
  85. else
  86. {
  87. printf(_T("前置设置成功\n"));
  88. }
  89. }
  90. else
  91. {
  92. if ( nIndex <= 10 )
  93. goto again;
  94. }
  95. }
  96. return 0;
  97. }