0

我用 Visual C++ 编写了一个程序来显示位置和速度。它工作得很好。当我扩展代码以显示错误时。尽管我只是从视觉工作室添加的。我收到访问冲突错误,代码中的错误首先发生在 testDLg.h 的“CEdit”处。默认情况下,CEdit 类由 windows 中的 Visual Studio 在 axfwin.h 中生成。

// testDlg.cpp : implementation file
//

#include "stdafx.h"
#include "test.h"
#include "testDlg.h"
//#include <timer.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#pragma comment(lib,"Mx4nt.lib")
extern "C"
{
#include "mx4nt.h"
#include "mx4dll.h"

int pstn = 0;

// The following function is not included in the DLL's header file, but
// it is included in the DLL.
NOMANGLE BYTE _stdcall r_1byte( int offset );
NOMANGLE BYTE _stdcall w_1byte( int offset, unsigned char data );
}



// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
CAboutDlg();

// Dialog Data
enum { IDD = IDD_ABOUTBOX };

protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

// Implementation
protected:
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()


// CtestDlg dialog



CtestDlg::CtestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CtestDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CtestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT10, tab1);
DDX_Control(pDX, IDC_EDIT11, tab2);
DDX_Control(pDX, IDC_EDIT12, tab3);
DDX_Control(pDX, IDC_EDIT13, tab4);
DDX_Control(pDX, IDC_EDIT14, tab5);
DDX_Control(pDX, IDC_EDIT15, tab6);
DDX_Control(pDX, IDC_EDIT16, tab7);
DDX_Control(pDX, IDC_EDIT1, pos1);
DDX_Control(pDX, IDC_EDIT3, pos2);
DDX_Control(pDX, IDC_EDIT5, pos3);
DDX_Control(pDX, IDC_EDIT7, pos4);
DDX_Control(pDX, IDC_EDIT2, vel1);
DDX_Control(pDX, IDC_EDIT4, vel2);
DDX_Control(pDX, IDC_EDIT6, vel3);
DDX_Control(pDX, IDC_EDIT8, vel4);
DDX_Control(pDX, IDC_EDIT9, ferr1);
DDX_Control(pDX, IDC_EDIT17, ferr2);
DDX_Control(pDX, IDC_EDIT18, ferr3);
DDX_Control(pDX, IDC_EDIT19, ferr4);

}

BEGIN_MESSAGE_MAP(CtestDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP

ON_WM_TIMER()

END_MESSAGE_MAP()


// CtestDlg message handlers

BOOL CtestDlg::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

clear_dspl();
reset_MX4();
SetTimer(1,50,NULL);

// TODO: Add extra initialization here

GetDlgItem(IDC_EDIT10)->SetWindowText("axis1");
GetDlgItem(IDC_EDIT11)->SetWindowText("axis2");
GetDlgItem(IDC_EDIT12)->SetWindowText("axis3");
GetDlgItem(IDC_EDIT13)->SetWindowText("axis4");
GetDlgItem(IDC_EDIT14)->SetWindowText("position");
GetDlgItem(IDC_EDIT15)->SetWindowText("velocity");
GetDlgItem(IDC_EDIT16)->SetWindowText("error");

GetDlgItem(IDC_EDIT1)->SetWindowText("");
GetDlgItem(IDC_EDIT2)->SetWindowText("");
GetDlgItem(IDC_EDIT3)->SetWindowText("");
GetDlgItem(IDC_EDIT4)->SetWindowText("");
GetDlgItem(IDC_EDIT5)->SetWindowText("");
GetDlgItem(IDC_EDIT6)->SetWindowText("");
GetDlgItem(IDC_EDIT7)->SetWindowText("");
GetDlgItem(IDC_EDIT8)->SetWindowText("");
GetDlgItem(IDC_EDIT9)->SetWindowText("");
GetDlgItem(IDC_EDIT17)->SetWindowText("");
GetDlgItem(IDC_EDIT18)->SetWindowText("");
GetDlgItem(IDC_EDIT19)->SetWindowText("");

pos_preset(1, pstn);

return TRUE;  // return TRUE  unless you set the focus to a control
}

void CtestDlg::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 CtestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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
{
CDialog::OnPaint();
}

/*
CString str[8];
str[0].Format("%f",pos(1));
str[1].Format("%f",pos(2));
str[2].Format("%f",pos(3));
str[3].Format("%f",pos(4));
str[4].Format("%f",vel(1));
str[5].Format("%f",vel(2));
str[6].Format("%f",vel(3));
str[7].Format("%f",vel(4));
GetDlgItem(IDC_EDIT1)->SetWindowText(str[0]);
GetDlgItem(IDC_EDIT3)->SetWindowText(str[1]);
GetDlgItem(IDC_EDIT5)->SetWindowText(str[2]);
GetDlgItem(IDC_EDIT7)->SetWindowText(str[3]);
GetDlgItem(IDC_EDIT2)->SetWindowText(str[4]);
GetDlgItem(IDC_EDIT4)->SetWindowText(str[5]);
GetDlgItem(IDC_EDIT6)->SetWindowText(str[6]);
GetDlgItem(IDC_EDIT8)->SetWindowText(str[7]);
*/
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CtestDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}

void CtestDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default

//pstn += 100;
//pos_preset(1, pstn);
maxacc(1, 1.0);
velmode(1, 1.0);

CString str[8];
str[0].Format("%f",pos(1));
str[1].Format("%f",pos(2));
str[2].Format("%f",pos(3));
str[3].Format("%f",pos(4));
str[4].Format("%f",vel(1));
str[5].Format("%f",vel(2));
str[6].Format("%f",vel(3));
str[7].Format("%f",vel(4));
str[8].Format("%f",ferr(1));
str[9].Format("%f",ferr(2));
str[10].Format("%f",ferr(3));
str[11].Format("%f",ferr(4));
GetDlgItem(IDC_EDIT1)->SetWindowText(str[0]);
GetDlgItem(IDC_EDIT3)->SetWindowText(str[1]);
GetDlgItem(IDC_EDIT5)->SetWindowText(str[2]);
GetDlgItem(IDC_EDIT7)->SetWindowText(str[3]);
GetDlgItem(IDC_EDIT2)->SetWindowText(str[4]);
GetDlgItem(IDC_EDIT4)->SetWindowText(str[5]);
GetDlgItem(IDC_EDIT6)->SetWindowText(str[6]);
GetDlgItem(IDC_EDIT8)->SetWindowText(str[7]);
GetDlgItem(IDC_EDIT9)->SetWindowText(str[8]);
GetDlgItem(IDC_EDIT17)->SetWindowText(str[9]);
GetDlgItem(IDC_EDIT18)->SetWindowText(str[10]);
GetDlgItem(IDC_EDIT19)->SetWindowText(str[11]);

//KillTimer(1);
//i = i+100;

//Invalidate();

CDialog::OnTimer(nIDEvent);
}

-- 
- Nandhini
www.linkedin.com/in/nandhinisudarsanan

// testDlg.h : header file
//

#pragma once
#include "afxwin.h"


// CtestDlg dialog
class CtestDlg : public CDialog
{
// Construction
public:
CtestDlg(CWnd* pParent = NULL); // standard constructor

// Dialog Data
enum { IDD = IDD_TEST_DIALOG };

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support


// Implementation
protected:
HICON m_hIcon;

// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
CEdit tab1;
CEdit tab2;
CEdit tab3;
CEdit tab4;
CEdit tab5;
CEdit tab6;
CEdit tab7;
CEdit pos1;
CEdit pos2;
CEdit pos3;
CEdit pos4;
CEdit vel1;
CEdit vel2;
CEdit vel3;
CEdit vel4;
CEdit ferr1;
CEdit ferr2;
CEdit ferr3;
CEdit ferr4;
afx_msg void OnTimer(UINT nIDEvent);
};

我从调试中得到的结果。NTDLL.DLL!77f8f397()
NTDLL.DLL!77fa0346()

mfc70d.dll!AfxWinMain(HINSTANCE__ * hInstance=, HINSTANCE__ * hPrevInstance=, char * lpCmdLine=, int nCmdShow=) 第 23 行 C++

  • hInstance CXX0017:错误:未找到符号“” HINSTANCE__ *未使用 CXX0030:错误:无法评估表达式 int
  • hPrevInstance CXX0030:错误:无法评估表达式 HINSTANCE__ * 未使用 CXX0030:错误:无法评估表达式 int
  • lpCmdLine CXX0030:错误:无法评估表达式 char * CXX0030:错误:无法评估表达式 char nCmdShow CXX0030:错误:无法评估表达式 int

HINSTANCE__* 应该等于某个值,因为那里没有找到任何东西。我收到 77F8F397 CXX0013:错误:缺少操作员
需要帮助打开包装谢谢。

更新 :

我删除了不必要的 CEdit。它不会产生任何错误。速度和误差的值始终为零,尽管我知道它不应该显示为零。

4

1 回答 1

0

使用调试器!

  • 在调试器下运行您的应用程序(Visual Studio 中默认为 F5)。
  • 当抛出异常时,按“Break”。应用程序执行将暂停(调试断点),并显示错误的源代码位置。
  • 如果错误位置不在您的代码中(可能在库代码中的某个位置),请查看“调用堆栈”窗口并选择您识别的最顶层函数。您将跳转到代码中导致进一步问题的位置。
  • 查看“Autos”和“Locals”窗口。检查变量的值,与您期望的值进行比较。您将能够快速发现错误。

调试愉快!

于 2013-09-24T02:01:24.840 回答