lyfzSMSHandle.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // lyfzSMSHandle.cpp : 定义应用程序的类行为。
  2. //
  3. #include "stdafx.h"
  4. #include "lyfzSMSHandle.h"
  5. #include "lyfzSMSHandleDlg.h"
  6. #include "Global.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #endif
  10. HANDLE g_hMutex = NULL; // 全局互斥量;
  11. // ClyfzSMSHandleApp
  12. BEGIN_MESSAGE_MAP(ClyfzSMSHandleApp, CWinAppEx)
  13. ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
  14. END_MESSAGE_MAP()
  15. // ClyfzSMSHandleApp 构造
  16. ClyfzSMSHandleApp::ClyfzSMSHandleApp()
  17. {
  18. // TODO: 在此处添加构造代码,
  19. // 将所有重要的初始化放置在 InitInstance 中
  20. }
  21. // 唯一的一个 ClyfzSMSHandleApp 对象
  22. ClyfzSMSHandleApp theApp;
  23. // ClyfzSMSHandleApp 初始化
  24. BOOL ClyfzSMSHandleApp::InitInstance()
  25. {
  26. g_hMutex = ::CreateMutex(NULL,FALSE,_T("lyfzSMSHandle"));
  27. if( GetLastError() == ERROR_ALREADY_EXISTS )
  28. {
  29. ::MessageBox(NULL,_T("短信处理程序已经打开!"),_T("温馨提示"),MB_ICONINFORMATION);
  30. return FALSE;
  31. }
  32. // 如果一个运行在 Windows XP 上的应用程序清单指定要
  33. // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
  34. //则需要 InitCommonControlsEx()。否则,将无法创建窗口。
  35. INITCOMMONCONTROLSEX InitCtrls;
  36. InitCtrls.dwSize = sizeof(InitCtrls);
  37. // 将它设置为包括所有要在应用程序中使用的
  38. // 公共控件类。
  39. InitCtrls.dwICC = ICC_WIN95_CLASSES;
  40. InitCommonControlsEx(&InitCtrls);
  41. CWinAppEx::InitInstance();
  42. AfxEnableControlContainer();
  43. // 标准初始化
  44. // 如果未使用这些功能并希望减小
  45. // 最终可执行文件的大小,则应移除下列
  46. // 不需要的特定初始化例程
  47. // 更改用于存储设置的注册表项
  48. // TODO: 应适当修改该字符串,
  49. // 例如修改为公司或组织名
  50. SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
  51. #if JEFF_TEST_ON
  52. if(GetSysIniInfo() == -1)
  53. {
  54. // 若没有找到Server.ini文件,则默认没有放在DBServer.exe所有的主机上;
  55. if ( GetSysIniInfo2() == -1)
  56. {
  57. AfxMessageBox(_T("没有找到配置文件"));
  58. return FALSE;
  59. }
  60. // 配置加密狗类型;
  61. g_nVersion = g_dwEncryType;
  62. }
  63. else
  64. {
  65. #ifndef NOYT
  66. if(GetSoftWareVersion() == -1)
  67. {
  68. AfxMessageBox(_T("没有找到加密狗,请确认是否有加密狗!"));
  69. return FALSE;
  70. }
  71. #endif
  72. }
  73. WSADATA WSAData = { 0 };
  74. if(0 != WSAStartup(MAKEWORD(2, 2), &WSAData))
  75. {
  76. AfxMessageBox(_T("网络环境初始化失败!"));
  77. return FALSE;
  78. }
  79. else
  80. {
  81. DWORD dwServerIP = 0;
  82. #ifdef UNICODE
  83. char szHost[MAX_PATH] = {0};
  84. strcpy_s(szHost,CW2A(g_szSMSServer));
  85. HOSTENT *host = gethostbyname(szHost); // Jeff.所有本机的网络适配器;
  86. #else
  87. HOSTENT *host = gethostbyname(g_szSMSServer); // Jeff.所有本机的网络适配器;
  88. #endif
  89. struct in_addr addr;
  90. if (host != NULL)
  91. {
  92. // Jeff.遍历本机所有适配器的IP地址;
  93. CString strSvrIP = _T("");
  94. for (int i = 0; host->h_addr_list[i] != NULL; i++)
  95. {
  96. memset(&addr, 0, sizeof(addr));
  97. memcpy(&addr.S_un.S_addr, host->h_addr_list[i], host->h_length);
  98. dwServerIP = ntohl(addr.S_un.S_addr);
  99. BYTE* pIP = (BYTE*)&dwServerIP;
  100. g_strServerIP.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]);
  101. WriteTextLog("域名IP:%s",g_strServerIP);
  102. break;
  103. }
  104. }
  105. else
  106. {
  107. WriteTextLog("DNS服务器解析域名IP失败,有可能是服务器DNS异常,请使用360等工具修复!");
  108. }
  109. }
  110. #endif
  111. ClyfzSMSHandleDlg dlg;
  112. m_pMainWnd = &dlg;
  113. INT_PTR nResponse = dlg.DoModal();
  114. if (nResponse == IDOK)
  115. {
  116. // TODO: 在此放置处理何时用
  117. // “确定”来关闭对话框的代码
  118. }
  119. else if (nResponse == IDCANCEL)
  120. {
  121. // TODO: 在此放置处理何时用
  122. // “取消”来关闭对话框的代码
  123. }
  124. // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
  125. // 而不是启动应用程序的消息泵。
  126. return FALSE;
  127. }
  128. int ClyfzSMSHandleApp::ExitInstance()
  129. {
  130. // TODO: 在此添加专用代码和/或调用基类
  131. WriteTextLog("退出log日志");
  132. CloseHandle(g_hMutex);
  133. return CWinAppEx::ExitInstance();
  134. }