Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CSocket in a console application

44 views
Skip to first unread message

Martin Otten

unread,
Nov 12, 1999, 3:00:00 AM11/12/99
to
hello,

i want to use the MFC CSocket class in a console application.
for learning i used CSocket in a dialog based GUI program.
everything workd fine.
now i ported the code to my console application.
first i call AFXSocketInit(), then i call the socket create
function. my program produces a assert error.
i think MFC is trying to open a window.
i debugged a bit around and found some lines like these:

1. CAsyncSocket::AttachHandle(m_hSocket, this, FALSE);
2. CSocketWnd* pWnd = new CSocketWnd;
3. if (!pWnd->CreateEx(0, AfxRegisterWndClass(0),_T("Socket Notification
Sink"),WS_OVERLAPPED, 0, 0, 0, 0, NULL, NULL))

BOOMM.
in the last line i got the assertion failure.
i think MFC is using windows messages for the Socket syncronisation.
(OnAccept,OnClose and so on)
my program is a NT service and i can't open windows.
do you know how i can use the esay handling of the CSocket class in a
console app ??
or can i use other classes to make my socket life easier ??

Regards (and sorry for my english)
Martin Otten

David Ferguson

unread,
Nov 12, 1999, 3:00:00 AM11/12/99
to
Did you initialize MFC, like this?

if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
cerr << "MFC failed to initialize!" << endl;
return 1;
}

Martin Otten wrote in message <382C4453...@do.isst.fhg.de>...

Martin Otten

unread,
Nov 13, 1999, 3:00:00 AM11/13/99
to

David Ferguson <DavidF...@NOcsiSPAM.com> schrieb in im Newsbeitrag:
e9acmQTL$GA.55@cppssbbsa05...

> Did you initialize MFC, like this?
>
> if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
> {
> cerr << "MFC failed to initialize!" << endl;
> return 1;
> }
>

wow, you are right. That works fine.
Thank you a lot.

Best regards
Martin Otten

0 new messages