• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 564
  • Last Modified:

threaded socket in MFC system service

I've got a problem with trying to use a CAsyncSocket in an MFC system service.  The service is coded as an EXE and currently being run in console mode (for debugging).

The problem I am having is that after I do my AfxSocketInit() I instantiate the socket as follows


      CUDPSocket *m_pUDPSocket;
      m_pUDPSocket = new CUDPSocket;            //( this );
      m_pUDPSocket->Create( 2230, SOCK_DGRAM, FD_READ );
when I do the create I get the following assert/message Dialog

Microsoft Visual C++ Debug Libary
Debug Assertion Failed

Program myprogram.exe
File: afxwin1.inl
Line 19

press retry etc....

now, line 19 is the middle line of the following code

LINE 19-> ASSERT(afxCurrentInstanceHandle != NULL);
      return afxCurrentInstanceHandle;

SO.  my question is obvious.  Whats going wrong here, why can't I create my socket?

any help would be appreciated.

  • 2
1 Solution
SD_AdeptAuthor Commented:
Edited text of question.
set some breakpoints and debug your application ...
To use MFC in a Win32 Console application, you must call AfxWinInit to initialize MFC. See

SD_AdeptAuthor Commented:
chensu, excellent, that worked perfectly.  thanks!

[Note to nil_dib for his comment.... geee, ya think?]
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now