这段代码是对的吗?因为我有退出代码1 [英] Is This Code Is Right? Because I Got Exit Code 1

查看:60
本文介绍了这段代码是对的吗?因为我有退出代码1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨;



我问我的代码是不是?因为我在调试器中获得退出代码1,程序很好并且工作正常但很少崩溃,代码是从图片控件获取图片并将图像保存到文件,这是我的代码片段;

hi;

i ask about my code is it right? because i get exit code 1 in debugger ,the program is fine and work good but it crashs rarely, the code is to get picture from picture control and save the image to file, here is a piece of my code;

#include <atlimage.h>

#include <Gdiplusimaging.h>

//take snapshot of pic

CDC dc;

  
	CRect rect;
CWnd *wnd = GetDlgItem(IDC_SHOW_PICTURE_STATUS2);
wnd->GetWindowRect(&rect);


         HDC hdc = ::GetDC(wnd->m_hWnd);
         dc.Attach(hdc);
      

     CDC memDC;

     memDC.CreateCompatibleDC(&dc);

     CBitmap bm;
     CRect r;

    
         wnd->GetClientRect(&r);
      

     CString s;
     wnd->GetWindowText(s);

     CSize sz(r.Width(), r.Height());

     bm.CreateCompatibleBitmap(&dc, sz.cx, sz.cy);

     CBitmap * oldbm = memDC.SelectObject(&bm);

     memDC.BitBlt(0, 0, sz.cx, sz.cy, &dc, 0, 0, SRCCOPY);



	 CImage image;

        image.Attach(bm);

        image.Save(bmp_file, Gdiplus::ImageFormatBMP);




     memDC.SelectObject(oldbm);
     bm.Detach();

推荐答案

这个问题毫无意义。你知道退出代码来自哪里吗?这是从应用程序的入口点函数返回的返回值。请参阅:

http://en.wikipedia.org/wiki/Entry_point #C_and_C.2B.2B [ ^ ]。



你没有显示这个功能,所以请找出为什么它自己返回1。还有其他方法可以返回此值,但这只是因为退出代码设置机制包含在某些库中,如果是Windows,则包含在Windows SDK中。特别是,MFC有这个:

http://msdn.microsoft.com /en-us/library/e4zc2h84.aspx [ ^ ];

另见: http://en.wikipedia.org/ wiki / Message_loop_in_Microsoft_Windows [ ^ ]。



您也没有显示任何与之相关的信息。所以......请参阅上文。 :-)



另外,你应该明白返回的退出代码并不意味着什么。习惯上使用0表示没问题,所有其他值都是每个特定应用程序引入的约定问题。由于有问题的应用程序应该是您的(是吗?:-)),您应该对返回的值负责。顺便说一句,在现代Windows开发中,最典型的策略是完全忽略这种机制。使用基于C ++的UI应用程序(MFC与否),所有线程中的所有异常最终都会被捕获到一些顶层堆栈帧或主消息循环中;所有问题都显示在应用程序内部的UI中。



-SA
The question makes no sense. Do you know where exit code comes from? This is the return value, returned from the entry point function of the application. Please see:
http://en.wikipedia.org/wiki/Entry_point#C_and_C.2B.2B[^].

You don't show this function, so please find out why it returns 1 yourself. There are other ways to return this value, but only because the exit code setting mechanism is wrapped in some libraries and, in case of Windows, in Windows SDK. In particular, MFC has this:
http://msdn.microsoft.com/en-us/library/e4zc2h84.aspx[^];
see also: http://en.wikipedia.org/wiki/Message_loop_in_Microsoft_Windows[^].

You also did not show anything related to it. So… please see above. :-)

Also, you should understand that returned exit code does not mean anything certain. It's customary to use 0 to indicate "no problem", and all other values is a matter of conventions introduced by each particular application. As the application in question is supposed to be yours (is it? :-)), you are supposed to take responsibility for the returned value. By the way, in modern Windows development the most typical strategy is to completely ignore this mechanism. With C++-based UI applications (MFC or not), all exceptions in all threads are ultimately caught in some top stack frames or in the main message loop; and all the problems are shown inside the application, in its UI.

—SA


这篇关于这段代码是对的吗?因为我有退出代码1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