Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why CAsyncSocket doesn't work in Windows Service application?

Status
Not open for further replies.

hankgao0703

Programmer
Jul 18, 2001
27
CA
Hi,
I am developing a Windows service application, in which I use CAysncSocket class as a listenning socket to monitor requests from clients, but when I call CAsynSocket.Create(), the application crashes, Why?
my code is as follows:

....
AfxSocketInit();
....
CAsyncSocket socket;
socket.Create(2047); <===== application crashes here

by the way, I made a small console application to test and same error happens, but in a dialog based appication, it works, so CAysncSocket only can be used in standard windows application, Is that right?
If so, that's too bad, I just wonder if there is any other ways to communicate with clients that can be used in Windows service application?

thanks in advance

Hank Gao
 
Yes I'm pretty sure CAsyncSocket can only be used by a standard Window application because it uses Windows Messages to notify the dialog of network events. Creating a listening socket as you did should work also. You might need to include the WS2_32.LIB files to your project.

You can use the app-wizard to include all Winsock initilizations and .LIB files for you .. just check the use &quot;Windows Sockets&quot; check box.
 
Hi.
I had the same problem with sockets and services. To solve it, I used a trick: when the time comes to use a socket I just run a sepparate application that can use sockets...

Hope to help...
 
Thanks for you guy's reply, (but I don't what to use a sperate application to run socket)

To sirbeatsalot:
I don't quite understand your post, could you please give more details?

Thanks
Hank
 
Thanks, guys,

I tried to use CAsyncSocket in DLL, it still doesn't work, (I mean applicatin crashes when CAsyncSocket::Create is called). but if I don't use SCM(Service Control Manager) to start my service application, instead starts it directly, everything is just fine, Could anybody tell me the reason?


Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top