Solved

CSocket in ISAPI

Posted on 2001-07-09
3
482 Views
Last Modified: 2013-11-20
Hi,
I have tried CSocket function in ISAPI DLL Extension. In the project settings, if I used "Use MFC in

a shared DLL", the program is working fine and giving me a proper output. But, If I try to use "Use

MFC in a static library" it is not giving output.

Any of you can tell me, how to fix this.

Thanks in Advance,
Raja
0
Comment
Question by:kvraja
3 Comments
 
LVL 4

Accepted Solution

by:
aponcealbuerne earned 25 total points
Comment Utility
From MSDN

SYMPTOMS
An MFC application that uses MFC's socket classes (CSocket and CAsyncSocket) and statically links with MFC causes a general protection (GP) fault on exit. The GP fault occurs on the following line in SOCKCORE.CPP:

SOCKCORE.CPP(32):

   if (_afxSockState->lpfnSockCleanup != NULL)


This error occurs if the application contains a call to AfxSocketInit but for some reason terminates without ever actually calling that function. It will also occur if the call to AfxSocketInit fails.


CAUSE
The MFC socket implementation maintains a static pointer to a structure that maintains socket state information. This variable is defined in SOCKCORE.CPP as:


   static AFX_SOCKSTATE* _afxSockState;


_afxSockState is initialized when an application calls AfxSocketInit. However if an application does not call AfxSocketInit or the call to AfxSocketInit fails, the variable is not initialized, and the 'if' statement shown above attempts to remove the reference to a NULL pointer, which causes the GP fault.


RESOLUTION

This problem occurs only if your application statically links with MFC. If your application uses the DLL version of MFC (MFC250(D).DLL), this problem does not occur. To learn how to use the DLL version of MFC, please see MFC TechNote #33. In particular, examine the section titled:


      "Writing An Application that Uses the DLL Version"

NOTE: In order to use the DLL version of MFC with a sockets app, you also need to link with MFCN250(D), which contains the definitions for the CSocket and CAsyncSocket members.


Force the application to call AfxSocketInit. This causes the variable to be properly initialized when socket support is available. However the problem still occurs if AfxSocketInit fails.

If your application links statically to MFC, you can rebuild the static MFC library with a fix to the problem. To fix the problem, change the following code located on line 32 of SOCKCORE.CPP in the MFC\SRC directory:
Change this line:



      if (_afxSockState->lpfnSockCleanup != NULL)

To this line:



      if((_afxSockState!=NULL) && (_afxSockState->lpfnSockCleanup!=NULL))

Once the change has been made, you can rebuild the MFC static library to incorporate the change. For details on how to rebuild the MFC static library, please see the README.TXT file in the MFC\SRC directory and Appendix B of the Class Library User's Guide.

IMPORTANT: Remember that the problem only exists in the static library, so you should not rebuild the MFC DLL (MFC250(D).DLL).
0
 
LVL 49

Assisted Solution

by:DanRollins
DanRollins earned 25 total points
Comment Utility
Search in MSDN for
   Q152054

It will show you how to put debug tracing messages and use messageboxes in your ISAPI DLL.  This will help you track down the error.

-- Dan
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: aponcealbuerne, DanRollins (points to be split)

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 83
Turn a spreadsheet into a vba executable. 2 66
dog bark java program 15 81
Thin secure Windows 10 5 46
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video discusses moving either the default database or any database to a new volume.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now