Home > Software engineering >  To overcome "0 xc0000005: write position 0 x0036bc7a access conflict" problem
To overcome "0 xc0000005: write position 0 x0036bc7a access conflict" problem

Time:09-29

The younger brother in learning "Windows programming" fifth edition, in the debugging chapter 10 (resources and other resources) POEPOEM. C program, encounter this problem: "write position 0 0 xc0000005: x0036bc7a access conflict",
1, tools: visual studio 2013
2, when the debug to 108 lines of code; * PText='\ 0'; Cannot execute

3, "AnnabelLee" represents a TXT text resources; The text resources end with a backslash,
4, hResource is pointing to the text resources a handle to the memory block;
5, Pointers PText text strings in memory;


6, the source code, resource files are identical, and the book
why * PText='\ 0' why can't not perform?
Why is 0 x0036bc7a value cannot be modified?

If over 108 lines, to perform can debug successful, but in the end is displayed in the window the text is on the end with a backslash,

All below is POEPOEM. C code:
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
POEPOEM. C -- -- Demonstrates the Custom Resource
(c) Charles Petzold, 1998
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - */

#include
# include "resource. H"

LRESULT a CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

HINSTANCE hInst,

Int WINAPI WinMain (HINSTANCE HINSTANCE, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
SzCaption TCHAR szAppName [16], [64], szErrMsg [64].
The HWND HWND;
MSG MSG.
WNDCLASS WNDCLASS;

LoadString (hInstance, IDS_APPNAME, szAppName,
Sizeof (szAppName)/sizeof (TCHAR));

LoadString (hInstance, IDS_CAPTION szCaption,
Sizeof (szCaption)/sizeof (TCHAR));

Wndclass. Style=CS_HREDRAW | CS_VREDRAW;
Wndclass. LpfnWndProc=WndProc;
Wndclass. CbClsExtra=0;
Wndclass. CbWndExtra=0;
Wndclass. HInstance=hInstance;
Wndclass. HIcon=LoadIcon (hInstance, szAppName);
Wndclass. HCursor=LoadCursor (NULL, IDC_ARROW);
Wndclass. HbrBackground=(HBRUSH) GetStockObject (WHITE_BRUSH);
Wndclass. LpszMenuName=NULL;
Wndclass. LpszClassName=szAppName;

if (! RegisterClass (& amp; Wndclass))
{
LoadStringA (hInstance, IDS_APPNAME, (char *) szAppName,
Sizeof (szAppName));

LoadStringA (hInstance, IDS_ERRMSG szErrMsg (char *),
Sizeof (szErrMsg));

SzErrMsg MessageBoxA (NULL, (char *),
(char *) szAppName, MB_ICONERROR);
return 0;
}

HWND=CreateWindow (szAppName, szCaption,
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT CW_USEDEFAULT,
CW_USEDEFAULT CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);

ShowWindow (HWND, iCmdShow);
UpdateWindow (HWND);

While (GetMessage (& amp; MSG, NULL, 0, 0))
{
TranslateMessage (& amp; MSG);
DispatchMessage (& amp; MSG);
}
Return MSG. WParam;
}

LRESULT a CALLBACK WndProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM)
{
The static char * pText;
The static HGLOBAL hResource;
The static HWND hScroll;
Static int iPosition cxChar, cyChar, cyClient iNumLines, xScroll;
HDC HDC.
PAINTSTRUCT ps;
The RECT the RECT.
The TEXTMETRIC tm;
TCHAR zp;
The switch (the message)
{
Case WM_CREATE message handler:
HDC=GetDC (HWND);
GetTextMetrics (HDC, & amp; Tm);
CxChar=tm. TmAveCharWidth;
CyChar=tm. TmHeight + tm. TmExternalLeading;
ReleaseDC (HWND, HDC);

XScroll=GetSystemMetrics (SM_CXVSCROLL);

HScroll=CreateWindow (TEXT (" scrollbar "), NULL,
WS_CHILD | WS_VISIBLE | SBS_VERT,
0, 0, 0, 0,
HWND, (HMENU) 1, hInst, NULL);

hResource=LoadResource (hInst,
FindResource (hInst, TEXT (" AnnabelLee "),
The TEXT (" TEXT ")));

PText=(char *) LockResource (hResource);
INumLines=0;

While (* pText!='\ \' & amp; & * pText!='\ 0')
{
If (* pText=='\ n')
INumLines++;
PText=AnsiNext (pText);
}
* pText='\ 0';


SetScrollRange (hScroll SB_CTL, 0, iNumLines, FALSE);
SetScrollPos (hScroll SB_CTL, 0, FALSE);
return 0;

Case WM_SIZE:
MoveWindow (hScroll, LOWORD (lParam) - xScroll, 0,
XScroll, cyClient=HIWORD (lParam), TRUE);
SetFocus (HWND);
return 0;

Case WM_SETFOCUS:
SetFocus (hScroll);
return 0;

Case WM_VSCROLL:
The switch (wParam)
{
Case SB_TOP:
IPosition=0;
break;
Case SB_BOTTOM:
IPosition=iNumLines;
break;
Case SB_LINEUP:
IPosition -=1;
break;
Case SB_LINEDOWN:
IPosition +=1;
break;
Case SB_PAGEUP:
IPosition -=cyClient/cyChar;
break;
Case SB_PAGEDOWN:
IPosition +=cyClient/cyChar;
break;
Case SB_THUMBPOSITION:
IPosition=LOWORD (lParam);
break;
}
IPosition=Max (0, min (iPosition iNumLines));

If (iPosition!=GetScrollPos (hScroll SB_CTL))
{
SetScrollPos (hScroll, SB_CTL iPosition, TRUE);
The InvalidateRect (HWND, NULL, TRUE);
}
return 0;

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related