<?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[WinSock Problem]]></title><description><![CDATA[<p>Schreibe grad ne kleine WinSock Anwendung und habe folgendes Problem, ich deaktiviere die DEFAULTLIBRARIES und lade die WinSock Funktionen zur Laufzeit. Ich zeige einfach erstmal den Quelltext:</p>
<pre><code class="language-cpp">#include &lt;winsock2.h&gt;
#include &lt;windows.h&gt;

typedef int	(*PFNWSASTARTUP)(WORD, LPWSADATA);
typedef SOCKET  (*PFNSOCKET)(int, int, int);
typedef int	(*PFNCLOSESOCKET)(SOCKET);
typedef int	(*PFNBIND)(SOCKET, const SOCKADDR*, int);
typedef int     (*PFNLISTEN)(SOCKET, int);
typedef SOCKET  (*PFNACCEPT)(SOCKET, SOCKADDR*, int*);
typedef int	(*PFNSEND)(SOCKET, const char*, int, int);
typedef int	(*PFNRECV)(SOCKET, char*, int, int);
typedef u_short (*PFNHTONS)(u_short);
typedef u_long  (*PFNHTONL)(u_long);
typedef int	(*PFNWSAGETLASTERROR)(void);

static PFNWSASTARTUP      pfnWSAStartup   = 0;
static PFNSOCKET          pfnSocket       = 0;
static PFNCLOSESOCKET     pfnCloseSocket  = 0;
static PFNBIND		  pfnBind	  = 0;
static PFNLISTEN	  pfnListen	  = 0;
static PFNACCEPT	  pfnAccept	  = 0;
static PFNSEND		  pfnSend         = 0;
static PFNRECV		  pfnRecv         = 0;
static PFNHTONS	          pfnHtons	  = 0;
static PFNHTONL		  pfnHtonl        = 0;
static PFNWSAGETLASTERROR pfnGetLastError = 0;

int __cdecl WinMainCRTStartup() {

	HMODULE hWinSock = LoadLibrary(L&quot;Ws2_32.dll&quot;);
	if(!hWinSock) return 1;

	pfnWSAStartup   =
reinterpret_cast&lt;PFNWSASTARTUP&gt;(GetProcAddress(hWinSock,&quot;WSAStartup&quot;));
	pfnSocket       = reinterpret_cast&lt;PFNSOCKET&gt;(GetProcAddress(hWinSock, &quot;socket&quot;));
	pfnCloseSocket  = reinterpret_cast&lt;PFNCLOSESOCKET&gt;(GetProcAddress(hWinSock, &quot;closesocket&quot;));
	pfnBind	        = reinterpret_cast&lt;PFNBIND&gt;(GetProcAddress(hWinSock, &quot;bind&quot;));
	pfnListen	    = reinterpret_cast&lt;PFNLISTEN&gt;(GetProcAddress(hWinSock, &quot;listen&quot;));
	pfnAccept       = reinterpret_cast&lt;PFNACCEPT&gt;(GetProcAddress(hWinSock, &quot;accept&quot;));
	pfnSend		    = reinterpret_cast&lt;PFNSEND&gt;(GetProcAddress(hWinSock, &quot;send&quot;));
	pfnRecv		    = reinterpret_cast&lt;PFNRECV&gt;(GetProcAddress(hWinSock, &quot;recv&quot;));
	pfnHtons	    = reinterpret_cast&lt;PFNHTONS&gt;(GetProcAddress(hWinSock, &quot;htons&quot;));
	pfnHtonl	    = reinterpret_cast&lt;PFNHTONL&gt;(GetProcAddress(hWinSock, &quot;htonl&quot;));
	pfnGetLastError = reinterpret_cast&lt;PFNWSAGETLASTERROR&gt;(GetProcAddress(hWinSock, &quot;WSAGetLastError&quot;));

	WSAData sData;
	if(pfnWSAStartup(MAKEWORD(2, 2), &amp;sData)) return 1;

	SOCKET iListenSocket = pfnSocket(AF_INET,
					 SOCK_STREAM,
					 IPPROTO_TCP);

	if(iListenSocket == INVALID_SOCKET) return 1;

	SOCKADDR_IN sSockAddr;
	sSockAddr.sin_addr.s_addr = INADDR_ANY;
	sSockAddr.sin_family	  = AF_INET;
	sSockAddr.sin_port	  = pfnHtons(12532);

	if(pfnBind(iListenSocket,
		   reinterpret_cast&lt;SOCKADDR*&gt;(&amp;sSockAddr),
		   sizeof(sSockAddr)) == SOCKET_ERROR) return 1;

	int iLength = sizeof(sSockAddr);

	MSG msg;
	while(GetMessage(&amp;msg, 0, 0, 0)) {

		if(pfnListen(iListenSocket, 0) == SOCKET_ERROR) return 1;

		SOCKET iAcceptSocket = pfnAccept(iListenSocket,
			                   nterpret_cast&lt;SOCKADDR*&gt;(&amp;sSockAddr),
						 &amp;iLength);

		if(iAcceptSocket == INVALID_SOCKET) return 1;

		pfnCloseSocket(iAcceptSocket);

		TranslateMessage(&amp;msg);
		DispatchMessage(&amp;msg);
	}

	pfnCloseSocket(iListenSocket);

	FreeLibrary(hWinSock);

	return 0;
}
</code></pre>
<p>Alles klappt wunderbar nur der bind Funktionsaufruf schlägt fehl mit dem Errorcode WSAENOTSOCK... Irgendjemand eine Idee? Wenn ich die Portangabe weglasse klappt der bind Aufruf. Hab absolut keine Idee an was das liegen könnte.<br />
Tut mir leid wegen der grottigen Formatierung, kriegs einfach net besser hin.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/187227/winsock-problem</link><generator>RSS for Node</generator><lastBuildDate>Sat, 04 Jul 2026 13:35:44 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/187227.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 17 Jul 2007 11:22:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to WinSock Problem on Tue, 17 Jul 2007 11:22:21 GMT]]></title><description><![CDATA[<p>Schreibe grad ne kleine WinSock Anwendung und habe folgendes Problem, ich deaktiviere die DEFAULTLIBRARIES und lade die WinSock Funktionen zur Laufzeit. Ich zeige einfach erstmal den Quelltext:</p>
<pre><code class="language-cpp">#include &lt;winsock2.h&gt;
#include &lt;windows.h&gt;

typedef int	(*PFNWSASTARTUP)(WORD, LPWSADATA);
typedef SOCKET  (*PFNSOCKET)(int, int, int);
typedef int	(*PFNCLOSESOCKET)(SOCKET);
typedef int	(*PFNBIND)(SOCKET, const SOCKADDR*, int);
typedef int     (*PFNLISTEN)(SOCKET, int);
typedef SOCKET  (*PFNACCEPT)(SOCKET, SOCKADDR*, int*);
typedef int	(*PFNSEND)(SOCKET, const char*, int, int);
typedef int	(*PFNRECV)(SOCKET, char*, int, int);
typedef u_short (*PFNHTONS)(u_short);
typedef u_long  (*PFNHTONL)(u_long);
typedef int	(*PFNWSAGETLASTERROR)(void);

static PFNWSASTARTUP      pfnWSAStartup   = 0;
static PFNSOCKET          pfnSocket       = 0;
static PFNCLOSESOCKET     pfnCloseSocket  = 0;
static PFNBIND		  pfnBind	  = 0;
static PFNLISTEN	  pfnListen	  = 0;
static PFNACCEPT	  pfnAccept	  = 0;
static PFNSEND		  pfnSend         = 0;
static PFNRECV		  pfnRecv         = 0;
static PFNHTONS	          pfnHtons	  = 0;
static PFNHTONL		  pfnHtonl        = 0;
static PFNWSAGETLASTERROR pfnGetLastError = 0;

int __cdecl WinMainCRTStartup() {

	HMODULE hWinSock = LoadLibrary(L&quot;Ws2_32.dll&quot;);
	if(!hWinSock) return 1;

	pfnWSAStartup   =
reinterpret_cast&lt;PFNWSASTARTUP&gt;(GetProcAddress(hWinSock,&quot;WSAStartup&quot;));
	pfnSocket       = reinterpret_cast&lt;PFNSOCKET&gt;(GetProcAddress(hWinSock, &quot;socket&quot;));
	pfnCloseSocket  = reinterpret_cast&lt;PFNCLOSESOCKET&gt;(GetProcAddress(hWinSock, &quot;closesocket&quot;));
	pfnBind	        = reinterpret_cast&lt;PFNBIND&gt;(GetProcAddress(hWinSock, &quot;bind&quot;));
	pfnListen	    = reinterpret_cast&lt;PFNLISTEN&gt;(GetProcAddress(hWinSock, &quot;listen&quot;));
	pfnAccept       = reinterpret_cast&lt;PFNACCEPT&gt;(GetProcAddress(hWinSock, &quot;accept&quot;));
	pfnSend		    = reinterpret_cast&lt;PFNSEND&gt;(GetProcAddress(hWinSock, &quot;send&quot;));
	pfnRecv		    = reinterpret_cast&lt;PFNRECV&gt;(GetProcAddress(hWinSock, &quot;recv&quot;));
	pfnHtons	    = reinterpret_cast&lt;PFNHTONS&gt;(GetProcAddress(hWinSock, &quot;htons&quot;));
	pfnHtonl	    = reinterpret_cast&lt;PFNHTONL&gt;(GetProcAddress(hWinSock, &quot;htonl&quot;));
	pfnGetLastError = reinterpret_cast&lt;PFNWSAGETLASTERROR&gt;(GetProcAddress(hWinSock, &quot;WSAGetLastError&quot;));

	WSAData sData;
	if(pfnWSAStartup(MAKEWORD(2, 2), &amp;sData)) return 1;

	SOCKET iListenSocket = pfnSocket(AF_INET,
					 SOCK_STREAM,
					 IPPROTO_TCP);

	if(iListenSocket == INVALID_SOCKET) return 1;

	SOCKADDR_IN sSockAddr;
	sSockAddr.sin_addr.s_addr = INADDR_ANY;
	sSockAddr.sin_family	  = AF_INET;
	sSockAddr.sin_port	  = pfnHtons(12532);

	if(pfnBind(iListenSocket,
		   reinterpret_cast&lt;SOCKADDR*&gt;(&amp;sSockAddr),
		   sizeof(sSockAddr)) == SOCKET_ERROR) return 1;

	int iLength = sizeof(sSockAddr);

	MSG msg;
	while(GetMessage(&amp;msg, 0, 0, 0)) {

		if(pfnListen(iListenSocket, 0) == SOCKET_ERROR) return 1;

		SOCKET iAcceptSocket = pfnAccept(iListenSocket,
			                   nterpret_cast&lt;SOCKADDR*&gt;(&amp;sSockAddr),
						 &amp;iLength);

		if(iAcceptSocket == INVALID_SOCKET) return 1;

		pfnCloseSocket(iAcceptSocket);

		TranslateMessage(&amp;msg);
		DispatchMessage(&amp;msg);
	}

	pfnCloseSocket(iListenSocket);

	FreeLibrary(hWinSock);

	return 0;
}
</code></pre>
<p>Alles klappt wunderbar nur der bind Funktionsaufruf schlägt fehl mit dem Errorcode WSAENOTSOCK... Irgendjemand eine Idee? Wenn ich die Portangabe weglasse klappt der bind Aufruf. Hab absolut keine Idee an was das liegen könnte.<br />
Tut mir leid wegen der grottigen Formatierung, kriegs einfach net besser hin.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1327151</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1327151</guid><dc:creator><![CDATA[0xDEADBEEF]]></dc:creator><pubDate>Tue, 17 Jul 2007 11:22:21 GMT</pubDate></item><item><title><![CDATA[Reply to WinSock Problem on Sun, 22 Jul 2007 17:08:32 GMT]]></title><description><![CDATA[<p>Hab nun herausgefunden wieso es nicht gefunzt hat, falls es interessiert...</p>
<p>Es lag an der Aufrufkonvention der Funktionen. Ein einfaches _stdcall bei den Funktionspointern und es funktioniert so wie es soll.</p>
<p>kleines bsp.</p>
<p>typedef int (*PFNBIND)(SOCKET, const sockaddr*, int);</p>
<p>-&gt;</p>
<p>typedef int (_stdcall *PFNBIND)(SOCKET, const sockaddr*, int);</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1330317</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1330317</guid><dc:creator><![CDATA[0xDEADBEEF]]></dc:creator><pubDate>Sun, 22 Jul 2007 17:08:32 GMT</pubDate></item><item><title><![CDATA[Reply to WinSock Problem on Sun, 22 Jul 2007 20:01:01 GMT]]></title><description><![CDATA[<p>Mir ist etwas unklar warum die winsock funktionen überhaupt manuell lädst?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1330391</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1330391</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Sun, 22 Jul 2007 20:01:01 GMT</pubDate></item><item><title><![CDATA[Reply to WinSock Problem on Sun, 22 Jul 2007 20:02:56 GMT]]></title><description><![CDATA[<p>Ich schätze er halt sich an die Regel: Warum einfach, wenns auch kompliziert geht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1330393</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1330393</guid><dc:creator><![CDATA[asdasdasdasdasd]]></dc:creator><pubDate>Sun, 22 Jul 2007 20:02:56 GMT</pubDate></item><item><title><![CDATA[Reply to WinSock Problem on Sun, 22 Jul 2007 21:59:35 GMT]]></title><description><![CDATA[<p>Ich habe zur Zeit die Zwangsneurose alle Anwendungen so klein wie möglich zu schreiben <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> . Klein ist natürlich bezogen auf die reine Anwendungsgröße, und wenn ich so eine Stanadardexe normal Multithreaded(nicht Multithreaded-DLL) erstelle wird die exe schon ohne das ich etwas in das Programm packe 40kb GROß(im Release-Build selbstverständlich). Das ärgert mich einfach... also arbeite ich micht RTDL und spare mir so ein paar kb. Außerdem kann ich falls die erforderliche DLL nicht vorhanden ist alternative Problemlösungen in betracht ziehen, anstatt dass das gesamte Programm den Dienst verweigert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1330437</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1330437</guid><dc:creator><![CDATA[0xDEADBEEF]]></dc:creator><pubDate>Sun, 22 Jul 2007 21:59:35 GMT</pubDate></item></channel></rss>