Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Unloading Winsock (MSWSOCK.dll) after use

skeg_13skeg_13 Member Posts: 12
I have written a dll (mROC.dll) in C++ Builder 2007 R2. The dll implements a multithreaded TCP/IP Client with 3 connections. For each connection I initialise the winsock system as follows:

#include "winsock2.h"

In the constructor:
VersionRequested = MAKEWORD(2, 2);
WSAStartup( VersionRequested, &wsaData );

When I am finished with each connection, I do the following:

[code]
shutdown( mySocket, 2);
WSACleanup();
[/code]

So for each call to WSAStartup there is a corresponding call to WSACleanup.

The issue I have, it that when I include this dll in my Test console application or the intended target, a .NET Forms application, I run into the issue where as far as I can tell, my dll is not releasing all its resources, holding up the termination of the host application.

When my dll (mROC.dll) is called apon, the following resources are loaded:

[code]
Module Load: mROC.dll. No Debug Info. Base Address: $00E70000. Process Tester.exe (6120)
Module Load: OLEPRO32.DLL. No Debug Info. Base Address: $5EDD0000. Process Tester.exe (6120)
Thread Start: Thread ID: 6276. Process Tester.exe (6120)
Thread Start: Thread ID: 472. Process Tester.exe (6120)
Thread Start: Thread ID: 4040. Process Tester.exe (6120)
Module Load: MSWSOCK.dll. No Debug Info. Base Address: $71A50000. Process Tester.exe (6120)
Module Load: HNetCfg.dll. No Debug Info. Base Address: $662B0000. Process Tester.exe (6120)
Module Load: WSHTCPIP.dll. No Debug Info. Base Address: $71A90000. Process Tester.exe (6120)[/code]

NOTE: The three threads created represent my TCP/IP connections..

Then when my dll (mROC.dll) is finished with, one of the resources is NOT unloaded (MSWSOCK.dll):

[code]
Thread Exit: Thread ID: 6276. Process Tester.exe (6120)
Thread Exit: Thread ID: 472. Process Tester.exe (6120)
Thread Exit: Thread ID: 4040. Process Tester.exe (6120)
Module Unload: WSHTCPIP.dll. Process Tester.exe (6120)
Module Unload: HNetCfg.dll. Process Tester.exe (6120)
Module Unload: mROC.dll. Process Tester.exe (6120)
Module Unload: OLEPRO32.DLL. Process Tester.exe (6120)
[/code]

Is this where my dll is not releasing all its resources and causing my applications to not exit correctly?? If so how do I correct this?

Below is the complete Output from C++ Builder as the Test Console application initialises an instance on my dll, requests the connections, disconnects, and attempts to exit:

