首页
社区
课程
招聘
[分享]利用邮箱实现bug提交和自动检查更新
发表于: 2013-2-27 14:19 9079

[分享]利用邮箱实现bug提交和自动检查更新

2013-2-27 14:19
9079

看了下邮件的发送与接收,了解了这方面知识,写一个帖子。

1、设置捕获

int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE h0, LPTSTR lpCmdLine, int nCmdShow)
 {
     BOOL bRet;
     MSG msg;
     HWND hwndFrame;
     
  [B][COLOR="Red"]   g_previousFilter = SetUnhandledExceptionFilter(TopLevelExceptionFilter);[/COLOR][/B]
     //_CrtSetBreakAlloc(58);
     InitCommonControls();
     g_hInst = hInst;
     //hModUxTheme = LoadLibrary(L"uxtheme.dll");
     //注册框架窗口类
   //创建框架窗口   
   //消息泵

     //if (hModUxTheme)
     //FreeLibrary(hModUxTheme);
     _CrtDumpMemoryLeaks();
     return (int) bRet;
 } 

LONG WINAPI TopLevelExceptionFilter(struct _EXCEPTION_POINTERS *pExceptionInfo)
 {
     SYSTEMTIME time;
     LONG lRet = EXCEPTION_CONTINUE_SEARCH;
     //HRESULT hr ;
     int end;
     GetLocalTime(&time);
     char acBuf[MAX_PATH] = {0};
     // Build a string showing the date and time.
     //Returns the number of characters written to the buffer, excluding any terminating NULL characters. A negative value is returned if an error occurs.
     end = wnsprintfA(acBuf, MAX_PATH, "%d%02d%02d%02d%02d%02d.dmp",time.wYear,
         time.wMonth, time.wDay,time.wHour, time.wMinute,time.wSecond);
     
     if(end > 0)
     {
         HANDLE hFile;
         char szBugFile[MAX_PATH+1] = {0};
         GetModuleFileNameA(NULL,szBugFile,MAX_PATH + 1);
         PathRemoveFileSpecA(szBugFile);
         PathAppendA(szBugFile,acBuf);
         hFile = CreateFileA(szBugFile,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL); 

         if(hFile == INVALID_HANDLE_VALUE) 
         { 
             ;
             //WriteLog(_T("ExceptionInfo"),_T("CreateFile"),_T("-1"));
         }else{
             BOOL (__stdcall *fnMiniDumpWriteDump)(HANDLE,DWORD,HANDLE,MINIDUMP_TYPE,
                 PMINIDUMP_EXCEPTION_INFORMATION, PMINIDUMP_USER_STREAM_INFORMATION,PMINIDUMP_CALLBACK_INFORMATION); 
             //typedef BOOL (__stdcall *MiniDumpWriteDumpProc)(HANDLE,DWORD,HANDLE,MINIDUMP_TYPE,
             //PMINIDUMP_EXCEPTION_INFORMATION, PMINIDUMP_USER_STREAM_INFORMATION,PMINIDUMP_CALLBACK_INFORMATION);
             HINSTANCE hinstLib; 
             //BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; 
             //MiniDumpWriteDumpProc fnMiniDumpWriteDump;
             hinstLib = LoadLibrary(TEXT("DbgHelp.dll")); 

             if(hinstLib)
             {
                 (FARPROC&)fnMiniDumpWriteDump = ::GetProcAddress(hinstLib, "MiniDumpWriteDump");
                 //fnMiniDumpWriteDump = ( MiniDumpWriteDumpProc)::GetProcAddress(hinstLib, _T("MiniDumpWriteDump"));
                 if(fnMiniDumpWriteDump )
                 {
                     MINIDUMP_EXCEPTION_INFORMATION info;
                     info.ThreadId = ::GetCurrentThreadId();
                     info.ExceptionPointers = pExceptionInfo;
                     info.ClientPointers = FALSE;
                     BOOL bOk = fnMiniDumpWriteDump(::GetCurrentProcess,::GetCurrentProcessId(),hFile,MiniDumpNormal,&info,NULL,NULL);
                     if(bOk == FALSE) 
                         WriteLog(_T("ExceptionInfo"),_T("MiniDumpWriteDump"),_T("error(0x%x)"),GetLastError());
                     HWND hBug = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_BUGDLG), NULL, (DLGPROC)BugDlgProc,(LPARAM)&info);
                     SetWindowLong(hBug,GWL_USERDATA,(LONG)szBugFile);
                     ShowWindow(hBug,SW_NORMAL);
                     BOOL bRet;
                     MSG msg;
                     while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) 
                     { 
                         if (bRet == -1)
                         {
                             // Handle the error and possibly exit
                             break;
                         }
                         else if (!IsWindow(hBug) || !IsDialogMessage(hBug, &msg)) 
                         { 
                             TranslateMessage(&msg); 
                             DispatchMessage(&msg); 
                         } 
                     }
                     lRet = EXCEPTION_EXECUTE_HANDLER;
                 }else
                     WriteLog(_T("ExceptionInfo"),_T("MiniDumpWriteDump"),_T("Failed to get"));
                 FreeLibrary(hinstLib); 
             }else
                 WriteLog(_T("ExceptionInfo"),_T("DbgHelp.dll"),_T("Failed to load"));
         }
         CloseHandle(hFile);
         
         //SAFE_DELETE(g_pszBugFile);
     }
     //if(g_previousFilter)
     //    return g_previousFilter(pExceptionInfo);
     //else
         return lRet;
 }

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 6
支持
分享
最新回复 (14)
雪    币: 698
活跃值: (4564)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
2
good idea
2013-2-27 16:34
0
雪    币: 66
活跃值: (203)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
3
nice 啊,指令邮件
2013-2-27 22:00
0
雪    币: 967
活跃值: (1138)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
4
不行!谁有这么笨啊 邮箱账户密码 不明摆着!这样会导致大面积种马的
2013-2-27 22:11
0
雪    币: 656
活跃值: (448)
能力值: ( LV12,RANK:360 )
在线值:
发帖
回帖
粉丝
5
好东西,收藏!!
2013-2-28 21:11
0
雪    币: 12
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
坐等楼主解释这个问题!
2013-2-28 21:29
0
雪    币: 12
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
想法是不错滴,lz创新精神不错
2013-2-28 21:30
0
雪    币: 3032
活跃值: (2810)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
太复杂了,直接读取空间、博客、微博什么的内容不就完了。
2013-2-28 21:37
0
雪    币: 170
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
mark一下,回头学习~
2013-3-1 09:38
0
雪    币: 21
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
这个  收下呵呵 不错
2013-3-1 21:50
0
雪    币: 199
活跃值: (65)
能力值: ( LV5,RANK:70 )
在线值:
发帖
回帖
粉丝
11
MARK一下,感谢楼主的无私分享!
2013-3-2 14:47
0
雪    币: 471
活跃值: (4058)
能力值: ( LV9,RANK:170 )
在线值:
发帖
回帖
粉丝
12
mark!!!1
2013-3-3 18:47
0
雪    币: 97697
活跃值: (200829)
能力值: (RANK:10 )
在线值:
发帖
回帖
粉丝
13
Thanks for share.
2013-3-3 19:20
0
雪    币: 107
活跃值: (404)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
14
有点意思............
2013-3-4 00:45
0
雪    币: 27
活跃值: (36)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
15
收藏!!!!
2013-3-3 21:05
0
游客
登录 | 注册 方可回帖
返回
//