返回信息流近日因为毕设,要使用到C++环境下的MFC编程,但是,在连接数据库成功后,当我按下F5的时候,出现了这个问题...
>正在生成代码...
1>正在编译资源...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>正在编译资源清单...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>正在链接...
1>LINK : 没有找到 G:\visual C++\Project1\my_db\Debug\my_db.exe 或上一个增量链接没有生成它;正在执行完全链接
1>正在嵌入清单...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>LINK : fatal error LNK1000: Internal error during IncrBuildImage
1> Version 9.00.21022.08
1> ExceptionCode = C0000005
1> ExceptionFlags = 00000000
1> ExceptionAddress = 008FFCF7 (00880000) "G:\visual studio 2008\VC\bin\link.exe"
1> NumberParameters = 00000002
1> ExceptionInformation[ 0] = 00000000
1> ExceptionInformation[ 1] = 001DD670
1>CONTEXT:
1> Eax = 400BE6A0 Esp = 001FEBCC
1> Ebx = 40008164 Ebp = 001FEBF4
1> Ecx = 001DD670 Esi = 400BE52C
1> Edx = 001FEBE4 Edi = 0088D6C0
1> Eip = 008FFCF7 EFlags = 00010246
1> SegCs = 00000023 SegDs = 0000002B
1> SegSs = 0000002B SegEs = 0000002B
1> SegFs = 00000053 SegGs = 0000002B
1> Dr0 = 00000000 Dr3 = 00000000
1> Dr1 = 00000000 Dr6 = 00000000
1> Dr2 = 00000000 Dr7 = 00000000
1>生成日志保存在“file://g:\visual C++\Project1\my_db\my_db\Debug\BuildLog.htm”
1>my_db - 1 个错误,0 个警告
========== 全部重新生成: 成功 0 个,失败 1 个,跳过 0 个 ==========
下面附上原代码,跪求大神指点迷津
// my_db.h : PROJECT_NAME 应用程序的主头文件
//
#pragma once
#ifndef __AFXWIN_H__
#error "在包含此文件之前包含“stdafx.h”以生成 PCH 文件"
#endif
#include "resource.h" // 主符号
// Cmy_dbApp:
// 有关此类的实现,请参阅 my_db.cpp
//
class Cmy_dbApp : public CWinApp
{
public:
Cmy_dbApp();
// 重写
public:
virtual BOOL InitInstance();
// 实现
DECLARE_MESSAGE_MAP()
};
extern Cmy_dbApp theApp;
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
// my_dbDlg.h : 头文件
//
#include "afxdb.h"
#pragma once
// Cmy_dbDlg 对话框
class Cmy_dbDlg : public CDialog
{
// 构造
public:
Cmy_dbDlg(CWnd* pParent = NULL); // 标准构造函数
private:
CDatabase m_db_opr;
CEdit m_cust_id;
CEdit m_cust_name;
// 对话框数据
enum { IDD = IDD_MY_DB_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
HICON m_hIcon;
// 生成的消息映射函数
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
virtual BOOL GetCustIdFromEdit(int &out_id);
afx_msg void OnBnClickedAddNew();
afx_msg void OnBnClickedEdit();
afx_msg void OnBnClickedDelete();
};
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
// my_dbDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "my_db.h"
#include "my_dbDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Cmy_dbDlg 对话框
Cmy_dbDlg::Cmy_dbDlg(CWnd* pParent /*=NULL*/)
: CDialog(Cmy_dbDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void Cmy_dbDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(Cmy_dbDlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, &Cmy_dbDlg::OnBnClickedAddNew)
END_MESSAGE_MAP()
// Cmy_dbDlg 消息处理程序
BOOL Cmy_dbDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
m_db_opr.Open(NULL,
false,
false,
_T("ODBC;server=127.0.0.1;DSN=k;UID=root;PWD=weibao")
);
if(!m_db_opr.IsOpen())
{
AfxMessageBox(_T("DB open failed!"));
return false;
}
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
BOOL Cmy_dbDlg::GetCustIdFromEdit(int &out_id)
{
int cust_id;
CString str;
const wchar_t *c_str;
if(!m_cust_id.GetWindowTextLengthW())
{
return false;
}
m_cust_id.GetWindowTextW(str);
c_str = str.GetString();
swscanf_s(c_str, _T("%lu"), &cust_id);
out_id = cust_id;
return true;
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void Cmy_dbDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作区矩形中居中
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;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR Cmy_dbDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void Cmy_dbDlg::OnBnClickedAddNew()
{
// TODO: 在此添加控件通知处理程序代码
int cust_id = 0 ;
CString cust_name;
if(!GetCustIdFromEdit(cust_id))
{
AfxMessageBox(_T("NULL cust id, return"));
return;
}
if(!m_cust_name.GetWindowTextLengthW())
{
AfxMessageBox(_T("NULL cust name, return"));
return;
}
m_cust_name.GetWindowTextW(cust_name);
try
{
CString sql_str;
sql_str.Format(_T("insert customer value (%d, '%s')"), cust_id, cust_name);
m_db_opr.ExecuteSQL(sql_str);
}
catch(CDBException* pe)
{
// The error code is in pe->m_nRetCode
pe->ReportError();
pe->Delete();
}
}
void Cmy_dbDlg::OnBnClickedEdit()
{
// TODO: Add your control notification handler code here
int cust_id = 0 ;
CString cust_name;
if(!GetCustIdFromEdit(cust_id))
{
AfxMessageBox(_T("NULL cust id, return"));
return;
}
if(!m_cust_name.GetWindowTextLengthW())
{
AfxMessageBox(_T("NULL cust name, return"));
return;
}
m_cust_name.GetWindowTextW(cust_name);
try
{
CString sql_str;
sql_str.Format(_T("update customer set cust_name = '%s' where cust_id = %d"),
cust_name,
cust_id
);
m_db_opr.ExecuteSQL(sql_str);
}
catch(CDBException* pe)
{
// The error code is in pe->m_nRetCode
pe->ReportError();
pe->Delete();
}
}
void Cmy_dbDlg::OnBnClickedDelete()
{
// TODO: Add your control notification handler code here
int cust_id = 0 ;
CString cust_name;
if(!GetCustIdFromEdit(cust_id))
{
AfxMessageBox(_T("NULL cust id, return"));
return;
}
try
{
CString sql_str;
sql_str.Format(_T("delete from customer where cust_id = %d"), cust_id);
m_db_opr.ExecuteSQL(sql_str);
}
catch(CDBException* pe)
{
// The error code is in pe->m_nRetCode
pe->ReportError();
pe->Delete();
}
}
这是一条镜像帖。来源:北邮人论坛 / cpp / #77554同步于 2014/3/18
CPP机器人发帖
小弟向各位大神问个C++debug问题
weibao
2014/3/18镜像同步0 回复
订阅后,新回复会通过你的通知中心匿名送达。
0 条回复
暂无回复 · 你可以订阅本帖等待新回复。