<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Childwindow und MemoryAccessViolation]]></title><description><![CDATA[<p>hallihallo,</p>
<p>ich hab ein kleines problem mit einem Childwindow:<br />
Und zwar wenn ich das fenster schließe udn dann über das menü ein neues erzeugen will, kackt mir das programm mit einer AccessViolation ab. ich weiß langsam nicht mehr woran das liegen könnte.</p>
<p>Hier der Source:</p>
<pre><code class="language-cpp">#include &quot;windows.h&quot;
#include &quot;resource.h&quot;

LRESULT CALLBACK WndProc(HWND hwnd2, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK ChildProc(HWND hwnd1, UINT msg, WPARAM wParam, LPARAM lParam);

HWND hwnd_1;
HWND hwnd_2;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int cmdShow)
{
	WNDCLASSEX wc;
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.cbClsExtra = NULL;
	wc.cbWndExtra = NULL;
	wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
	wc.hIconSm = NULL;
	wc.hInstance = hInstance;
	wc.lpfnWndProc = WndProc;
	wc.lpszClassName = &quot;MyWindowClass&quot;;
	wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
	wc.style = CS_VREDRAW | CS_HREDRAW;

	if(!RegisterClassEx(&amp;wc))
		MessageBox(NULL, &quot;Windowclass not created.&quot;, &quot;Fehler&quot;, NULL);

	wc.lpfnWndProc = ChildProc;
	wc.lpszClassName = &quot;MyWindowChildClass&quot;;
	wc.lpszMenuName = NULL;

	if(!RegisterClassEx(&amp;wc))
		MessageBox(NULL, &quot;Windowclass not created.&quot;, &quot;Fehler&quot;, NULL);

	hwnd_1 = CreateWindowEx(WS_EX_APPWINDOW, &quot;MyWindowClass&quot;, &quot;Neues Fensterle&quot;,  WS_OVERLAPPEDWINDOW |  WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 800, 600, NULL, NULL, hInstance, NULL);

	ShowWindow(hwnd_1, SW_SHOW);

	MSG msg;

	while(GetMessage(&amp;msg, NULL, 0, 0))
	{
		TranslateMessage(&amp;msg);
		DispatchMessage(&amp;msg);
	}

	return 0;
}

LRESULT CALLBACK WndProc(HWND hwnd2, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_CREATE:
		{
			CreateWindowEx(WS_EX_APPWINDOW, &quot;MyWindowChildClass&quot;, &quot;Child1&quot;, WS_CHILD | WS_SYSMENU | WS_MINIMIZEBOX | WS_CAPTION | WS_VISIBLE, 0, 0, 300, 300, hwnd2, NULL, ((LPCREATESTRUCT) lParam)-&gt;hInstance, NULL);
			break;
		}
		case WM_COMMAND:
		{
			switch(LOWORD(wParam))
			{
				case ID_NEW_CHILDWINDOW:
				{
					CreateWindowEx(WS_EX_APPWINDOW, &quot;MyWindowChildClass&quot;, &quot;Child4&quot;, WS_CHILD | WS_SYSMENU | WS_MINIMIZEBOX | WS_CAPTION | WS_VISIBLE, 0, 0, 300, 300, hwnd2, NULL, ((LPCREATESTRUCT) lParam)-&gt;hInstance, NULL);
					break;
				}
				break;
			}
			break;
		}
		case WM_DESTROY:
		case WM_CLOSE:
		{
			PostQuitMessage(0);
			break;
		}
		case WM_SIZE:
		{
			return 0;
			break;
		}
	}
	return DefWindowProc(hwnd2, msg, wParam, lParam);
}

LRESULT CALLBACK ChildProc(HWND hwnd1, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_CREATE:
		{
			break;
		}
		case WM_DESTROY:
		{
			//DestroyWindow(hwnd);
			break;
		}
		case WM_CLOSE:
		{
			break;
		}
		case WM_SIZE:
		{
			return 0;
			break;
		}
	}
	return DefWindowProc(hwnd1, msg, wParam, lParam);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/166680/childwindow-und-memoryaccessviolation</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Jul 2026 01:50:30 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/166680.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 01 Dec 2006 13:13:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Childwindow und MemoryAccessViolation on Fri, 01 Dec 2006 13:13:29 GMT]]></title><description><![CDATA[<p>hallihallo,</p>
<p>ich hab ein kleines problem mit einem Childwindow:<br />
Und zwar wenn ich das fenster schließe udn dann über das menü ein neues erzeugen will, kackt mir das programm mit einer AccessViolation ab. ich weiß langsam nicht mehr woran das liegen könnte.</p>
<p>Hier der Source:</p>
<pre><code class="language-cpp">#include &quot;windows.h&quot;
#include &quot;resource.h&quot;

LRESULT CALLBACK WndProc(HWND hwnd2, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK ChildProc(HWND hwnd1, UINT msg, WPARAM wParam, LPARAM lParam);

HWND hwnd_1;
HWND hwnd_2;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int cmdShow)
{
	WNDCLASSEX wc;
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.cbClsExtra = NULL;
	wc.cbWndExtra = NULL;
	wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
	wc.hIconSm = NULL;
	wc.hInstance = hInstance;
	wc.lpfnWndProc = WndProc;
	wc.lpszClassName = &quot;MyWindowClass&quot;;
	wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
	wc.style = CS_VREDRAW | CS_HREDRAW;

	if(!RegisterClassEx(&amp;wc))
		MessageBox(NULL, &quot;Windowclass not created.&quot;, &quot;Fehler&quot;, NULL);

	wc.lpfnWndProc = ChildProc;
	wc.lpszClassName = &quot;MyWindowChildClass&quot;;
	wc.lpszMenuName = NULL;

	if(!RegisterClassEx(&amp;wc))
		MessageBox(NULL, &quot;Windowclass not created.&quot;, &quot;Fehler&quot;, NULL);

	hwnd_1 = CreateWindowEx(WS_EX_APPWINDOW, &quot;MyWindowClass&quot;, &quot;Neues Fensterle&quot;,  WS_OVERLAPPEDWINDOW |  WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 800, 600, NULL, NULL, hInstance, NULL);

	ShowWindow(hwnd_1, SW_SHOW);

	MSG msg;

	while(GetMessage(&amp;msg, NULL, 0, 0))
	{
		TranslateMessage(&amp;msg);
		DispatchMessage(&amp;msg);
	}

	return 0;
}

LRESULT CALLBACK WndProc(HWND hwnd2, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_CREATE:
		{
			CreateWindowEx(WS_EX_APPWINDOW, &quot;MyWindowChildClass&quot;, &quot;Child1&quot;, WS_CHILD | WS_SYSMENU | WS_MINIMIZEBOX | WS_CAPTION | WS_VISIBLE, 0, 0, 300, 300, hwnd2, NULL, ((LPCREATESTRUCT) lParam)-&gt;hInstance, NULL);
			break;
		}
		case WM_COMMAND:
		{
			switch(LOWORD(wParam))
			{
				case ID_NEW_CHILDWINDOW:
				{
					CreateWindowEx(WS_EX_APPWINDOW, &quot;MyWindowChildClass&quot;, &quot;Child4&quot;, WS_CHILD | WS_SYSMENU | WS_MINIMIZEBOX | WS_CAPTION | WS_VISIBLE, 0, 0, 300, 300, hwnd2, NULL, ((LPCREATESTRUCT) lParam)-&gt;hInstance, NULL);
					break;
				}
				break;
			}
			break;
		}
		case WM_DESTROY:
		case WM_CLOSE:
		{
			PostQuitMessage(0);
			break;
		}
		case WM_SIZE:
		{
			return 0;
			break;
		}
	}
	return DefWindowProc(hwnd2, msg, wParam, lParam);
}

LRESULT CALLBACK ChildProc(HWND hwnd1, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_CREATE:
		{
			break;
		}
		case WM_DESTROY:
		{
			//DestroyWindow(hwnd);
			break;
		}
		case WM_CLOSE:
		{
			break;
		}
		case WM_SIZE:
		{
			return 0;
			break;
		}
	}
	return DefWindowProc(hwnd1, msg, wParam, lParam);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1185298</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1185298</guid><dc:creator><![CDATA[VirtualDreams]]></dc:creator><pubDate>Fri, 01 Dec 2006 13:13:29 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow und MemoryAccessViolation on Fri, 01 Dec 2006 14:21:09 GMT]]></title><description><![CDATA[<p>lParam ist nur bei WM_CREATE ein LPCREATESTRUCT. Am einfachsten ist es, wenn du einfach bei WM_CREATE ((LPCREATESTRUCT) lParam)-&gt;hInstance in einer static Variable speicherst und diese dann verwendest...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1185344</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1185344</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Fri, 01 Dec 2006 14:21:09 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow und MemoryAccessViolation on Sat, 02 Dec 2006 11:26:17 GMT]]></title><description><![CDATA[<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/27a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--right_arrow"
      title=":arrow_right:"
      alt="➡"
    /> GetModuleHandle(NULL) <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1185731</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1185731</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Sat, 02 Dec 2006 11:26:17 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow und MemoryAccessViolation on Sat, 02 Dec 2006 17:55:07 GMT]]></title><description><![CDATA[<p>Funktioniert inzwischen, danke =)) :xmas1:</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1185917</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1185917</guid><dc:creator><![CDATA[VirtualDreams]]></dc:creator><pubDate>Sat, 02 Dec 2006 17:55:07 GMT</pubDate></item></channel></rss>