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. Problem with CDC:SetMapMode (in Release-Mode) [modified]

Problem with CDC:SetMapMode (in Release-Mode) [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++graphicsdebuggingannouncement
11 Posts 3 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.
  • A AnTri

    Hey, I've a MFC-Based DLL calling a special drawing function in another DLL (MFC extended). All works fine in debug-mode. But when I tried to test my DLL in release mode, the program crashes in the line with SetMapMode. Function in calling DLL (OnPaint): ... CPaintDC dc(this); //dc.SetMapMode(MM_LOMETRIC); <<<< Works fine here! PaintSpecialGraphics(&dc); ... Function in DLL: int WINAPI PaintSpecialGraphics(CDC *pDC) { ... pDC->SetMapMode(MM_LOMETRIC); <<<< CRASH !!! ... } Thanx for your help..... P.S: When I try to call the "PaintSpecialGrafics" from my Application (.exe) all works fine... -- modified at 18:09 Thursday 31st August, 2006

    S Offline
    S Offline
    Stephen Hewitt
    wrote on last edited by
    #2

    First I'd make sure you're building the release build with debug info. Follow these steps in MSVC 6:   - Select "Project->Settings...".   - Select the "Release" configuration.   - Select "C/C++" tab.   - Select "General" in the "Category" combo.   - In the "Debug info" combo select "Program Database".   - Select the "Link" tab.   - Select "Debug" in the "Category" in combo.   - Tick "Debug info" and "Separate types" and choose "Microsoft format".   - Select OK.   - Rebuild all. If you're using a newer version of visual studio you'll have to adjust these steps. Now reproduce the error are see where the error occurs in the MFC source code; this might give you more chance of understanding what's going wrong.

    Steve

    1 Reply Last reply
    0
    • A AnTri

      Hey, I've a MFC-Based DLL calling a special drawing function in another DLL (MFC extended). All works fine in debug-mode. But when I tried to test my DLL in release mode, the program crashes in the line with SetMapMode. Function in calling DLL (OnPaint): ... CPaintDC dc(this); //dc.SetMapMode(MM_LOMETRIC); <<<< Works fine here! PaintSpecialGraphics(&dc); ... Function in DLL: int WINAPI PaintSpecialGraphics(CDC *pDC) { ... pDC->SetMapMode(MM_LOMETRIC); <<<< CRASH !!! ... } Thanx for your help..... P.S: When I try to call the "PaintSpecialGrafics" from my Application (.exe) all works fine... -- modified at 18:09 Thursday 31st August, 2006

      J Offline
      J Offline
      Jun Du
      wrote on last edited by
      #3

      I suspect it's due to the passing of the DC object between two DLLs, but I can't be sure where exactly the problem is. To narrow it down, check the following: 1) Check the validity of pointer pDC in PaintSpecialGraphics(CDC *pDC); 2) Add thhis code to the calling DLL and see if it works locally: CDC* pDC = &dc; pDC->SetMapMode(MM_LOMETRIC); 3) To further test, you could change the function signature from PaintSpecialGraphics(CDC *pDC) to PaintSpecialGraphics(CPaintDC &dc). Etc.

      Best, Jun

      S A 2 Replies Last reply
      0
      • J Jun Du

        I suspect it's due to the passing of the DC object between two DLLs, but I can't be sure where exactly the problem is. To narrow it down, check the following: 1) Check the validity of pointer pDC in PaintSpecialGraphics(CDC *pDC); 2) Add thhis code to the calling DLL and see if it works locally: CDC* pDC = &dc; pDC->SetMapMode(MM_LOMETRIC); 3) To further test, you could change the function signature from PaintSpecialGraphics(CDC *pDC) to PaintSpecialGraphics(CPaintDC &dc). Etc.

        Best, Jun

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #4

        I suspected the same thing but, like you, can't pinpoint the exact problem. That's why I think knowing where things go wrong inside MFC might help. Perhaps it's possible that different compiler settings were used in the EXE and the DLL and this caused the layout of the CDC class differ. Or perhaps it's a mixed allocator problem: class CDC in the EXE allocates some data on its heap the the DLL free it on a different heap. It would probably be a good idea to pass the raw HDC when passing a DC between modules.

        Steve

        A 1 Reply Last reply
        0
        • A AnTri

          Hey, I've a MFC-Based DLL calling a special drawing function in another DLL (MFC extended). All works fine in debug-mode. But when I tried to test my DLL in release mode, the program crashes in the line with SetMapMode. Function in calling DLL (OnPaint): ... CPaintDC dc(this); //dc.SetMapMode(MM_LOMETRIC); <<<< Works fine here! PaintSpecialGraphics(&dc); ... Function in DLL: int WINAPI PaintSpecialGraphics(CDC *pDC) { ... pDC->SetMapMode(MM_LOMETRIC); <<<< CRASH !!! ... } Thanx for your help..... P.S: When I try to call the "PaintSpecialGrafics" from my Application (.exe) all works fine... -- modified at 18:09 Thursday 31st August, 2006

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #5

          I suggest you side step the problem as follows:  1. Change the signature of the DLL function as follows: int WINAPI PaintSpecialGraphics(HDC hDC);  2. Adjust the implementaion in the DLL so it looks like this: int WINAPI PaintSpecialGraphics(HDC hDC) {     CDC dc;     dc.Attach(hDC);     // Do stuff with 'dc' here...     dc.Detach(); }  3. Make the call like this: CPaintDC dc(this); PaintSpecialGraphics(dc); I suspect you can't use MFC classes across DLL boundries. Here are some possible reasons:  - MFC's handle map implementation.  - Different heaps.  - Different compiler settings in EXE and DLL.

          Steve

          A 1 Reply Last reply
          0
          • J Jun Du

            I suspect it's due to the passing of the DC object between two DLLs, but I can't be sure where exactly the problem is. To narrow it down, check the following: 1) Check the validity of pointer pDC in PaintSpecialGraphics(CDC *pDC); 2) Add thhis code to the calling DLL and see if it works locally: CDC* pDC = &dc; pDC->SetMapMode(MM_LOMETRIC); 3) To further test, you could change the function signature from PaintSpecialGraphics(CDC *pDC) to PaintSpecialGraphics(CPaintDC &dc). Etc.

            Best, Jun

            A Offline
            A Offline
            AnTri
            wrote on last edited by
            #6

            Thank you for your answer, I tried your recommendation... 1) --> Pointer is valid 2) --> works fine 3) --> ?

            1 Reply Last reply
            0
            • S Stephen Hewitt

              I suspected the same thing but, like you, can't pinpoint the exact problem. That's why I think knowing where things go wrong inside MFC might help. Perhaps it's possible that different compiler settings were used in the EXE and the DLL and this caused the layout of the CDC class differ. Or perhaps it's a mixed allocator problem: class CDC in the EXE allocates some data on its heap the the DLL free it on a different heap. It would probably be a good idea to pass the raw HDC when passing a DC between modules.

              Steve

              A Offline
              A Offline
              AnTri
              wrote on last edited by
              #7

              OK, the error is in the CDC class. The compiler stops in the function OffsetViewportOrg!

              S 1 Reply Last reply
              0
              • A AnTri

                OK, the error is in the CDC class. The compiler stops in the function OffsetViewportOrg!

                S Offline
                S Offline
                Stephen Hewitt
                wrote on last edited by
                #8

                Perhaps you can quote the file/line (and MFC version) and paste in some code surrounding the fault.

                Steve

                A 1 Reply Last reply
                0
                • S Stephen Hewitt

                  I suggest you side step the problem as follows:  1. Change the signature of the DLL function as follows: int WINAPI PaintSpecialGraphics(HDC hDC);  2. Adjust the implementaion in the DLL so it looks like this: int WINAPI PaintSpecialGraphics(HDC hDC) {     CDC dc;     dc.Attach(hDC);     // Do stuff with 'dc' here...     dc.Detach(); }  3. Make the call like this: CPaintDC dc(this); PaintSpecialGraphics(dc); I suspect you can't use MFC classes across DLL boundries. Here are some possible reasons:  - MFC's handle map implementation.  - Different heaps.  - Different compiler settings in EXE and DLL.

                  Steve

                  A Offline
                  A Offline
                  AnTri
                  wrote on last edited by
                  #9

                  Stephen Hewitt wrote:

                  I suspect you can't use MFC classes across DLL boundries. Here are some possible reasons: - MFC's handle map implementation. - Different heaps. - Different compiler settings in EXE and DLL.

                  Does this mean, that there is no way to exchange data (pointer to mfc objects) between mfc dlls? My concept is to exchange cobject dervied classes (pointer) between my application and a mfc-based calculation dll..

                  S 1 Reply Last reply
                  0
                  • S Stephen Hewitt

                    Perhaps you can quote the file/line (and MFC version) and paste in some code surrounding the fault.

                    Steve

                    A Offline
                    A Offline
                    AnTri
                    wrote on last edited by
                    #10

                    Ok, here is the function where the debugger stops (wingdi.cpp, MFC 7.1, VS2003 SP1): CPoint CDC::SetViewportOrg(int x, int y) { ASSERT(m_hDC != NULL); CPoint point; if (m_hDC != m_hAttribDC) VERIFY(::SetViewportOrgEx(m_hDC, x, y, &point)); if (m_hAttribDC != NULL) VERIFY(::SetViewportOrgEx(m_hAttribDC, x, y, &point)); return point; <<<<<<<<<<<<<<< I can't imagine why the debugger/program stops at this line...?

                    1 Reply Last reply
                    0
                    • A AnTri

                      Stephen Hewitt wrote:

                      I suspect you can't use MFC classes across DLL boundries. Here are some possible reasons: - MFC's handle map implementation. - Different heaps. - Different compiler settings in EXE and DLL.

                      Does this mean, that there is no way to exchange data (pointer to mfc objects) between mfc dlls? My concept is to exchange cobject dervied classes (pointer) between my application and a mfc-based calculation dll..

                      S Offline
                      S Offline
                      Stephen Hewitt
                      wrote on last edited by
                      #11

                      It depends on how the classes are implemented and packaged. Consider this example: class CExample { public:     int GetNum() { return g_Number; } } In this class the CExample::GetNum method access a global variable. If you include this class into an EXE and a DLL then the version in the EXE will access a global in the EXE; but when called from the DLL it will access a global (of the same name) in the DLL. Problems will probably ensue. There are ways around this issue but perhaps the MFC classes are simply not designed to be passed between module boundries (like this class). Unless you know it is same to do this the only safe assumption is that you can't.

                      Steve

                      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