<?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[WinMain überladen]]></title><description><![CDATA[<p>Ok, ich programmiere seit ein paar Jahren C++, möchte mich jetzt aber mehr der Windows Programmierung widmen... ich habe zwar schon ein paar kleinigkeiten in C gemacht aber ich bin nicht in der lage folgendes beispiel welches ich fast 1:1 aus dem petzold abgeschrieben habe zum laufen zu bringen:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

LRESULT CALLBACK WndProc(HWND hwnd, unsigned int msg, WPARAM wPar, LPARAM lPar);

int WINAPI WinMain(HINSTANCE inst, HINSTANCE prevInst, LPCTSTR cmdline, int show)
{
	static TCHAR progName[] = TEXT(&quot;Test&quot;);

	WNDCLASS _wc;
	_wc.style			= CS_HREDRAW | CS_VREDRAW;
	_wc.lpfnWndProc		= WndProc;
	_wc.cbClsExtra		= 0;
	_wc.cbWndExtra		= 0;
	_wc.hbrBackground	= reinterpret_cast&lt;HBRUSH&gt; (GetStockObject(WHITE_BRUSH));
	_wc.hCursor			= LoadCursor(0, IDC_ARROW);
	_wc.hIcon			= LoadIcon(0, IDI_APPLICATION);
	_wc.hInstance		= inst;
	_wc.lpszClassName	= progName;

	if (!RegisterClass (&amp;_wc))
	{
		MessageBox(NULL, TEXT(&quot;Fehler: RegisterClass()&quot;), TEXT(&quot;Fehlermeldung&quot;), MB_ICONERROR);
		return 0;
	}

	HWND hwnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, progName, TEXT(&quot;Testprogramm&quot;), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
		NULL, NULL, inst, NULL);
	ShowWindow(hwnd, show);
	UpdateWindow(hwnd);

	MSG msg;
	while(GetMessage(&amp;msg, NULL, NULL, NULL))
	{
		TranslateMessage(&amp;msg);
		DispatchMessage(&amp;msg);
	}
	return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, unsigned int msg, WPARAM wPar, LPARAM lPar)
{
	switch(msg)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	default:
		break;
	}
	return DefWindowProc(hwnd, msg, wPar, lPar);
}
</code></pre>
<p>Das ganze meldet nur einen Fehler:</p>
<p>d:\in Arbeit\Win32\Lib\Basic\basic.cpp(6): error C2731: 'WinMain' : function cannot be overloaded</p>
<p>Ich habe keine Ahnung woran das liegt... eventuell Compilerswitch oder direkt ein Fehler in dem was ich abgeschrieben hab?? wobei ich letzeres eher bezweifel.<br />
ich arbeite mit VC7.0 unter WindowsXP</p>
<p>Vielen Dank im Voraus für Hilfe</p>
<p>lg DGATmaster</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/112604/winmain-überladen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 01 Jul 2026 08:20:13 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/112604.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 14 Jun 2005 11:33:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to WinMain überladen on Tue, 14 Jun 2005 11:33:02 GMT]]></title><description><![CDATA[<p>Ok, ich programmiere seit ein paar Jahren C++, möchte mich jetzt aber mehr der Windows Programmierung widmen... ich habe zwar schon ein paar kleinigkeiten in C gemacht aber ich bin nicht in der lage folgendes beispiel welches ich fast 1:1 aus dem petzold abgeschrieben habe zum laufen zu bringen:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

LRESULT CALLBACK WndProc(HWND hwnd, unsigned int msg, WPARAM wPar, LPARAM lPar);

int WINAPI WinMain(HINSTANCE inst, HINSTANCE prevInst, LPCTSTR cmdline, int show)
{
	static TCHAR progName[] = TEXT(&quot;Test&quot;);

	WNDCLASS _wc;
	_wc.style			= CS_HREDRAW | CS_VREDRAW;
	_wc.lpfnWndProc		= WndProc;
	_wc.cbClsExtra		= 0;
	_wc.cbWndExtra		= 0;
	_wc.hbrBackground	= reinterpret_cast&lt;HBRUSH&gt; (GetStockObject(WHITE_BRUSH));
	_wc.hCursor			= LoadCursor(0, IDC_ARROW);
	_wc.hIcon			= LoadIcon(0, IDI_APPLICATION);
	_wc.hInstance		= inst;
	_wc.lpszClassName	= progName;

	if (!RegisterClass (&amp;_wc))
	{
		MessageBox(NULL, TEXT(&quot;Fehler: RegisterClass()&quot;), TEXT(&quot;Fehlermeldung&quot;), MB_ICONERROR);
		return 0;
	}

	HWND hwnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, progName, TEXT(&quot;Testprogramm&quot;), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
		NULL, NULL, inst, NULL);
	ShowWindow(hwnd, show);
	UpdateWindow(hwnd);

	MSG msg;
	while(GetMessage(&amp;msg, NULL, NULL, NULL))
	{
		TranslateMessage(&amp;msg);
		DispatchMessage(&amp;msg);
	}
	return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, unsigned int msg, WPARAM wPar, LPARAM lPar)
{
	switch(msg)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	default:
		break;
	}
	return DefWindowProc(hwnd, msg, wPar, lPar);
}
</code></pre>
<p>Das ganze meldet nur einen Fehler:</p>
<p>d:\in Arbeit\Win32\Lib\Basic\basic.cpp(6): error C2731: 'WinMain' : function cannot be overloaded</p>
<p>Ich habe keine Ahnung woran das liegt... eventuell Compilerswitch oder direkt ein Fehler in dem was ich abgeschrieben hab?? wobei ich letzeres eher bezweifel.<br />
ich arbeite mit VC7.0 unter WindowsXP</p>
<p>Vielen Dank im Voraus für Hilfe</p>
<p>lg DGATmaster</p>
]]></description><link>https://www.c-plusplus.net/forum/post/808901</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/808901</guid><dc:creator><![CDATA[DGATmaster]]></dc:creator><pubDate>Tue, 14 Jun 2005 11:33:02 GMT</pubDate></item><item><title><![CDATA[Reply to WinMain überladen on Tue, 14 Jun 2005 11:46:08 GMT]]></title><description><![CDATA[<p>ok, mittlerweile läst sich das ganz kompilieren,<br />
das problem war das LPCTSTR in der Parameterliste von WinMain mit LPSTR funktioniert es...<br />
dafür erhalte ich jetzt eine Exception bei RegisterClass(&amp;_wc);<br />
echt schlimm... mit VC6 hat dieses beispiel nie probleme gemacht...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/808915</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/808915</guid><dc:creator><![CDATA[DGATmaster]]></dc:creator><pubDate>Tue, 14 Jun 2005 11:46:08 GMT</pubDate></item><item><title><![CDATA[Reply to WinMain überladen on Tue, 14 Jun 2005 11:52:57 GMT]]></title><description><![CDATA[<p><a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/winmain.asp" rel="nofollow">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/winmain.asp</a></p>
<p>dritter param<br />
LPSTR == char*<br />
LPCTSTR == const char*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/808924</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/808924</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Tue, 14 Jun 2005 11:52:57 GMT</pubDate></item><item><title><![CDATA[Reply to WinMain überladen on Tue, 14 Jun 2005 11:55:00 GMT]]></title><description><![CDATA[<p>DGATmaster schrieb:</p>
<blockquote>
<p>dafür erhalte ich jetzt eine Exception bei RegisterClass(&amp;_wc);</p>
</blockquote>
<p>und wie sieht die aus?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/808928</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/808928</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Tue, 14 Jun 2005 11:55:00 GMT</pubDate></item><item><title><![CDATA[Reply to WinMain überladen on Tue, 14 Jun 2005 12:08:11 GMT]]></title><description><![CDATA[<p>Es tritt folgende Fehlermeldung beim Aufruf von RegisterClass auf:</p>
<p>Unhandled exception at 0x77d269e1 in Basis.exe: 0xC0000005: Access violation reading location 0xcccccccc.</p>
<p>kA was das soll... spielt da eventuell die .Net CLR mit oder warum ist das so?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/808942</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/808942</guid><dc:creator><![CDATA[DGATmaster]]></dc:creator><pubDate>Tue, 14 Jun 2005 12:08:11 GMT</pubDate></item><item><title><![CDATA[Reply to WinMain überladen on Tue, 14 Jun 2005 13:21:01 GMT]]></title><description><![CDATA[<p>du hast bei der initialisierung von _wc</p>
<pre><code class="language-cpp">_wc.lpszMenuName = NULL;
</code></pre>
<p>vergessen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/809000</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/809000</guid><dc:creator><![CDATA[Konfusius]]></dc:creator><pubDate>Tue, 14 Jun 2005 13:21:01 GMT</pubDate></item><item><title><![CDATA[Reply to WinMain überladen on Tue, 14 Jun 2005 14:26:06 GMT]]></title><description><![CDATA[<p>miller_m schrieb:</p>
<blockquote>
<p>dritter param<br />
LPSTR == char*<br />
LPCTSTR == const char*</p>
</blockquote>
<p>Fast</p>
<pre><code class="language-cpp">LPSTR == char*
LPCTSTR == const TCHAR*
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/809072</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/809072</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Tue, 14 Jun 2005 14:26:06 GMT</pubDate></item><item><title><![CDATA[Reply to WinMain überladen on Tue, 14 Jun 2005 14:32:11 GMT]]></title><description><![CDATA[<p>groovemaster schrieb:</p>
<blockquote>
<p>miller_m schrieb:</p>
<blockquote>
<p>dritter param<br />
LPSTR == char*<br />
LPCTSTR == const char*</p>
</blockquote>
<p>Fast</p>
<pre><code class="language-cpp">LPSTR == char*
LPCTSTR == const TCHAR*
</code></pre>
</blockquote>
<p>hätte ich mal nachgeschaut <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/809082</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/809082</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Tue, 14 Jun 2005 14:32:11 GMT</pubDate></item><item><title><![CDATA[Reply to WinMain überladen on Tue, 14 Jun 2005 15:13:01 GMT]]></title><description><![CDATA[<p>ok, danke erstmal für die vielen rückmeldungen...<br />
soweit ich weiß ist:</p>
<pre><code class="language-cpp">LPSTR TCHAR*
LPCTSTR const TCHAR*
und TCHAR entweder char oder wchar
</code></pre>
<p>dieses problem hat sich zum glück bereits gelöst...<br />
leider tritt trotz _wc.lpszMenuName = NULL; bzw _wc.lpszMenuName = 0; die bereits erwähnte Exception auf...<br />
habe die komplette _wc memberinitialisierung auskommentiert und schrittweise die zeilen mit HINSTANCE und WNDPROC wieder hinzugefügt... logischerweise treten wenn diese fehlen entsprechende Fehler auf...</p>
<p>im Moment siehts so aus:</p>
<pre><code class="language-cpp">_wc.cbSize			= sizeof(WNDCLASSEX);
	_wc.style			= CS_HREDRAW | CS_VREDRAW;
	_wc.lpfnWndProc		= WndProc;
	_wc.cbClsExtra		= 0;
	_wc.cbWndExtra		= 0;
	_wc.hbrBackground	= (HBRUSH) (GetStockObject(WHITE_BRUSH));
	_wc.hCursor			= LoadCursor(0, IDC_ARROW);
	_wc.hIcon			= LoadIcon(0, IDI_APPLICATION);
	_wc.lpszMenuName	= 0;
	_wc.hInstance		= inst;
	_wc.lpszClassName	= progName;

	try
	{
		if (!RegisterClassEx (&amp;_wc))
		{
			throw 0;
			MessageBox(NULL, &quot;Fehler: RegisterClass()&quot;, &quot;Fehlermeldung&quot;, MB_ICONERROR);
			return 0;
		}
	}
	catch(...)
	{
		char temp[128];
		FormatMessage( 
			FORMAT_MESSAGE_FROM_SYSTEM | 
			FORMAT_MESSAGE_IGNORE_INSERTS,
			NULL,
			GetLastError(),
			MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
			temp,
			128,
			NULL );
		MessageBox(0, temp, &quot;Fehler!&quot;,MB_ICONERROR);
	}
</code></pre>
<p>der rest ist gleichgeblieben und ich bekomme den fehler falscher Parameter...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/809120</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/809120</guid><dc:creator><![CDATA[DGATmaster]]></dc:creator><pubDate>Tue, 14 Jun 2005 15:13:01 GMT</pubDate></item><item><title><![CDATA[Reply to WinMain überladen on Tue, 14 Jun 2005 15:30:49 GMT]]></title><description><![CDATA[<p>DGATmaster schrieb:</p>
<blockquote>
<p>soweit ich weiß ist:</p>
<pre><code class="language-cpp">LPSTR TCHAR*
LPCTSTR const TCHAR*
und TCHAR entweder char oder wchar
</code></pre>
</blockquote>
<p>Nicht ganz, LPSTR ist schon char*. LPTSTR ist TCHAR*.</p>
<p>DGATmaster schrieb:</p>
<blockquote>
<p>im Moment siehts so aus:</p>
<pre><code class="language-cpp">_wc.cbSize			= sizeof(WNDCLASSEX);
	_wc.style			= CS_HREDRAW | CS_VREDRAW;
	_wc.lpfnWndProc		= WndProc;
	_wc.cbClsExtra		= 0;
	_wc.cbWndExtra		= 0;
	_wc.hbrBackground	= (HBRUSH) (GetStockObject(WHITE_BRUSH));
	_wc.hCursor			= LoadCursor(0, IDC_ARROW);
	_wc.hIcon			= LoadIcon(0, IDI_APPLICATION);
	_wc.lpszMenuName	= 0;
	_wc.hInstance		= inst;
	_wc.lpszClassName	= progName;
</code></pre>
</blockquote>
<p>_wc ist aber schon noch vom Typ WNDCLASS? Dann solltest du auch sizeof WNDCLASS schreiben. Oder noch besser sizeof _wc. (und lass den Unterstrich bei _wc weg)<br />
Es heisst übrigens &amp;WndProc. Dass dein Compiler das ohne Adress Operator akzeptiert, ist eine dumme MS Angewohnheit.</p>
<p>DGATmaster schrieb:</p>
<blockquote>
<pre><code class="language-cpp">try
	{
		if (!RegisterClassEx (&amp;_wc))
		{
			throw 0;
			MessageBox(NULL, &quot;Fehler: RegisterClass()&quot;, &quot;Fehlermeldung&quot;, MB_ICONERROR);
			return 0;
		}
	}
</code></pre>
</blockquote>
<p>Was du hier machst, ist eigentlich Bödsinn. Alles was nach throw kommt, wird nie ausgeführt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/809125</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/809125</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Tue, 14 Jun 2005 15:30:49 GMT</pubDate></item><item><title><![CDATA[Reply to WinMain überladen on Tue, 14 Jun 2005 15:33:16 GMT]]></title><description><![CDATA[<p>ok das was nach throw kommt is bei mir im editor schon auskommentiert...<br />
und _wc is vom Type WNDCLASSEX, das habe ich auch noch verändert aber vergessen zu sagen<br />
den Unterstrich hab ich deswegen da ich das nachher in ein oder zwei Klassen verpacken werde und alle Klasseninternen Variablen mit _ beginne...<br />
sofern es funktionieren würde...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/809131</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/809131</guid><dc:creator><![CDATA[DGATmaster]]></dc:creator><pubDate>Tue, 14 Jun 2005 15:33:16 GMT</pubDate></item><item><title><![CDATA[Reply to WinMain überladen on Tue, 14 Jun 2005 15:46:59 GMT]]></title><description><![CDATA[<p>Wenn du WNDCLASSEX nimmst, was ist dann mit _wc.hIconSm?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/809135</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/809135</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Tue, 14 Jun 2005 15:46:59 GMT</pubDate></item><item><title><![CDATA[Reply to WinMain überladen on Tue, 14 Jun 2005 15:57:00 GMT]]></title><description><![CDATA[<p>thx an groovemaster...<br />
das wars dann wohl...<br />
aber warum hat es vorher mit WNDCLASS nicht funktioniert???<br />
naja... egal... es funktioniert...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/809145</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/809145</guid><dc:creator><![CDATA[DGATmaster]]></dc:creator><pubDate>Tue, 14 Jun 2005 15:57:00 GMT</pubDate></item><item><title><![CDATA[Reply to WinMain überladen on Tue, 14 Jun 2005 16:04:21 GMT]]></title><description><![CDATA[<p>DGATmaster schrieb:</p>
<blockquote>
<p>aber warum hat es vorher mit WNDCLASS nicht funktioniert???</p>
</blockquote>
<p>So genau kann man deine Änderungen leider nicht nachvollziehen. Aber bei deinem ersten Post fehlt die Initialisierung von _wc.cbSize und _wc.lpszMenuName.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/809154</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/809154</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Tue, 14 Jun 2005 16:04:21 GMT</pubDate></item><item><title><![CDATA[Reply to WinMain überladen on Tue, 14 Jun 2005 16:06:18 GMT]]></title><description><![CDATA[<p>ja, das wars... danke für die hilfe!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/809155</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/809155</guid><dc:creator><![CDATA[DGATmaster]]></dc:creator><pubDate>Tue, 14 Jun 2005 16:06:18 GMT</pubDate></item></channel></rss>