Search code examples
visual-studiovisual-c++mfcatlmfc-networking

Using MFC in Windows service?


I'm starting to develop a Windows service. I want to use some classes from my own, that has little dependencies to some MFC classes like CString, CSocket, CArchive, CMemFile and CObject. MSDN says you need to be very careful about which pieces of MFC you use in the Windows service, but don't specifies it and don't describes the problems that can occur.

My questions are:

  • what pieces of MFC can be used?
  • what problems can I expect, by using MFC?
  • which parts of Windows service are critical for MFC use?
  • is it advisable to use ATL instead of MFC for Windows service?

Solution

  • I'm not sure what they mean in teh MSDN article. As long as you don't use any of the GUI functionality you'll be fine - but that's a general design issue when developing services.

    That being said, ATL has functionality specifically designed for building services IIRC so you may be better off using that.

    To answer your questions (to the best of my knowledge):

    1) the ones you specify are no problem.

    2) I guess they mean synchronization issues with UI components. As long as you don't use any CWnd-derived classes you'll be fine.

    3) don't understand the question.

    4) See before, plus ATL is more lightweight so you'll have to distribute less, and provides build-in functionality that'll make it less of a pain to develop the service. See e.g. CAtlServiceModuleT. You'll still be able to mostly use your own classes, as CString is shared between MFC and ATL nowadays and ATL has classes for socket programming and memory file mapping itself. It doesn't have an equivalent for CArchive, and I'm not sure what functionality you use in CObject so I can't say whether there's an equivalent in ATL. So to conclude, I'd say 'yes' to this question.