<?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[[SOCKETS] Windows bekommt keine definierte Socket notify Meldung]]></title><description><![CDATA[<p>Hi Leute,</p>
<p>ich arbeite grade an einem Chatprogramm um mich etwas mit den Winsocks außeinander zu setzen. Jetzt habe ich allerdings ein Prob:</p>
<p>Wenn ich hiermit eine Nachricht definiere die Windows an mein Fenster senden soll</p>
<pre><code class="language-cpp">WSAAsyncSelect(sock,hDlg,WM_SOCKET_NOTIFY,FD_CONNECT|FD_READ|FD_CLOSE);
</code></pre>
<p>Und das natürlich auch noch definiere</p>
<pre><code class="language-cpp">#define WM_SOCKET_NOTIFY (WM_USER + 1)
</code></pre>
<p>müsste mein Programm doch in der Callbackschleife eine Messagebox ausgeben, wenn ich Daten empfange.<br />
Allerdings tut es das nicht, ich weiß aber zu 100%, dass Daten gesendet werden.</p>
<p>Mein kompletter Code:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;shlwapi.h&gt;
#include &quot;resource.h&quot;
#define WM_SOCKET_NOTIFY (WM_USER + 1)

WSADATA	WSAData;
SOCKET sock; // Der hauptsocket, muss global sein!

HWND hDlg;

HWND hwnd_edit_ip;
HWND hwnd_edit_port;
HWND hwnd_cmd_verbinden;
HWND hwnd_edit_verlauf;
HWND hwnd_edit_eingabe;

bool verbunden = 0;
// Prototypen
BOOL CALLBACK DlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
BOOL edit_addline(HWND hWnd, UINT uIndex, LPCTSTR lpText);
void send_message(LPCTSTR textstring);
bool verbinden(void);

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{

	 DialogBox(hInstance,&quot;IDD_Start&quot;,NULL,DlgProc);

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

BOOL CALLBACK DlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
	case WM_INITDIALOG:

		hwnd_edit_ip = GetDlgItem(hDlg,IDC_IPADRESS);
		hwnd_edit_port = GetDlgItem(hDlg,IDC_PORT);
		hwnd_cmd_verbinden = GetDlgItem(hDlg,IDC_CONNECT);
		hwnd_edit_verlauf = GetDlgItem(hDlg,IDC_VERLAUF);
		hwnd_edit_eingabe = GetDlgItem(hDlg,IDC_EINGABE);

       	SendMessage(hwnd_edit_ip,WM_SETTEXT,0,(long)&quot;192.168.0.2&quot;);
		SendMessage(hwnd_edit_port,WM_SETTEXT,0,(long)&quot;12345&quot;);

		return TRUE;
	break;

	case WM_SOCKET_NOTIFY:
		MessageBox(NULL,&quot;Der Socket wird angesprochen!&quot;,&quot;Hinweis&quot;,MB_OK);
		switch(LOWORD(lParam)) {
		case FD_READ:
			MessageBox(NULL,&quot;Daten zum lesen bereit!&quot;,&quot;Hinweis&quot;,MB_OK);
			break;
		}
	break;

	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		case CMD_CANCEL:
			PostQuitMessage(0);
			break;
		case IDC_CONNECT:
			verbinden();
			break;

		case IDC_SEND:
			char nachricht[99];
		SendMessage(hwnd_edit_eingabe,WM_GETTEXT,99,(long)nachricht);
		SendMessage(hwnd_edit_eingabe,WM_SETTEXT,NULL,NULL);
		send_message(nachricht);
		edit_addline(hwnd_edit_verlauf,0,&quot;Client: &quot;);
		edit_addline(hwnd_edit_verlauf,0,nachricht);
		edit_addline(hwnd_edit_verlauf,0,&quot;\r\n&quot;);

			break;
		}
		break;

	case WM_DESTROY :
         PostQuitMessage (0) ;
         break;

}
return FALSE;
}

