VC内存栈溢出_求解
#include <Windows.h>
#include <stdio.h>
HWND g_hWnd;
HRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
bool initWin(HINSTANCE hInstance, LPCTSTR pClassName, LPCTSTR pAppName)
{
WNDCLASS wc;
wc.cbClsExtra = 4;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hCursor = 0;
wc.hIcon = 0;
wc.hInstance = hInstance;
wc.lpfnWndProc = (WNDPROC)WindowProc;
wc.lpszClassName = pClassName;
wc.lpszMenuName = 0;
wc.style = CS_HREDRAW|CS_VREDRAW;
if (!RegisterClass(&wc))
{
return false;
}
g_hWnd = CreateWindow(pClassName, pAppName, WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
if (!g_hWnd)
{
return false;
}
ShowWindow(g_hWnd, SW_SHOW);
UpdateWindow(g_hWnd);
return true;
}
HRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
PostQuitMessage(0);
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
int CALLBACK WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in LPSTR lpCmdLine, __in int nShowCmd )
{
LPCTSTR pClassName = TEXT("WinMsgClass");
LPCTSTR pAppName = TEXT("WinMsgApp");
initWin(hInstance, pClassName, pAppName);
int a = 100;
SetClassLong(g_hWnd, 0L, a);
int b = GetClassLong(g_hWnd, 0);
TCHAR buf[9] = {0};
int size = sizeof("CLS: %d"); //运行后,当点击了对话按钮后,点击窗口关闭按钮时出错。程序回弹出中断程序对话框
swprintf_s(buf, sizeof(buf), TEXT("CLS: %d"), b);
::MessageBox(0, buf, 0, 0);
MSG msg;
ZeroMemory(&msg, sizeof(msg));
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
#include <stdio.h>
HWND g_hWnd;
HRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
bool initWin(HINSTANCE hInstance, LPCTSTR pClassName, LPCTSTR pAppName)
{
WNDCLASS wc;
wc.cbClsExtra = 4;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hCursor = 0;
wc.hIcon = 0;
wc.hInstance = hInstance;
wc.lpfnWndProc = (WNDPROC)WindowProc;
wc.lpszClassName = pClassName;
wc.lpszMenuName = 0;
wc.style = CS_HREDRAW|CS_VREDRAW;
if (!RegisterClass(&wc))
{
return false;
}
g_hWnd = CreateWindow(pClassName, pAppName, WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
if (!g_hWnd)
{
return false;
}
ShowWindow(g_hWnd, SW_SHOW);
UpdateWindow(g_hWnd);
return true;
}
HRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
PostQuitMessage(0);
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
int CALLBACK WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in LPSTR lpCmdLine, __in int nShowCmd )
{
LPCTSTR pClassName = TEXT("WinMsgClass");
LPCTSTR pAppName = TEXT("WinMsgApp");
initWin(hInstance, pClassName, pAppName);
int a = 100;
SetClassLong(g_hWnd, 0L, a);
int b = GetClassLong(g_hWnd, 0);
TCHAR buf[9] = {0};
int size = sizeof("CLS: %d"); //运行后,当点击了对话按钮后,点击窗口关闭按钮时出错。程序回弹出中断程序对话框
swprintf_s(buf, sizeof(buf), TEXT("CLS: %d"), b);
::MessageBox(0, buf, 0, 0);
MSG msg;
ZeroMemory(&msg, sizeof(msg));
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
...全文
相关推荐
vc6实现监控程序内存使用情况
介绍见 http://blog.csdn.net/usister/article/details/74388537
VC++6.0迷宫游戏开发:MFC框架下的图形绘制与算法实现
图形用户界面(GUI)编程是桌面应用开发的核心,其原理在于通过事件驱动模型响应用户操作,并在屏幕上绘制视觉元素。在Windows平台,这一过程传统上依赖于GDI(图形设备接口)等底层API进行像素级绘图,而MFC(Microsoft Foundation Classes)框架则对其进行了封装,提供了更高效的开发范式。其技术价值在于,开发者可以专注于业务逻辑与算法实现,而非繁琐的窗口管理细节,从而快速构建稳定、交互性强的原生应用。典型的应用场景包括工具软件、教育演示程序以及轻量级游戏开发。本文以经典的迷宫游戏
栈溢出攻击技术 windows linux下的都有
缓冲区溢出攻击简介 基本概念及发展历史 背景知识 (Linux & win32) 缓冲区溢出攻击的原理 栈溢出攻击如何工作? Linux: 栈溢出, shellcode Win32: 栈溢出, shellcode 总结 有需要的话,我有光盘。可以找我。
C语言深度剖析_Vc_
C 语言深度解剖未出版 PDF,解开程序员面试笔试的秘密,以含金量勇敢挑战国内外同类书籍
rapidxml for vc6
rapidxml在vc6.0下运行,已测试通过可用。



