Muhi89
-
Hallo!
Da mein Vorthread aufgrund von Unstimmigkeiten eher in die Hose ging möchte ich es hier nocheinmal versuchen indem ich mein Problem stark reduziere, und so präzise wie möglich schildere.
Mein Problem ist fast gelöst.
Lediglich eine Warnmeldung (vermutlich geht das was ich vorhabe auch nicht)
Zuerst der Source:
#pragma comment( lib, "ws2_32.lib" ) #include <winsock2.h> #include <winsock.h> #include <stdio.h> #include <time.h> #include <windows.h> #include <stdio.h> DWORD WINAPI Connection (void); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hInstance_2, LPSTR CmdLine, int Show ) { DWORD id=1; HANDLE handle = CreateThread(0, 0, &Connection,0, 0, &id); int x=5; while(1) x=x; return 0; } DWORD WINAPI Connection(void) { SOCKET ProtoClient; SOCKADDR_IN ProtoAddress; ProtoClient = socket(AF_INET,SOCK_STREAM,0); memset(&ProtoAddress,0,sizeof(SOCKADDR_IN)); ProtoAddress.sin_family = AF_INET; ProtoAddress.sin_port = htons(80); ProtoAddress.sin_addr.s_addr = inet_addr("209.85.135.147"); connect(ProtoClient, (SOCKADDR*)&ProtoAddress, sizeof(SOCKADDR)); return 0; }Einziges Problem:
"(27): warning #2168: Operands of = have incompatible types 'unsigned long int __stdcall function(void *)' and 'unsigned long int __stdcall function(void)'.
" das ist an der Stelle wo ich den Thread erstelle.Mfg
-
CreateThread will ein unsigned long int __stdcall function(void) nicht ein unsigned long int __stdcall function(void) also mach aus dem
DWORD WINAPI Connection(void)
and
DWORD WINAPI Connection(void)
-
Eine "ThreadProc" ist so deklariert :
DWORD WINAPI ThreadFunc( LPVOID );D.h. Deiner "Connection" fehlt noch ein Parameter vom Typ "LPVOID". Sinn und Zweck dieser Deklaration ist, dass man dem Thread z.B. noch ein Zeiger auf ein Datenfeld übergeben kann.
-
wobei bemerkt sei, dass LPVOID und void* genau das selbe ist.
-
Hallo,
danke für eure hilfreichen Antworten.Hab das mal so umgesetzt (hoffe richtig), das mit der Übergabe weiss ich noch immer nicht, wie ichs machen soll.
#pragma comment( lib, "ws2_32.lib" ) #include <winsock2.h> #include <winsock.h> #include <stdio.h> #include <time.h> #include <windows.h> #include <stdio.h> DWORD WINAPI Connection(void*); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hInstance_2, LPSTR CmdLine, int Show ) { DWORD id=1; HANDLE handle = CreateThread(0, 0,(LPTHREAD_START_ROUTINE)Connection,0, 0, &id); for (; { }; return 0; } DWORD WINAPI Connection(void* kA) { SOCKET ProtoClient; SOCKADDR_IN ProtoAddress; ProtoClient = socket(AF_INET,SOCK_STREAM,0); memset(&ProtoAddress,0,sizeof(SOCKADDR_IN)); ProtoAddress.sin_family = AF_INET; ProtoAddress.sin_port = (80); ProtoAddress.sin_addr.s_addr = inet_addr("209.85.135.147"); connect(ProtoClient, (SOCKADDR*)&ProtoAddress, sizeof(SOCKADDR)); return 0; } mfg
-
Hi,
hab nun auch den Datenparameter ausgefüllt.
Leider gibt mein Compiler an, dass kA nicht referenziert ist.
Aba um es so zu übergeben müsst ich die Funktion ja extra starten oder?
Mfg
Hier der Source:
#pragma comment( lib, "ws2_32.lib" ) #include <winsock2.h> #include <winsock.h> #include <stdio.h> #include <time.h> #include <windows.h> #include <stdio.h> DWORD WINAPI Connection(void*); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hInstance_2, LPSTR CmdLine, int Show ) { struct one { SOCKET Client; SOCKADDR_IN Address; }Verbindungs; SOCKET ProtoClient; SOCKADDR_IN ProtoAddress; ProtoClient = socket(AF_INET,SOCK_STREAM,0); memset(&ProtoAddress,0,sizeof(SOCKADDR_IN)); ProtoAddress.sin_family = AF_INET; ProtoAddress.sin_port = (80); ProtoAddress.sin_addr.s_addr = inet_addr("209.85.135.147"); Verbindungs.Client=ProtoClient; Verbindungs.Address=ProtoAddress; DWORD id=1; HANDLE handle = CreateThread(0, 0,(LPTHREAD_START_ROUTINE)Connection,&Verbindungs, 0, &id); for (;;) { }; return 0; } DWORD WINAPI Connection(void* kA) { //connect(ProtoClient, (SOCKADDR*)&ProtoAddress, sizeof(SOCKADDR)); return 0; }
-
Wenn du den Parameter nicht brauchst, dann benenne ihn nicht, dann sudert der Compiler auch nicht.
DWORD WINAPI Connection(void* /*unused*/) { //... return 42; }Das /*unused*/ kannst du natürlich auch ganz weglassen, ist ja bloss ein Kommentar.
BTW: tu dir selbst einen Gefallen und verwende _beginthreadex statt CreateThread

-
Geht leider nicht, ich bin schon so wütend hab mich stundenlang allein damit gespielt ich pfeiff jetzt einfach drauf weil ich sonst nen Wutanfall bekomm.
Trotzdem danke an alle dir mir geholfen haben.
-
OMG
bin ich manchmal ein Hirsel........
Ich habe den Fehler gefunden, sry wenn ich genervt habe.
Is mir zwar sehr peinlich dass zu posten
, aber ich habe vergessen WSA-Startup zu starten 