bool verbinden(void) {

	if (verbunden) { // Verbindung beenden
	SendMessage(hwnd_cmd_verbinden,WM_SETTEXT,0,(long)&quot;Verbindung herstellen&quot;);

	closesocket(sock);
	WSACleanup();
	verbunden = 0;	
	edit_addline(hwnd_edit_verlauf,0,&quot;** Verbindung zum Server abgebrochen!\r\n&quot;);

	} else { // Verbindung starten

		// WErte abrufen (IP und Port)

		char serverip[16];
		SendMessage(hwnd_edit_ip,WM_GETTEXT,16,(long)serverip);
		char port[6];
		SendMessage(hwnd_edit_port,WM_GETTEXT,6,(long)port);
		int serverport = StrToInt(port);	

	// Socket erstellen

	WSAStartup(MAKEWORD(2,0),&amp;WSAData);

	sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); // socket erstellen

	sockaddr_in sa;
	sa.sin_family = AF_INET;
	sa.sin_port = htons(serverport);
	sa.sin_addr.S_un.S_addr = inet_addr(serverip);

	if(connect(sock,(SOCKADDR*)&amp;sa,sizeof(sa))==SOCKET_ERROR){
		MessageBox(0,&quot;Es konnte keine Verbindung zum Server aufgebaut werden&quot;,&quot;Fehler&quot;,MB_OK | MB_ICONEXCLAMATION); return false;
	} else { 
	WSAAsyncSelect(sock,hDlg,WM_SOCKET_NOTIFY,FD_CONNECT|FD_READ|FD_CLOSE);

	SendMessage(hwnd_cmd_verbinden,WM_SETTEXT,0,(long)&quot;Verbindung schließen&quot;);
	edit_addline(hwnd_edit_verlauf,0,&quot;** Verbindung zum Server erfolgreich gestartet!\r\n&quot;);
	verbunden = 1;

}
	} 

	return true;
}

BOOL edit_addline(HWND hWnd, UINT uIndex, LPCTSTR lpText)
{
	uIndex = 100;
   DWORD dwSelStart = 0, dwSelEnd = 0;
   UINT  uLine, uNumChars = 0;

   SendMessage(hWnd, EM_GETSEL, (WPARAM)&amp;dwSelStart, (LPARAM)&amp;dwSelEnd);

   for(uLine = 0; uLine &lt; uIndex; uLine++)
      uNumChars += (UINT)(SendMessage(hWnd, EM_LINELENGTH, (WPARAM)uNumChars, 0) + 2);

   SendMessage(hWnd, EM_SETSEL, (WPARAM)uNumChars, (LPARAM)uNumChars);
   SendMessage(hWnd, EM_REPLACESEL, (WPARAM)FALSE, (LPARAM)lpText);
   SendMessage(hWnd, EM_SETSEL, (WPARAM)dwSelStart, (LPARAM)dwSelEnd);

   return(TRUE);
}

void send_message(LPCTSTR textstring) { // Mit dieser Funktion werden Nachrichten versendet

send(sock,textstring,strlen(textstring),0);

}
</code></pre>
<p>MFG und hochachtungsvoll, Rodney</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/71107/sockets-windows-bekommt-keine-definierte-socket-notify-meldung</link><generator>RSS for Node</generator><lastBuildDate>Thu, 09 Apr 2026 17:19:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/71107.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 14 Apr 2004 21:13:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [SOCKETS] Windows bekommt keine definierte Socket notify Meldung on Wed, 14 Apr 2004 21:13:34 GMT]]></title><description><![CDATA[<p>Hi Leute,</p>
<p>ich arbeite grade an einem Chatprogramm um mich etwas mit den Winsocks außeinander zu setzen. Jetzt habe ich allerdings ein Prob:</p>
<p>Wenn ich hiermit eine Nachricht definiere die Windows an mein Fenster senden soll</p>
<pre><code class="language-cpp">WSAAsyncSelect(sock,hDlg,WM_SOCKET_NOTIFY,FD_CONNECT|FD_READ|FD_CLOSE);
</code></pre>
<p>Und das natürlich auch noch definiere</p>
<pre><code class="language-cpp">#define WM_SOCKET_NOTIFY (WM_USER + 1)
</code></pre>
<p>müsste mein Programm doch in der Callbackschleife eine Messagebox ausgeben, wenn ich Daten empfange.<br />
Allerdings tut es das nicht, ich weiß aber zu 100%, dass Daten gesendet werden.</p>
<p>Mein kompletter Code:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;shlwapi.h&gt;
#include &quot;resource.h&quot;
#define WM_SOCKET_NOTIFY (WM_USER + 1)

WSADATA	WSAData;
SOCKET sock; // Der hauptsocket, muss global sein!

HWND hDlg;

HWND hwnd_edit_ip;
HWND hwnd_edit_port;
HWND hwnd_cmd_verbinden;
HWND hwnd_edit_verlauf;
HWND hwnd_edit_eingabe;

bool verbunden = 0;
// Prototypen
BOOL CALLBACK DlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
BOOL edit_addline(HWND hWnd, UINT uIndex, LPCTSTR lpText);
void send_message(LPCTSTR textstring);
bool verbinden(void);

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{

	 DialogBox(hInstance,&quot;IDD_Start&quot;,NULL,DlgProc);

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

BOOL CALLBACK DlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
	case WM_INITDIALOG:

		hwnd_edit_ip = GetDlgItem(hDlg,IDC_IPADRESS);
		hwnd_edit_port = GetDlgItem(hDlg,IDC_PORT);
		hwnd_cmd_verbinden = GetDlgItem(hDlg,IDC_CONNECT);
		hwnd_edit_verlauf = GetDlgItem(hDlg,IDC_VERLAUF);
		hwnd_edit_eingabe = GetDlgItem(hDlg,IDC_EINGABE);

       	SendMessage(hwnd_edit_ip,WM_SETTEXT,0,(long)&quot;192.168.0.2&quot;);
		SendMessage(hwnd_edit_port,WM_SETTEXT,0,(long)&quot;12345&quot;);

		return TRUE;
	break;

	case WM_SOCKET_NOTIFY:
		MessageBox(NULL,&quot;Der Socket wird angesprochen!&quot;,&quot;Hinweis&quot;,MB_OK);
		switch(LOWORD(lParam)) {
		case FD_READ:
			MessageBox(NULL,&quot;Daten zum lesen bereit!&quot;,&quot;Hinweis&quot;,MB_OK);
			break;
		}
	break;

	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		case CMD_CANCEL:
			PostQuitMessage(0);
			break;
		case IDC_CONNECT:
			verbinden();
			break;

		case IDC_SEND:
			char nachricht[99];
		SendMessage(hwnd_edit_eingabe,WM_GETTEXT,99,(long)nachricht);
		SendMessage(hwnd_edit_eingabe,WM_SETTEXT,NULL,NULL);
		send_message(nachricht);
		edit_addline(hwnd_edit_verlauf,0,&quot;Client: &quot;);
		edit_addline(hwnd_edit_verlauf,0,nachricht);
		edit_addline(hwnd_edit_verlauf,0,&quot;\r\n&quot;);

			break;
		}
		break;

	case WM_DESTROY :
         PostQuitMessage (0) ;
         break;

}
return FALSE;
}

