GetWHnd()函数 0xC0000005报错

0

---旧编译环境

win10+vs2017+easyx2018

---现编译环境 

win10+vs2022+easyx2023 release/debug x86

---错误提示如下

0x00951A45 处有未经处理的异常(在 MineSweeper.exe 中): 0xC0000005: 读取位置 0x00000378 时发生访问冲突。

---调用堆栈信息

>    MineSweeper.exe!GetHWnd(void)    C++

     ucrtbase.dll!__initterm()    未知

     MineSweeper.exe!__scrt_common_main_seh() 行 256    C++

     kernel32.dll!75f200c9()    未知

     [下面的框架可能不正确和/或缺失,没有为 kernel32.dll 加载符号]    

     ntdll.dll!77227b4e()    未知

     ntdll.dll!77227b1e()    未知

---代码大体如下

//头文件mineS.h
#ifndef __MINES_H__
#define __MINES_H__
#define NUM 10
#define SIZE 30

extern HWND hwnd;

...

#endif
//源文件mineS.cpp
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<graphics.h>

#include"mineS.h"

HWND hwnd = GetHWnd();

...
//源文件main.cpp
#include<stdio.h>
#include<graphics.h>

#include"mineS.h"

int main()
{
	...
	return 0;
}
ava
α0.

2023-11-3

0

(你贴的大部分代码都是无关的。)

你必须保证调用 GetHWnd 之前先 initgraph。否则,窗口都不存在,获取窗口句柄必然失败。

ava
慢羊羊

2023-11-4

实在很抱歉,还在学习阶段,怕信息不完整就全贴上来了。 -  α0.  2023-11-4
技术讨论社区