Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How do I isolate MFC in a DLL?

How do I isolate MFC in a DLL?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++learning
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tomb 0
    wrote on last edited by
    #1

    Problem: Main app using 3rd party libraries as base for most classes. These 3rd party libs include windows.h. Have DLL with descendant of CDialog in it. I'm told (MSDN) you can use a statically or dynamically linked Win32 DLL using MFC within a non-MFC program (the main program doesn't see the MFC). How? When I include the header for a class in my DLL (which at the moment contains nothing, was planned to contain my CDIalog), the main project won't build because it complains about including stdafx.h (I have afxwin.h included therein). If I try to leave out stdafx.h, of course the DLL itself won't build. So what do I need to do to create a header that can be included in my main project, has the exports that won't drag MFC into the main App, and so that the DLL will still build? Any help appreciated.

    E 1 Reply Last reply
    0
    • T Tomb 0

      Problem: Main app using 3rd party libraries as base for most classes. These 3rd party libs include windows.h. Have DLL with descendant of CDialog in it. I'm told (MSDN) you can use a statically or dynamically linked Win32 DLL using MFC within a non-MFC program (the main program doesn't see the MFC). How? When I include the header for a class in my DLL (which at the moment contains nothing, was planned to contain my CDIalog), the main project won't build because it complains about including stdafx.h (I have afxwin.h included therein). If I try to leave out stdafx.h, of course the DLL itself won't build. So what do I need to do to create a header that can be included in my main project, has the exports that won't drag MFC into the main App, and so that the DLL will still build? Any help appreciated.

      E Offline
      E Offline
      Erik Funkenbusch
      wrote on last edited by
      #2

      You can't export an MFC class from a DLL to a non-MFC application. There are many reasons for this, but suffice it to say that it can't be done. What the MSDN means when it says you can use MFC in a DLL and call it from a non-MFC app, was that you can have a DLL that exports various functions, which can in and of themselves call MFC. You cannot call MFC derived classes directly from your app. So, what you would do is create an export called "ShowMyDlg()" which will create the CDialog, and another function called "GetDataFromMyDialog()" to retive the data from it.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups