[SOCKETS] VC kennt die Funktionen nicht
-
Hi Leute,
ich wollte heute mit der Socket-Programmierung anfangen, mein Server läuft auch schon, nun wollte ich einen GUI-Clienten programmieren. Jetzt steh ich vor einem ziemlich großen Problem:
Der Programmcode
#include <windows.h> #include "resource.h" WSADATA WSAData; WSAStartup(MAKEWORD(2,0),&WSAData); sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); // socket erstellen sockaddr_in sa; sa.sin_family = AF_INET; sa.sin_port = htons(1000); sa.sin_addr.S_un.S_addr = inet_addr("192.168.0.135"); if(connect(sock,(SOCKADDR*)&sa,sizeof(sa))==SOCKET_ERROR){ MessageBox(0,"Bei connect()","Socket Error",0);} else { WSAAsyncSelect(sock,hwnd,WM_SOCKET_NOTIFY,FD_CONNECT|FD_READ|FD_CLOSE); } #define WM_SOCKET_NOTIFY (WM_USER + 1) WSAAsyncSelect(sock,hwnd,WM_SOCKET_NOTIFY,FD_CONNECT|FD_READ|FD_CLOSE); BOOL CALLBACK DlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static char szAppName[] = "Socket-Client" ; DialogBox(hInstance,"IDD_Start",NULL,DlgProc); MSG msg; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; } BOOL CALLBACK DlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_INITDIALOG: HWND dlgitem; dlgitem = GetDlgItem(hDlg,IDC_IPADRESS); SendMessage(dlgitem,WM_SETTEXT,0,(long)"192.168.0.135"); dlgitem = GetDlgItem(hDlg,IDC_PORT); SendMessage(dlgitem,WM_SETTEXT,0,(long)"10000"); return TRUE; case WM_COMMAND: switch(LOWORD(wParam)) { case CMD_CANCEL: PostQuitMessage(0); break; case CMD_CONNECT: break; } break; case WM_DESTROY : PostQuitMessage (0) ; break; } return FALSE; }Die ws2_32.lib ist natürlich mitgelinkt, trotzdem meldet VC++ 6 Standard
--------------------Configuration: clientGUI - Win32 Debug-------------------- Compiling... haupt.cpp D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(5) : error C2501: 'WSAStartup' : missing storage-class or type specifiers D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(5) : error C2373: 'WSAStartup' : redefinition; different type modifiers d:\programme\microsoft visual studio\vc98\include\winsock.h(781) : see declaration of 'WSAStartup' D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(5) : error C2078: too many initializers D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(5) : error C2440: 'initializing' : cannot convert from 'struct WSAData *' to 'int' This conversion requires a reinterpret_cast, a C-style cast or function-style cast D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(7) : error C2501: 'sock' : missing storage-class or type specifiers D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(10) : error C2143: syntax error : missing ';' before '.' D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(10) : error C2501: 'sa' : missing storage-class or type specifiers D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(10) : error C2371: 'sa' : redefinition; different basic types D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(9) : see declaration of 'sa' D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(10) : error C2143: syntax error : missing ';' before '.' D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(11) : error C2143: syntax error : missing ';' before '.' D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(11) : error C2501: 'sa' : missing storage-class or type specifiers D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(11) : error C2371: 'sa' : redefinition; different basic types D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(9) : see declaration of 'sa' D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(11) : error C2143: syntax error : missing ';' before '.' D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(12) : error C2143: syntax error : missing ';' before '.' D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(12) : error C2501: 'sa' : missing storage-class or type specifiers D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(12) : error C2371: 'sa' : redefinition; different basic types D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(9) : see declaration of 'sa' D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(12) : error C2143: syntax error : missing ';' before '.' D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(14) : error C2143: syntax error : missing ';' before 'if' D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(14) : error C2143: syntax error : missing ';' before '{' D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(14) : error C2447: missing function header (old-style formal list?) D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(17) : error C2143: syntax error : missing ';' before 'else' D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(17) : error C2143: syntax error : missing ';' before '{' D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(17) : error C2447: missing function header (old-style formal list?) D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(22) : error C2065: 'hwnd' : undeclared identifier D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(22) : error C2501: 'WSAAsyncSelect' : missing storage-class or type specifiers D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(22) : error C2373: 'WSAAsyncSelect' : redefinition; different type modifiers d:\programme\microsoft visual studio\vc98\include\winsock.h(824) : see declaration of 'WSAAsyncSelect' D:\Programmierung\Geproggtes\SOCKETS\clientGUI\haupt.cpp(22) : error C2078: too many initializers Error executing cl.exe. clientGUI.exe - 27 error(s), 0 warning(s)Irgendetwas scheint mit den Headern oder Libs nicht zu stimmen, wenn ich die winsock2.h einbinde, kommt immer ein Neudefinitionsfehler, diese ist scheinbar schon in der windows.h integriert.
Hochachtungsvoll Rodney

-
Hallo,
du solltest nicht Quellcode wild in die Landschaft des VC-Editors platzieren
, der ganze Kram, der angemeckert wird, muß natürlich in einer Funktion stehen!! Also ab in WinMain damit (bis auf das #define), und dann sollten einige, wenn nicht alle Fehler verschwinden.MfG
-
Probe-Nutzer schrieb:
Hallo,
du solltest nicht Quellcode wild in die Landschaft des VC-Editors platzieren
, der ganze Kram, der angemeckert wird, muß natürlich in einer Funktion stehen!! Also ab in WinMain damit (bis auf das #define), und dann sollten einige, wenn nicht alle Fehler verschwinden.MfG
asche über mein haupt...

THX