-
December 6th, 2005, 02:34 PM
#1
Junior Member
Windows GUI + winsock
Hello everyone!
I've been working on a small project recently,which aimed to work under Windows.The whole idea is to make a programme that alert you when there's a new email in your mail box.
This would be a really easy task if i colud write it as a console app,but i can't...
I want the programme to work as a hidden process so i have to use Windows app.
So the problem is how to handle sockets in windows GUI.I.ve tried:
...
if(SOCKET_ERROR==WSAAsyncSelect(sock,hwnd,WM_SOCKET_NOTIFY,FD_CONNECT|FD_READ|FD_WRITE)){
MessageBox(hwnd,"WSAAsyncSelect!","error",MB_OK);
closesocket(sock);
WSACleanup();
return TRUE;
}
...
case WM_SOCKET_NOTIFY:
Event=WSAGETSELECTEVENT(lParam);
Error=WSAGETSELECTERROR(lParam);
switch(Event){
case FD_CONNECT:
if(Error){
MessageBox(hwnd,"connect!","error",MB_OK);
return TRUE;
}
return 0;
case FD_READ:
Log("recv...");
recv(sock,buff,sizeof(buff)/sizeof(buff[0]),0);
Log(buff);
rmsg++;
return 0;
case FD_WRITE:
Log("send...");
send(sock,DoWyslania[smsg],20,0);
Log(DoWyslania[smsg]);
smsg++;
return 0;
case FD_CLOSE:
Log("!@#@!...");
PostQuitMessage(0);
return 0;
}
return 0;
case WM_DESTROY:
Log("===========end===============");
KillTimer(hwnd,ID_TIMER);
PostQuitMessage(0);
WSACleanup();
fclose(log);
return 0;
but it doesn't work properly...it send data when i want to receive it and stops after receiving one message.
i want to :
-connect to a server
-receive it's prompt
-send "USER xxx"
-recv prompt
-send "Pass xxx"
-recv prompt
-send "STAT"
-recv info about mailbox
how to do it?
-
December 7th, 2005, 09:52 AM
#2
Oliver's Law:
Experience is something you don't get until just after you need it.
-
December 7th, 2005, 10:45 AM
#3
Junior Member
that's not what i wanted...
I told u i need some advices on how to use winsock WITH GUI. You gave me a tutorial about using sockets with console app.
Waiting for more advices
-
December 7th, 2005, 10:55 AM
#4
I hate to break this to you but neither the GUI nor the console has anything to do with the way winsock works.... It works the same for both.
Oliver's Law:
Experience is something you don't get until just after you need it.
-
December 7th, 2005, 11:12 AM
#5
Junior Member
This is not true...
When you write a console app you don't have to worry about blocking functions such as recv or connect. When you use windows GUI you can't block the program,and that's why u have to use :
switch(msg){
case ...
case...
case...
}
Windows GUI programs work in a different way simply...
-
December 7th, 2005, 11:27 AM
#6
The WSAEventSelect and WSAEnumNetworkEvents functions are provided to accommodate applications such as daemons and services that have no user interface (and hence do not use Windows handles). The WSAEventSelect function behaves exactly like the WSAAsyncSelect function. However, instead of causing a Windows message to be sent on the occurrence of an FD_XXX network event (for example, FD_READ and FD_WRITE), an application-designated event object is set.
Source: http://msdn.microsoft.com/library/en..._objects_2.asp
No GUI involved here... It's just an eventloop.. Works the same for a GUI or console app.. The only difference is that a GUI app will also send GUI events..
Oliver's Law:
Experience is something you don't get until just after you need it.
-
December 7th, 2005, 11:41 AM
#7
Junior Member
Ok.so probably you're right.Thx for help
C u
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|