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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Debug Assertion in Release wrong version of MFC Shared DLL

Debug Assertion in Release wrong version of MFC Shared DLL

Scheduled Pinned Locked Moved C / C++ / MFC
c++debugginghelpannouncementvisual-studio
8 Posts 3 Posters 3 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.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    HI, I have code that works fine in debug but I have already learned my lesson that it does mean It will work in Release Anyway I got an assertion in wincore.cpp line 656 for having a window handle = NULL After the message box came up pointing me to the location in wincore.cpp where the problem was I tried to attach the VS debugger with my solution. Wasn't much help as the call stack was all windows code One thing I did notice that was odd the DLL was MFC140d.DLL isn't that the debug version of MFC I checked my property pages for release and I had /MD not /MDd shouldn't I have MFC140.DLL ??

    L J 2 Replies Last reply
    0
    • F ForNow

      HI, I have code that works fine in debug but I have already learned my lesson that it does mean It will work in Release Anyway I got an assertion in wincore.cpp line 656 for having a window handle = NULL After the message box came up pointing me to the location in wincore.cpp where the problem was I tried to attach the VS debugger with my solution. Wasn't much help as the call stack was all windows code One thing I did notice that was odd the DLL was MFC140d.DLL isn't that the debug version of MFC I checked my property pages for release and I had /MD not /MDd shouldn't I have MFC140.DLL ??

      L Offline
      L Offline
      leon de boer
      wrote on last edited by
      #2

      Turn your warning level up .. it will give you uninitialized use warnings. The default is W3 go to W4 or WALL you might get a lot of warnings but saves you headaches :-) I usually start out W3 when it's getting close to release I crank the setting up and walk thru each warning. What you are really saying is you have a bad habit of either using uninitialized variables or forgetting to initialize them which will be what your current problem is about. You need to work on getting rid of what is obviously a bad coding habbit. /MD is the correct selection for the VC runtime library release but usually I go for /MT in release the exe gets bigger but no VC runtime install required on the target machine. Now I assume it follows thru to MFC I write so little on the MFC framework I can't say definitively. But yes usually in release /MD or /MT is the setting you would use the difference as stated, and if the blowup in size is worth not having to distribute the run-time library at all. Now when VS debugs in release mode it's a quirky thing, as you stated you wanted no debug compilation but the VS IDE still tries to give you debug info. It seems to sort of guess at the line sometimes you will find it out by a line or 2 especially if it has optimized some of the code away. When running outside the IDE I know it only uses the correct DLL because the times I have used DLL distribution I only copy the one DLL for install.

      In vino veritas

      F 1 Reply Last reply
      0
      • L leon de boer

        Turn your warning level up .. it will give you uninitialized use warnings. The default is W3 go to W4 or WALL you might get a lot of warnings but saves you headaches :-) I usually start out W3 when it's getting close to release I crank the setting up and walk thru each warning. What you are really saying is you have a bad habit of either using uninitialized variables or forgetting to initialize them which will be what your current problem is about. You need to work on getting rid of what is obviously a bad coding habbit. /MD is the correct selection for the VC runtime library release but usually I go for /MT in release the exe gets bigger but no VC runtime install required on the target machine. Now I assume it follows thru to MFC I write so little on the MFC framework I can't say definitively. But yes usually in release /MD or /MT is the setting you would use the difference as stated, and if the blowup in size is worth not having to distribute the run-time library at all. Now when VS debugs in release mode it's a quirky thing, as you stated you wanted no debug compilation but the VS IDE still tries to give you debug info. It seems to sort of guess at the line sometimes you will find it out by a line or 2 especially if it has optimized some of the code away. When running outside the IDE I know it only uses the correct DLL because the times I have used DLL distribution I only copy the one DLL for install.

        In vino veritas

        F Offline
        F Offline
        ForNow
        wrote on last edited by
        #3

        Thanks I just realized I did a number of SetDlgItemText for labels in my Dialog but I never Created a window Maybe I'll just have the appropriate CStatic's and use DDX_Control to initialize the windows handle or better yet just use DDX_Text and put the data in a CString Thanks

        1 Reply Last reply
        0
        • F ForNow

          HI, I have code that works fine in debug but I have already learned my lesson that it does mean It will work in Release Anyway I got an assertion in wincore.cpp line 656 for having a window handle = NULL After the message box came up pointing me to the location in wincore.cpp where the problem was I tried to attach the VS debugger with my solution. Wasn't much help as the call stack was all windows code One thing I did notice that was odd the DLL was MFC140d.DLL isn't that the debug version of MFC I checked my property pages for release and I had /MD not /MDd shouldn't I have MFC140.DLL ??

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          For some reason your release build is linked with the debug version of the MFC. You should find out why and fix that. A possible reason is linking with another DLL that depends on the MFC DLL and is a debug version itself. With proper code, a debug build should also assert at that point (window handle NULL). However, it would not assert if the handle is not NULL but invalid (uninitialised variable). But then you usually get other runtime errors.

          F 1 Reply Last reply
          0
          • J Jochen Arndt

            For some reason your release build is linked with the debug version of the MFC. You should find out why and fix that. A possible reason is linking with another DLL that depends on the MFC DLL and is a debug version itself. With proper code, a debug build should also assert at that point (window handle NULL). However, it would not assert if the handle is not NULL but invalid (uninitialised variable). But then you usually get other runtime errors.

            F Offline
            F Offline
            ForNow
            wrote on last edited by
            #5

            My only guess at this point that after doing various "new" to allocate heap storage to format labels for the dialog I do AfxCheckMemory rather then assert to see if I some how over stepped my storage allocation Thanks

            J 1 Reply Last reply
            0
            • F ForNow

              My only guess at this point that after doing various "new" to allocate heap storage to format labels for the dialog I do AfxCheckMemory rather then assert to see if I some how over stepped my storage allocation Thanks

              J Offline
              J Offline
              Jochen Arndt
              wrote on last edited by
              #6

              AfxCheckMemory[^]

              This function works only in the Debug version of MFC.

              Therefore, it is common to call that within an ASSERT(). Note also that you should check if the affected handle is on the heap. It does not help when it is on the stack.

              F 1 Reply Last reply
              0
              • J Jochen Arndt

                AfxCheckMemory[^]

                This function works only in the Debug version of MFC.

                Therefore, it is common to call that within an ASSERT(). Note also that you should check if the affected handle is on the heap. It does not help when it is on the stack.

                F Offline
                F Offline
                ForNow
                wrote on last edited by
                #7

                I am quite sure the reason I got an assertion was because I did a SetDlgItemText without some how creating a m_hWnd Just surprising that it worked at all under debug but then again I am beginning to understand the "debug" version covers up for a lot of mistakes On more thing should assert only be used in "debug" Thanks

                J 1 Reply Last reply
                0
                • F ForNow

                  I am quite sure the reason I got an assertion was because I did a SetDlgItemText without some how creating a m_hWnd Just surprising that it worked at all under debug but then again I am beginning to understand the "debug" version covers up for a lot of mistakes On more thing should assert only be used in "debug" Thanks

                  J Offline
                  J Offline
                  Jochen Arndt
                  wrote on last edited by
                  #8

                  Quote:

                  I am quite sure the reason I got an assertion was because I did a SetDlgItemText without some how creating a m_hWnd

                  That is very likely.

                  ForNow wrote:

                  On more thing should assert only be used in "debug"

                  Just read the documentation:

                  assert Macro, _assert, _wassert[^]

                  The assert macro is enabled in both the release and debug versions of the C run-time libraries when NDEBUG is not defined. When NDEBUG is defined, the macro is available but does not evaluate its argument and has no effect. When it is enabled, the assert macro calls _wassert for its implementation. Other assertion macros, _ASSERT, _ASSERTE and _ASSERT_EXPR, are also available, but they only evaluate the expressions passed to them when the _DEBUG macro has been defined and when they are in code linked with the debug version of the C run-time libraries.

                  My tip: Use them often (e.g. on top of functions for parameter checking and with function return values when there is no error handling). They are simply ignored in release builds but can save you a lot of debugging time.

                  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