bool verbinden(void) {

	if (verbunden) { // Verbindung beenden
	SendMessage(hwnd_cmd_verbinden,WM_SETTEXT,0,(long)&quot;Verbindung herstellen&quot;);

	closesocket(sock);
	WSACleanup();
	verbunden = 0;	
	edit_addline(hwnd_edit_verlauf,0,&quot;** Verbindung zum Server abgebrochen!\r\n&quot;);

	} else { // Verbindung starten

		// WErte abrufen (IP und Port)

		char serverip[16];
		SendMessage(hwnd_edit_ip,WM_GETTEXT,16,(long)serverip);
		char port[6];
		SendMessage(hwnd_edit_port,WM_GETTEXT,6,(long)port);
		int serverport = StrToInt(port);	

	// Socket erstellen

	WSAStartup(MAKEWORD(2,0),&amp;WSAData);

	sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); // socket erstellen

	sockaddr_in sa;
	sa.sin_family = AF_INET;
	sa.sin_port = htons(serverport);
	sa.sin_addr.S_un.S_addr = inet_addr(serverip);

	if(connect(sock,(SOCKADDR*)&amp;sa,sizeof(sa))==SOCKET_ERROR){
		MessageBox(0,&quot;Es konnte keine Verbindung zum Server aufgebaut werden&quot;,&quot;Fehler&quot;,MB_OK | MB_ICONEXCLAMATION); return false;
	} else { 
	WSAAsyncSelect(sock,hDlg,WM_SOCKET_NOTIFY,FD_CONNECT|FD_READ|FD_CLOSE);

	SendMessage(hwnd_cmd_verbinden,WM_SETTEXT,0,(long)&quot;Verbindung schließen&quot;);
	edit_addline(hwnd_edit_verlauf,0,&quot;** Verbindung zum Server erfolgreich gestartet!\r\n&quot;);
	verbunden = 1;

}
	} 

	return true;
}

BOOL edit_addline(HWND hWnd, UINT uIndex, LPCTSTR lpText)
{
	uIndex = 100;
   DWORD dwSelStart = 0, dwSelEnd = 0;
   UINT  uLine, uNumChars = 0;

   SendMessage(hWnd, EM_GETSEL, (WPARAM)&amp;dwSelStart, (LPARAM)&amp;dwSelEnd);

   for(uLine = 0; uLine &lt; uIndex; uLine++)
      uNumChars += (UINT)(SendMessage(hWnd, EM_LINELENGTH, (WPARAM)uNumChars, 0) + 2);

   SendMessage(hWnd, EM_SETSEL, (WPARAM)uNumChars, (LPARAM)uNumChars);
   SendMessage(hWnd, EM_REPLACESEL, (WPARAM)FALSE, (LPARAM)lpText);
   SendMessage(hWnd, EM_SETSEL, (WPARAM)dwSelStart, (LPARAM)dwSelEnd);

   return(TRUE);
}

