我有一个我最初制作的应用程序没有线程,所有工作正常没有内存泄漏。我决定改变应用程序并添加一个线程来处理测量读数。在添加了线程后,我得到了一堆内存泄漏,我无法弄清楚它们的来源。
我从线程函数中取出了所有内容,所以它只是一个空函数,我仍然会得到这些泄漏......
在主循环中,我添加了线程t(Monitor);就在主消息循环之前。
Monitor功能现在为空 void Monitor {}
我得到了这些内存泄漏
The thread 0x1d10 has exited with code 0 (0x0).
R6010
- abort() has been called
The thread 0xd64 has exited with code 3 (0x3).
The thread 0x1828 has exited with code 3 (0x3).
The thread 0x1d7c has exited with code 3 (0x3).
Detected memory leaks!
Dumping objects ->
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {244} normal block at 0x003A9620, 46 bytes long.
Data: <x > 78 C5 E5 0F 1D 00 00 00 1D 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {243} normal block at 0x003A95C8, 23 bytes long.
Data: <x > 78 C5 E5 0F 06 00 00 00 06 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {242} normal block at 0x003A9578, 18 bytes long.
Data: <x > 78 C5 E5 0F 01 00 00 00 01 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {241} normal block at 0x003A9520, 22 bytes long.
Data: <x > 78 C5 E5 0F 05 00 00 00 05 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {240} normal block at 0x003A94D0, 18 bytes long.
Data: <x > 78 C5 E5 0F 01 00 00 00 01 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {239} normal block at 0x003A9480, 18 bytes long.
Data: <x > 78 C5 E5 0F 01 00 00 00 01 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {238} normal block at 0x003A9428, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {237} normal block at 0x003A93D8, 20 bytes long.
Data: <x > 78 C5 E5 0F 03 00 00 00 03 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {236} normal block at 0x003A9380, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {235} normal block at 0x003A9330, 18 bytes long.
Data: <x > 78 C5 E5 0F 01 00 00 00 01 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {234} normal block at 0x003A92E0, 18 bytes long.
Data: <x > 78 C5 E5 0F 01 00 00 00 01 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {233} normal block at 0x003A9288, 23 bytes long.
Data: <x > 78 C5 E5 0F 06 00 00 00 06 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {232} normal block at 0x003A9230, 22 bytes long.
Data: <x > 78 C5 E5 0F 05 00 00 00 05 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {231} normal block at 0x003A91D8, 22 bytes long.
Data: <x > 78 C5 E5 0F 05 00 00 00 05 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {230} normal block at 0x003A9180, 22 bytes long.
Data: <x > 78 C5 E5 0F 05 00 00 00 05 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {229} normal block at 0x003A9128, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {228} normal block at 0x003A90D0, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {227} normal block at 0x003A9078, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {226} normal block at 0x003A9020, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {225} normal block at 0x003A8FC8, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {224} normal block at 0x003A8F78, 20 bytes long.
Data: <x > 78 C5 E5 0F 03 00 00 00 03 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {223} normal block at 0x003A8F28, 20 bytes long.
Data: <x > 78 C5 E5 0F 03 00 00 00 03 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {222} normal block at 0x003A8ED8, 19 bytes long.
Data: <x > 78 C5 E5 0F 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {221} normal block at 0x003A8E88, 19 bytes long.
Data: <x > 78 C5 E5 0F 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {220} normal block at 0x003A8E38, 19 bytes long.
Data: <x > 78 C5 E5 0F 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {219} normal block at 0x003A8DE8, 19 bytes long.
Data: <x > 78 C5 E5 0F 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {218} normal block at 0x003A8D98, 19 bytes long.
Data: <x > 78 C5 E5 0F 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {217} normal block at 0x003A8D48, 19 bytes long.
Data: <x > 78 C5 E5 0F 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {216} normal block at 0x003A8CF8, 19 bytes long.
Data: <x > 78 C5 E5 0F 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {215} normal block at 0x003A8CA8, 19 bytes long.
Data: <x > 78 C5 E5 0F 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {214} normal block at 0x003A8C58, 19 bytes long.
Data: <x > 78 C5 E5 0F 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {213} normal block at 0x003A8C08, 19 bytes long.
Data: <x > 78 C5 E5 0F 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {212} normal block at 0x003A8BB8, 19 bytes long.
Data: <x > 78 C5 E5 0F 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {211} normal block at 0x003A8B68, 19 bytes long.
Data: <x > 78 C5 E5 0F 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {210} normal block at 0x003A8B18, 19 bytes long.
Data: <x > 78 C5 E5 0F 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {209} normal block at 0x003A8AC8, 19 bytes long.
Data: <x > 78 C5 E5 0F 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {208} normal block at 0x003A8A78, 19 bytes long.
Data: <x > 78 C5 E5 0F 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {207} normal block at 0x003A8A28, 19 bytes long.
Data: <x > 78 C5 E5 0F 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {206} normal block at 0x003A89D8, 18 bytes long.
Data: <x > 78 C5 E5 0F 01 00 00 00 01 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {205} normal block at 0x003A8988, 18 bytes long.
Data: <x > 78 C5 E5 0F 01 00 00 00 01 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {204} normal block at 0x003A8938, 18 bytes long.
Data: <x > 78 C5 E5 0F 01 00 00 00 01 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {203} normal block at 0x003A88E8, 18 bytes long.
Data: <x > 78 C5 E5 0F 01 00 00 00 01 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {202} normal block at 0x003A8898, 18 bytes long.
Data: <x > 78 C5 E5 0F 01 00 00 00 01 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {201} normal block at 0x003A8848, 18 bytes long.
Data: <x > 78 C5 E5 0F 01 00 00 00 01 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {200} normal block at 0x003A87F8, 18 bytes long.
Data: <x > 78 C5 E5 0F 01 00 00 00 01 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {199} normal block at 0x003A87A8, 18 bytes long.
Data: <x > 78 C5 E5 0F 01 00 00 00 01 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {198} normal block at 0x003A8758, 18 bytes long.
Data: <x > 78 C5 E5 0F 01 00 00 00 01 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {197} normal block at 0x003A8708, 18 bytes long.
Data: <x > 78 C5 E5 0F 01 00 00 00 01 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {196} normal block at 0x003A86B0, 26 bytes long.
Data: <x > 78 C5 E5 0F 09 00 00 00 09 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {195} normal block at 0x003A8658, 26 bytes long.
Data: <x > 78 C5 E5 0F 09 00 00 00 09 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {194} normal block at 0x003A8600, 26 bytes long.
Data: <x > 78 C5 E5 0F 09 00 00 00 09 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {193} normal block at 0x003A85A8, 26 bytes long.
Data: <x > 78 C5 E5 0F 09 00 00 00 09 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {192} normal block at 0x003A8550, 26 bytes long.
Data: <x > 78 C5 E5 0F 09 00 00 00 09 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {191} normal block at 0x003A84F8, 26 bytes long.
Data: <x > 78 C5 E5 0F 09 00 00 00 09 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {190} normal block at 0x003A84A0, 26 bytes long.
Data: <x > 78 C5 E5 0F 09 00 00 00 09 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {189} normal block at 0x003A8448, 26 bytes long.
Data: <x > 78 C5 E5 0F 09 00 00 00 09 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {188} normal block at 0x003A83F0, 26 bytes long.
Data: <x > 78 C5 E5 0F 09 00 00 00 09 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {187} normal block at 0x003A8398, 26 bytes long.
Data: <x > 78 C5 E5 0F 09 00 00 00 09 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {186} normal block at 0x003A8340, 26 bytes long.
Data: <x > 78 C5 E5 0F 09 00 00 00 09 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {185} normal block at 0x003A82E8, 26 bytes long.
Data: <x > 78 C5 E5 0F 09 00 00 00 09 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {184} normal block at 0x003A8290, 26 bytes long.
Data: <x > 78 C5 E5 0F 09 00 00 00 09 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {183} normal block at 0x003A8238, 26 bytes long.
Data: <x > 78 C5 E5 0F 09 00 00 00 09 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {182} normal block at 0x003A81E0, 26 bytes long.
Data: <x > 78 C5 E5 0F 09 00 00 00 09 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {181} normal block at 0x003A8188, 26 bytes long.
Data: <x > 78 C5 E5 0F 09 00 00 00 09 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {180} normal block at 0x003A8130, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {179} normal block at 0x003A80D8, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {178} normal block at 0x003A8080, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {177} normal block at 0x003A8028, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {176} normal block at 0x003A7FD0, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {175} normal block at 0x003A7F78, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {174} normal block at 0x003A7F20, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {173} normal block at 0x003A7EC8, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {172} normal block at 0x003A7E70, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {171} normal block at 0x003A7E18, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {170} normal block at 0x003A7DC0, 22 bytes long.
Data: <x > 78 C5 E5 0F 05 00 00 00 05 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {169} normal block at 0x003A7D68, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {168} normal block at 0x003A7D10, 22 bytes long.
Data: <x > 78 C5 E5 0F 05 00 00 00 05 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {167} normal block at 0x003A7CB8, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {166} normal block at 0x003A7C60, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {165} normal block at 0x003A7C08, 21 bytes long.
Data: <x > 78 C5 E5 0F 04 00 00 00 04 00 00 00 01 00 00 00
Object dump complete.
The program '[7208] Interface Card GUI.exe' has exited with code 3 (0x3).
所以,我猜我做错了什么......但我不确定是什么。 任何帮助,将不胜感激!
[编辑]以下是我将项目缩减为
的代码//#include "Variables.h"
//#include "FileFunctions.h"
#include "resource.h"
#include "Tab.h"
#include <shellapi.h>
#include <thread>
//#include <WinSock2.h>
//#include <WS2tcpip.h>
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
using namespace std;
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void Monitor()
{
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd)
{
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );
int horizontalWindow = 870;
int verticalWindow = 655;
/*
WNDCLASSEX is a structure used during the RegisterClassEx and GetClassInfoEx functions
cbSize = size of the structure, set to sizeof(WNDCLASSEX)
style = class styles
lpfnWndProc = pointer to the window procedure (WinProc function)
hInstance = handle to the instance that contains the window procedure for the class
lpszMenuName = pointer to null-terminated string of the window class name
hIcon and hIconSm used for window icons
hbrBackground = background of window, could be a bitmap for a picture
*/
WNDCLASSEX wClass;
ZeroMemory(&wClass, sizeof(WNDCLASSEX));
wClass.cbClsExtra = NULL;
wClass.cbSize = sizeof(WNDCLASSEX);
wClass.cbWndExtra = NULL;
wClass.hbrBackground = NULL;//CreateSolidBrush(RGB(240, 240, 240));//(HBRUSH)COLOR_WINDOW;
wClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wClass.hIcon = (HICON)LoadImage(NULL, "behlmanIcon.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);//NULL;
wClass.hIconSm = (HICON)LoadImage(NULL, "behlmanIcon.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);//NULL;
wClass.hInstance = hInst;
wClass.lpfnWndProc = (WNDPROC)WinProc;
wClass.lpszClassName = "Window Class";
wClass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
wClass.style = CS_HREDRAW | CS_VREDRAW;
//Register the class using the WNDCLASSEX structure just created
if (!RegisterClassEx(&wClass))
{
//if the registeration failed, report error
int nResult = GetLastError();
MessageBox(NULL,
"Window class creation failed\r\n",
"Window Class Failed",
MB_ICONERROR);
}
//Create a handle to the window
hWnd = CreateWindowEx(NULL,
"Window Class", //Window class name
"Windows application", //Window name (for title bar)
WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,//WS_OVERLAPPEDWINDOW, //dwStyle for the window
10, //x starting (upper left corner = 0)
10, //y starting (upper left corner = 0)
horizontalWindow, //x width
verticalWindow, //y width
NULL, //Handle to the parent window (NULL if parent)
NULL, //Handle to the menu
hInst, //Handle to the instance that contains the window procedure for the class
NULL); //Pointer to a value to be passed to the window through the createstruct
if (!hWnd)
{
//if the handle failed to be created, report error
int nResult = GetLastError();
MessageBox(NULL,
"Window creation failed\r\n",
"Window Creation Failed",
MB_ICONERROR);
}
//Set the state of the window, to display the window
ShowWindow(hWnd, nShowCmd);
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
thread t(Monitor);
//Window loop
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//_CrtDumpMemoryLeaks();
return 0;
}
LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
[再次编辑]抱歉,我没有意识到tab.h仍然包括在内......我开始通过tab.h注意到这个变量似乎导致了内存泄漏
在tab.c中
CString openCOM[26] =
{
"COM0", "COM1", "COM2", "COM3",
"COM4", "COM5", "COM6", "COM7",
"COM8", "COM9", "\\\\.\\COM10", "\\\\.\\COM11",
"\\\\.\\COM12", "\\\\.\\COM13", "\\\\.\\COM14", "\\\\.\\COM15",
"\\\\.\\COM16", "\\\\.\\COM17", "\\\\.\\COM18", "\\\\.\\COM19",
"\\\\.\\COM20", "\\\\.\\COM21", "\\\\.\\COM22", "\\\\.\\COM23",
"\\\\.\\COM24", "\\\\.\\COM25"
};
在tab.h中 extern CString openCOM [26];
当我评论CString数组时,我不再获得内存泄漏
我很困惑,我以为我自己管理自己的记忆,所以我不需要删除[]?
以下是tab.c中的内容。
#include "tab.h"
#include "resource.h"
WNDPROC prevWndProc;
HWND hWnd;
CString openCOM[26] =
{
"COM0", "COM1", "COM2", "COM3",
"COM4", "COM5", "COM6", "COM7",
"COM8", "COM9", "\\\\.\\COM10", "\\\\.\\COM11",
"\\\\.\\COM12", "\\\\.\\COM13", "\\\\.\\COM14", "\\\\.\\COM15",
"\\\\.\\COM16", "\\\\.\\COM17", "\\\\.\\COM18", "\\\\.\\COM19",
"\\\\.\\COM20", "\\\\.\\COM21", "\\\\.\\COM22", "\\\\.\\COM23",
"\\\\.\\COM24", "\\\\.\\COM25"
};
在tab.h中
#include <afx.h>
#include <Windowsx.h>
#include "commdlg.h"
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <ctime>
#include <direct.h>
#include <winsock2.h>
#include <ws2tcpip.h>
extern WNDPROC prevWndProc;
extern HWND hWnd;
extern CString openCOM[26];