[code]Module Load: Tester.exe. Has Debug Info. Base Address: $00400000. Process Tester.exe (6120)
Module Load: ntdll.dll. No Debug Info. Base Address: $7C900000. Process Tester.exe (6120)
Module Load: KERNEL32.dll. No Debug Info. Base Address: $7C800000. Process Tester.exe (6120)
Module Load: vcl100.bpl. No Debug Info. Base Address: $200E0000. Process Tester.exe (6120)
Module Load: rtl100.bpl. No Debug Info. Base Address: $20000000. Process Tester.exe (6120)
Module Load: OLEAUT32.dll. No Debug Info. Base Address: $77120000. Process Tester.exe (6120)
Module Load: ADVAPI32.dll. No Debug Info. Base Address: $77DD0000. Process Tester.exe (6120)
Module Load: RPCRT4.dll. No Debug Info. Base Address: $77E70000. Process Tester.exe (6120)
Module Load: Secur32.dll. No Debug Info. Base Address: $77FE0000. Process Tester.exe (6120)
Module Load: GDI32.dll. No Debug Info. Base Address: $77F10000. Process Tester.exe (6120)
Module Load: USER32.dll. No Debug Info. Base Address: $7E410000. Process Tester.exe (6120)
Module Load: msvcrt.dll. No Debug Info. Base Address: $77C10000. Process Tester.exe (6120)
Module Load: ole32.dll. No Debug Info. Base Address: $774E0000. Process Tester.exe (6120)
Module Load: VERSION.dll. No Debug Info. Base Address: $77C00000. Process Tester.exe (6120)
Module Load: MPR.dll. No Debug Info. Base Address: $71B20000. Process Tester.exe (6120)
Module Load: IMAGEHLP.dll. No Debug Info. Base Address: $76C90000. Process Tester.exe (6120)
Module Load: WSOCK32.dll. No Debug Info. Base Address: $71AD0000. Process Tester.exe (6120)
Module Load: WS2_32.dll. No Debug Info. Base Address: $71AB0000. Process Tester.exe (6120)
Module Load: WS2HELP.dll. No Debug Info. Base Address: $71AA0000. Process Tester.exe (6120)
Module Load: OLEACC.dll. No Debug Info. Base Address: $74C80000. Process Tester.exe (6120)
Module Load: MSVCP60.dll. No Debug Info. Base Address: $76080000. Process Tester.exe (6120)
Module Load: COMCTL32.dll. No Debug Info. Base Address: $5D090000. Process Tester.exe (6120)
Module Load: SHELL32.dll. No Debug Info. Base Address: $7C9C0000. Process Tester.exe (6120)
Module Load: SHLWAPI.dll. No Debug Info. Base Address: $77F60000. Process Tester.exe (6120)
Module Load: WINSPOOL.DRV. No Debug Info. Base Address: $73000000. Process Tester.exe (6120)
Module Load: comdlg32.dll. No Debug Info. Base Address: $763B0000. Process Tester.exe (6120)
Module Load: oledlg.dll. No Debug Info. Base Address: $7DF70000. Process Tester.exe (6120)
Module Load: borlndmm.dll. No Debug Info. Base Address: $21150000. Process Tester.exe (6120)
Module Load: cc3280mt.dll. No Debug Info. Base Address: $32800000. Process Tester.exe (6120)
Module Load: IMM32.dll. No Debug Info. Base Address: $76390000. Process Tester.exe (6120)
Module Load: COMCTL32.dll. No Debug Info. Base Address: $773D0000. Process Tester.exe (6120)
Module Load: UxTheme.dll. No Debug Info. Base Address: $5AD70000. Process Tester.exe (6120)
Module Load: MSCTF.dll. No Debug Info. Base Address: $74720000. Process Tester.exe (6120)
Module Load: nView.dll. No Debug Info. Base Address: $10000000. Process Tester.exe (6120)
Module Load: PSAPI.DLL. No Debug Info. Base Address: $76BF0000. Process Tester.exe (6120)
Module Load: WINMM.dll. No Debug Info. Base Address: $76B40000. Process Tester.exe (6120)
Module Load: NTMARTA.dll. No Debug Info. Base Address: $77690000. Process Tester.exe (6120)
Module Load: SAMLIB.dll. No Debug Info. Base Address: $71BF0000. Process Tester.exe (6120)
Module Load: WLDAP32.dll. No Debug Info. Base Address: $76F60000. Process Tester.exe (6120)
Module Load: msctfime.ime. No Debug Info. Base Address: $755C0000. Process Tester.exe (6120)
Module Load: CLBCatQ.DLL. No Debug Info. Base Address: $76FD0000. Process Tester.exe (6120)
Module Load: COMRes.dll. No Debug Info. Base Address: $77050000. Process Tester.exe (6120)
Module Load: mROC.dll. No Debug Info. Base Address: $00E70000. Process Tester.exe (6120)
Module Load: OLEPRO32.DLL. No Debug Info. Base Address: $5EDD0000. Process Tester.exe (6120)
Thread Start: Thread ID: 6276. Process Tester.exe (6120)
Thread Start: Thread ID: 472. Process Tester.exe (6120)
Thread Start: Thread ID: 4040. Process Tester.exe (6120)
Module Load: MSWSOCK.dll. No Debug Info. Base Address: $71A50000. Process Tester.exe (6120)
Module Load: HNetCfg.dll. No Debug Info. Base Address: $662B0000. Process Tester.exe (6120)
Module Load: WSHTCPIP.dll. No Debug Info. Base Address: $71A90000. Process Tester.exe (6120)
Thread Exit: Thread ID: 6276. Process Tester.exe (6120)
Thread Exit: Thread ID: 472. Process Tester.exe (6120)
Thread Exit: Thread ID: 4040. Process Tester.exe (6120)
Module Unload: WSHTCPIP.dll. Process Tester.exe (6120)
Module Unload: HNetCfg.dll. Process Tester.exe (6120)
Module Unload: mROC.dll. Process Tester.exe (6120)[/code]

Sign In or Register to comment.