Can We initialize Win sock in DLL_DETACH ? actulay i want to send some data when a process get terminated(DLL_DETACH)
Can We initilize Winsock in DLL_DETACH ? actulay i want to send some data when a process get terminated(DLL_DETACH)
132 views Asked by Saqib Khan At
2
There are 2 answers
0
On
Calling WSAStartup() in DllMain() will result in a deadlock due to the loader lock. WSAStartup() can result in DLLs being loaded.
A better solution would be to install a service that can do the sending for. Talk to the service from DllMain() using your preferred interprocess comms method (shared memory, named pipes, etc).
DLL_DETACH
is actuallyDLL_PROCESS_DETACH
.It is possible (i don't think that's any mechanism to prevent it) but it's not recommended.
WSAStartup
lies inws2_32.dll
. Here's a fragment from DllMain official doc (Remarks section):Also, from WSAStartup official doc (same Remarks section):
As an alternative sending the data (including the overhead of initializing the socket engine, creating the connection, and uninitializing the socket engine) could be achieved at the end of
main
(WinMain
).