高分求解 VS.net中的内存访问冲突问题,分数不够再加!!
我使用VS.net的WIN32框架程序,在添加自定义函数以后,编译连接没有问题,运行则会出现“0x0045fa20 处未处理的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突”问题。
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// TODO: 在此放置代码。
MSG msg;
HACCEL hAccelTable;
// 初始化全局字符串
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_EVER3D, szWindowClass, AX_LOADSTRING);
MyRegisterClass(hInstance);
// 执行应用程序初始化:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_EVER3D);
// 主消息循环:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // 将实例句柄存储在全局变量中
hWnd = CreateWindow( "Ever3D ", "CarDemo.exe ",
WS_OVERLAPPEDWINDOW |
WS_VISIBLE |
WS_SYSMENU |
WS_CLIPCHILDREN |
WS_CLIPSIBLINGS,
CW_USEDEFAULT,
0,
CW_USEDEFAULT,
0,
NULL, NULL,
hInstance,
NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
回调函数为WndProc,其中添加了WM_CREATE消息,并在其中进行初始化工作。
相应代码部分如下:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
...
switch (message)
{
case WM_CREATE:
hdc = GetDC(hWnd);
g_hdc = hdc;
SetupPixelFormat(hdc);
glRC = wglCreateContext(hdc);
wglMakeCurrent(hdc,glRC);
InitOpenGL();
if(! InitData())
{
Uninitialize();
wglMakeCurrent(hdc,glRC);
wglDeleteContext(glRC);
PostQuitMessage(0);
}
break;
}
其中的未知函数都已经在外部有了定义了。
使用调试跟踪错误,发现问题出在strcmp函数的ASM代码
CODESEG
public strcmp