void send_message(LPCTSTR textstring) { // Mit dieser Funktion werden Nachrichten versendet

send(sock,textstring,strlen(textstring),0);

}
</code></pre>
<p>MFG und hochachtungsvoll, Rodney</p>
]]></description><link>https://www.c-plusplus.net/forum/post/501622</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/501622</guid><dc:creator><![CDATA[Rodney]]></dc:creator><pubDate>Wed, 14 Apr 2004 21:13:34 GMT</pubDate></item><item><title><![CDATA[Reply to [SOCKETS] Windows bekommt keine definierte Socket notify Meldung on Wed, 14 Apr 2004 21:54:37 GMT]]></title><description><![CDATA[<p>Ich kann keinen Fehler erkennen Rodney, ich mache das gleich wie Du und das funktioniert top...<br />
Vielleicht fehlen ein zwei breaks, bzw. schreibe das doch etwas schöner auf:</p>
<pre><code class="language-cpp">case WM_SOCKET_NOTIFY:
{
	MessageBox(0, &quot;Der Socket wird angesprochen!&quot;, &quot;Hinweis&quot;, 0);
	switch(lParam)
	{
		case FD_READ:
		{
			MessageBox(0, &quot;Daten zum lesen bereit!&quot;, &quot;Hinweis&quot;, 0);
			break;
		}
		break;
	}
	break;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/501645</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/501645</guid><dc:creator><![CDATA[ChrisK]]></dc:creator><pubDate>Wed, 14 Apr 2004 21:54:37 GMT</pubDate></item><item><title><![CDATA[Reply to [SOCKETS] Windows bekommt keine definierte Socket notify Meldung on Wed, 14 Apr 2004 21:57:05 GMT]]></title><description><![CDATA[<p>hDlg wird nicht initialisiert!<br />
Scheiß globale Variablen...</p>
<p>Die MessageLoop kannst du in diesem Fall weg lassen.</p>
<p>Ein Dialog beendet man mit EndDialog() nicht mit PostQuitMessage()</p>
]]></description><link>https://www.c-plusplus.net/forum/post/501648</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/501648</guid><dc:creator><![CDATA[D*niel *chumann]]></dc:creator><pubDate>Wed, 14 Apr 2004 21:57:05 GMT</pubDate></item><item><title><![CDATA[Reply to [SOCKETS] Windows bekommt keine definierte Socket notify Meldung on Wed, 14 Apr 2004 22:01:25 GMT]]></title><description><![CDATA[<p>Stimmt ja,<br />
schreib einfach oben statt HWND hDlg; --&gt; HWND hMainDlg; und dann schreibe noch:</p>
<p>BOOL CALLBACK DlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)<br />
{<br />
hMainDlg = hDlg;<br />
switch(message)<br />
{<br />
case WM_INITDIALOG:<br />
// ....</p>
<p>Sollte gehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/501651</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/501651</guid><dc:creator><![CDATA[ChrisK]]></dc:creator><pubDate>Wed, 14 Apr 2004 22:01:25 GMT</pubDate></item><item><title><![CDATA[Reply to [SOCKETS] Windows bekommt keine definierte Socket notify Meldung on Thu, 15 Apr 2004 07:39:02 GMT]]></title><description><![CDATA[<p>Da die Variable global ist, langt es sie in WM_INITDIALOG zu initialisieren und nicht bei jedem Aufruf von DlgProc.</p>
<p>Man muss die globale Variable nicht umbenennen, man kann in DlgProc auch mit</p>
<pre><code>::hDlg=hDlg;
</code></pre>
<p>darauf zugreifen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/501773</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/501773</guid><dc:creator><![CDATA[D*niel *chumann]]></dc:creator><pubDate>Thu, 15 Apr 2004 07:39:02 GMT</pubDate></item><item><title><![CDATA[Reply to [SOCKETS] Windows bekommt keine definierte Socket notify Meldung on Fri, 16 Apr 2004 02:23:33 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>D@niel $chumann schrieb:</p>
<blockquote>
<p>Man muss die globale Variable nicht umbenennen, man kann in DlgProc auch mit ´</p>
<p>Code:<br />
::hDlg=hDlg;</p>
<p>darauf zugreifen.</p>
</blockquote>
<p>aber nur, wenn das ganze mit einem C++ - Compiler kompiliert wird <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>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/502328</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/502328</guid><dc:creator><![CDATA[Probe-Nutzer]]></dc:creator><pubDate>Fri, 16 Apr 2004 02:23:33 GMT</pubDate></item></channel></rss>