请问高手这个问题怎么解决,最好友详细步骤,我是新手。
这里提供点详细信息,我的系统是Vista,开始的时候的对话框程序只能实现格式转换功能,那时候还不存在运行时出现“testftsdll2 Microsoft基础类应用程序已停止工作”,现在我把显示的功能加上去之后,虽然通过编译和组建,但是在运行是会出想”testftsdll2 Microsoft基础类应用程序已停止工作“的问题。而且我的debug文件中还是以前的exe,功能只有转换,而release中的是添加显示功能后的exe,我该怎么办

解决方案 »

  1.   

    程序代码为:// testftsdll2Dlg.cpp : implementation file
    //#include "stdafx.h"
    #include "testftsdll2.h"
    #include "testftsdll2Dlg.h"
    #include "ftsdll.h"
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    // using namespace std;
    /////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
    {
    public:
    CAboutDlg();// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    //{{AFX_MSG(CAboutDlg)
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
    }void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    // No message handlers
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CTestftsdll2Dlg dialogCTestftsdll2Dlg::CTestftsdll2Dlg(CWnd* pParent /*=NULL*/)
    : CDialog(CTestftsdll2Dlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CTestftsdll2Dlg)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }void CTestftsdll2Dlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CTestftsdll2Dlg)
    // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CTestftsdll2Dlg, CDialog)
    //{{AFX_MSG_MAP(CTestftsdll2Dlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDC_BTN_FTBMP, OnBtnFtbmp)
    ON_BN_CLICKED(IDC_BTN_FTODATA, OnBtnFtodata)
    ON_BN_CLICKED(IDC_BTN_DATATBMP, OnBtnDatatbmp)
    ON_BN_CLICKED(IDC_BUTTON_OpenBMP, OnBUTTONOpenBMP)
    ON_BN_CLICKED(IDC_BUTTON_SaveBMP, OnBUTTONSaveBMP)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CTestftsdll2Dlg message handlersBOOL CTestftsdll2Dlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // TODO: Add extra initialization here

    return TRUE;  // return TRUE  unless you set the focus to a control
    }void CTestftsdll2Dlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
    CAboutDlg dlgAbout;
    dlgAbout.DoModal();
    }
    else
    {
    CDialog::OnSysCommand(nID, lParam);
    }
    }// If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.void CTestftsdll2Dlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
           if (m_pDib != NULL)
    {
    ShowBMP();
    }
    CDialog::OnPaint();

    }
    }// The system calls this to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CTestftsdll2Dlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }char ftsname[20];void CTestftsdll2Dlg::OnBtnFtbmp() 
    {
    // TODO: Add your control notification handler code here
           GetDlgItem(IDC_EDIT1)->GetWindowText(ftsname,20);
       FtstoBmp(ftsname,"3215.bmp");

    }
    BYTE *FtsDataTemp;
    int WTemp,HTemp;
    void CTestftsdll2Dlg::OnBtnFtodata() //测试ftstodata{ // TODO: Add your control notification handler code here
    BYTE *FtsData;
    FILE *fp;
    int W=0,H=0;
    CString str;
    fp=fopen("D:\\ftsdata1.txt","wt");//将数据写入到TXT文档中
    GetDlgItem(IDC_EDIT1)->GetWindowText(ftsname,20);
    FtsData=readfts(ftsname,W,H);
    fprintf(fp,"%d %d\n",W,H);
    for(int i=0;i<W*H;i++)
    fprintf(fp,"%d ",FtsData[i]);
    FtsDataTemp=(BYTE*) malloc(W*sizeof(BYTE)*H);
    FtsDataTemp=FtsData;
    WTemp=W;
    HTemp=H;
    fclose(fp);
    // str.Format("W=%d,h=%d",W,H);
    // MessageBox(str);
    }void CTestftsdll2Dlg::OnBtnDatatbmp() 
    {
    // TODO: Add your control notification handler code here
    /*
    int i,W,H;
    BYTE *FtsDataTemp,b[2];
    FILE *fp;
    fp=fopen("D:\\ftsdata1.txt","rt");

    for(i=0;i<2;i++)
      fscanf(fp,"%d",&b[i]);
    W=b[0];
    H=b[1];
    FtsDataTemp=(BYTE*) malloc(W*sizeof(BYTE)*H);
    for(i=0;i<W*H;i++)
    fscanf(fp,"%d",&FtsDataTemp[i]);
    */
    // if (FtsDataTemp==NULL) 

    writetoBmp(FtsDataTemp,WTemp,HTemp,"Datatobmpfile1.bmp");
    }void CTestftsdll2Dlg::OnBUTTONOpenBMP() 
    {
    // TODO: Add your control notification handler code here
    CFileDialog dlg(TRUE, "*.BMP", NULL, NULL,"位图文件(*.BMP)|*.bmp;*.BMP|");
    CString strFileName;
    CFile file;
        if (dlg.DoModal() == IDOK)
    {            
    strFileName = dlg.GetPathName();

    if(!file.Open(strFileName, CFile::modeRead))
    return; BITMAPFILEHEADER bmfHeader;

    nFileLen = file.GetLength();
    dwDibSize = nFileLen - sizeof(BITMAPFILEHEADER); //dwDibSize为BMP总大小减去BMP文件头的长度 if (m_pDib != NULL) 
    {
    delete[] m_pDib;
    m_pDib = NULL;
    } m_pDib = new unsigned char[dwDibSize]; // 为DIB位图分配内存

    if (file.Read((LPSTR)&bmfHeader, sizeof(bmfHeader)) != sizeof(bmfHeader)) //读文件头
    return;

    if (bmfHeader.bfType != ((WORD)('M' <<8) | 'B'))  //判断是否是BMP位图
    return ; if (file.Read(m_pDib, dwDibSize) != dwDibSize) //读文件头以后的数据
    return ;

    m_bmpInfoHeader = (BITMAPINFOHEADER*)m_pDib; lHeight = m_bmpInfoHeader->biHeight; //图像长
    lWidth = m_bmpInfoHeader->biWidth; //图像宽
            lBitCount = m_bmpInfoHeader->biBitCount; //图像位数 switch(lBitCount) 
    {
    case 1:
    NumColor = 2;
    break;
    case 4:
    NumColor = 16;
    break;
    case 8:
    NumColor = 256;
    break;
    case 24:
    NumColor = 0;
    break;
    default:
    return;
    } m_pDibBits = m_pDib + sizeof(BITMAPINFOHEADER) + NumColor * sizeof (RGBQUAD); ShowBMP();

    GetDlgItem(IDC_BUTTON_SaveBMP)->EnableWindow(TRUE);

    }

    }void CTestftsdll2Dlg::OnBUTTONSaveBMP() 
    {
    // TODO: Add your control notification handler code here
    CString m_szFileName;
    if (m_pDib!=NULL) 
    {
    CFileDialog dlg(FALSE, _T("bmp"), _T("Temp.bmp"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("Bitmap Files (*.bmp)|*.bmp|All Files (*.*)|*.*||"), this);
    if(dlg.DoModal() == IDOK)
    {
    m_szFileName = dlg.GetPathName();
    HANDLE hf = CreateFile(m_szFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL,CREATE_ALWAYS, NULL, NULL);
    if( hf == INVALID_HANDLE_VALUE ) return;
    // 写位图文件头 
    BITMAPFILEHEADER bfh;
    memset(&bfh, 0, sizeof(bfh));
    bfh.bfType = 'MB';      //文件类型
    bfh.bfSize = nFileLen; //bmp文件大小
    bfh.bfReserved1 = 0;
    bfh.bfReserved2 = 0;
    bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + NumColor * sizeof(RGBQUAD); 
    DWORD dwWritten = 0;
    WriteFile(hf, &bfh, sizeof(bfh), &dwWritten, NULL);

    // 写位图信息头
    BITMAPINFOHEADER bih;
    memset(&bih, 0, sizeof(bih));
    bih.biSize = sizeof(bih);
    bih.biWidth = lWidth;
    bih.biHeight = lHeight;
    bih.biPlanes = 1;
    bih.biBitCount = lBitCount;
    bih.biCompression = 0;
    bih.biSizeImage = bih.biWidth * bih.biHeight * lBitCount / 8;
    bih.biXPelsPerMeter = 3780;
    bih.biYPelsPerMeter = 3780;
    bih.biClrUsed = 0;
    bih.biClrImportant = 0;
    WriteFile(hf, &bih, sizeof(bih), &dwWritten, NULL);

    // 写位图数据
    unsigned char *m_pDibBuffer;
                m_pDibBuffer = m_pDib + sizeof(BITMAPINFOHEADER);
    DWORD lDibSize =  nFileLen - sizeof(BITMAPFILEHEADER) - sizeof(BITMAPINFOHEADER);
    WriteFile(hf, m_pDibBuffer, lDibSize, &dwWritten, NULL);
    CloseHandle(hf);
    }
    }

    }void CTestftsdll2Dlg::ShowBMP()
    {
    CDC *pDC;
    CRect rect;
    CWnd *pWnd = GetDlgItem(IDC_STATIC_SHOW);
    pWnd->GetClientRect(&rect);
    pDC = pWnd->GetDC();
    SetStretchBltMode(pDC->m_hDC,HALFTONE);//防止自适应窗口图像显示失真
    StretchDIBits(pDC->m_hDC,rect.left, rect.top, rect.right, rect.bottom, 0, 0, 
              lWidth, lHeight, m_pDibBits, (BITMAPINFO*)m_bmpInfoHeader, BI_RGB, SRCCOPY);
    }
      

  2.   

    楼主,请问下,你这个问题解决了吗?我这里也遇到个, test Microsoft基础类应用程序 已停止工作,求答案!