Sockets in Dll
-
I am developing an SNMP Agent. I want to use sockets to send/recieve data, for which I need the services of a socket. The code works fine, ie compiles correclty. #include "Connector.h" // The file that defines of the CAsyncSocket derived class Connector Connector Cn; // Entry Point for the DLL BOOL APIENTRY DllMain(...) .. { WSADATA wsaData; long Events = FD_READ | FD_WRITE | FD_CONNECT | FD_CLOSE | FD_ACCEPT; WSAStartup(MAKEWORD(1,1),&wsaData); AfxSocketInit(); switch(ul_reason_for_call) { case DLL_PROCESS_ATTACH: /* The problem lies here. If I don't use this line then the Agent will send traps correctly. But when I create this socket nothing happens. The Agent does not send traps. It kind of just stops working. Cn.Create(128,SOCK_DGRAM,Events,"127.0.0.1"); break; ... } I dont seem to know what is the problem. Please Reply as soon as possible as I am working on a project. Thanks
-
I am developing an SNMP Agent. I want to use sockets to send/recieve data, for which I need the services of a socket. The code works fine, ie compiles correclty. #include "Connector.h" // The file that defines of the CAsyncSocket derived class Connector Connector Cn; // Entry Point for the DLL BOOL APIENTRY DllMain(...) .. { WSADATA wsaData; long Events = FD_READ | FD_WRITE | FD_CONNECT | FD_CLOSE | FD_ACCEPT; WSAStartup(MAKEWORD(1,1),&wsaData); AfxSocketInit(); switch(ul_reason_for_call) { case DLL_PROCESS_ATTACH: /* The problem lies here. If I don't use this line then the Agent will send traps correctly. But when I create this socket nothing happens. The Agent does not send traps. It kind of just stops working. Cn.Create(128,SOCK_DGRAM,Events,"127.0.0.1"); break; ... } I dont seem to know what is the problem. Please Reply as soon as possible as I am working on a project. Thanks
-
Just a guess, could it happen beacuse you are calling WSAStartup() and AfxSocketInit() for every call of DllMain? You might considder moving those function calls into DLL_PROCESS_ATTACH
It is not working. I've probably tried all the combinations. Now, since it is an extension Dll, I am calling AfxInitExtensionModule and AfxTermExtensionModule from DLL_PROCESS_ATTACH and DLL_PROCESS_DETACH respectively. But still the problem persists. ie the dll does not respond when I try to create the socket. Plz check it out, if you could. Thanks