| |

VerySource

 Forgot password?
 Register
Search
View: 906|Reply: 10

The error message "Memory cannot be read". . . . How to deal with it?

[Copy link]

2

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-14 20:00:01
| Show all posts |Read mode
The code compiles and runs, but when I execute the program, it prompts "Some memory cannot be read." What to do? ?
CCustumInfoSet cSet (&theApp.db);
CBookRoomView * brvDlg;
brvDlg-> m_list.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
Ranch
cSet.Open ();
CODBCFieldInfo info;
for (int i = 0; i <cSet.GetODBCFieldCount (); i ++) {
cSet.GetODBCFieldInfo (i, info);
brvDlg-> m_list.InsertColumn (i, info.m_strName, LVCFMT_LEFT, _tcslen (info.m_strName));
}
cSet.Close ();
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-4 12:15:01
| Show all posts
I also made a mistake, it was connected to the database, and there was an assertion error
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-9-4 12:30:01
| Show all posts
CBookRoomView *brvDlg;
brvDlg-> m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT| LVS_EX_GRIDLINES);
=============
CBookRoomView *brvDlg is just a pointer, just start to use it without instantiation, of course it will be wrong.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-4 12:45:01
| Show all posts
This kind of error is generally that a pointer points to the wrong place, depending on the situation, if it is a very small number, for example, 0x00000023
Then maybe a pointer is empty, and an offset is added.
If it is a relatively large number, such as 0x5FFFFFFF, it may be that the pointer is not initialized, just like your brvDlg;

When you pop up an error message, click Retry first, then click Debug, and enter the debugging to see what the problem is.

The most obvious mistake is here
CBookRoomView *brvDlg;
brvDlg-> m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT| LVS_EX_GRIDLINES);
brvDlg is called without assigning a value, of course it is wrong
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-4 13:15:01
| Show all posts
[Quote=Quote the reply fromshamingjiaon the 2nd floor:]
CBookRoomView *brvDlg;
brvDlg-> m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT| LVS_EX_GRIDLINES);
=============
CBookRoomView *brvDlg is just a pointer, just start to use it without instantiation, of course it will be wrong.
[/Quote]
Try it
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Australia

Post time: 2020-9-4 13:30:01
| Show all posts
CBookRoomView *brvDlg = GetYourDlg();//First get the DLG you want to modify
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-9-4 14:00:01
| Show all posts
Try catch to see if it is a recognizable exception
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-4 14:30:01
| Show all posts
They are generally wild pointers
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-4 14:45:01
| Show all posts
Somewhere the memory cannot be read
Many are 0x000000
Null pointer
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-4 15:00:02
| Show all posts
I agree with the people upstairs, CBookRoomView *brvDlg is not initialized.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list