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. MFC DLL Help

MFC DLL Help

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++databaseperformancequestion
4 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.
  • M Offline
    M Offline
    Mike Danberg
    wrote on last edited by
    #1

    Hi all, Need some help with an MFC dll I have. I'm connecting/disconnecting to a database using two simple functions. __declspec(dllexport) void Connect() { AFX_MANAGE_STATE(AfxGetStaticModuleState( )); database.Open( "EmployeeManager" ); } __declspec(dllexport) void Disconnect() { AFX_MANAGE_STATE(AfxGetStaticModuleState( )); database.Close(); } database is declared as global so I can access it all through the dll. The problem is coming when I exit from the program using the dll. It throws a memory exception. I can't figure out why. I know its a problem with the connection because I tested just opening and connecting, then quitting and the error only occurs if I'm connected. I get an error regardless of whether or not I call disconnect on exit. Any ideas? Mike

    M 1 Reply Last reply
    0
    • M Mike Danberg

      Hi all, Need some help with an MFC dll I have. I'm connecting/disconnecting to a database using two simple functions. __declspec(dllexport) void Connect() { AFX_MANAGE_STATE(AfxGetStaticModuleState( )); database.Open( "EmployeeManager" ); } __declspec(dllexport) void Disconnect() { AFX_MANAGE_STATE(AfxGetStaticModuleState( )); database.Close(); } database is declared as global so I can access it all through the dll. The problem is coming when I exit from the program using the dll. It throws a memory exception. I can't figure out why. I know its a problem with the connection because I tested just opening and connecting, then quitting and the error only occurs if I'm connected. I get an error regardless of whether or not I call disconnect on exit. Any ideas? Mike

      M Offline
      M Offline
      Mike Danberg
      wrote on last edited by
      #2

      Did some more testing. The actual error I'm getting is "Exception Breakpoint A breakpoint has been reached." This occurs only in debug mode. The release has no errors. I can't find any breakpoints anywhere so I still have no idea what's going on in debug mode. Mike

      M 1 Reply Last reply
      0
      • M Mike Danberg

        Did some more testing. The actual error I'm getting is "Exception Breakpoint A breakpoint has been reached." This occurs only in debug mode. The release has no errors. I can't find any breakpoints anywhere so I still have no idea what's going on in debug mode. Mike

        M Offline
        M Offline
        Mike Dimmick
        wrote on last edited by
        #3

        A breakpoint is reported to the debugger by raising a STATUS_BREAKPOINT exception, code 0x80000003. If the debugger is not expecting it (i.e. there is no breakpoint on that instruction), it will report the exception to the user. The system's heap manager will generate such an exception if it discovers, on freeing a block, that the block has become corrupted. I suggest using the gflags utility to enable page granularity heap allocations, where the heap manager allocates two pages per heap allocation. The first page contains your allocated block (allocated at the end of the page), and the second page is marked no access. When you overflow a heap buffer, you get an immediate access violation at that point. IIRC, the heap manager by default only does heap checking if the executable image has the DEBUG flag in the header. VC's linker adds the DEBUG flag for a debug build. To set up gflags, run it as an administrator, enter the name of your executable in the 'Image File Name' box, then choose the 'Image File Options' radio button. Check the 'Enable page heap' box and click OK.

        M 1 Reply Last reply
        0
        • M Mike Dimmick

          A breakpoint is reported to the debugger by raising a STATUS_BREAKPOINT exception, code 0x80000003. If the debugger is not expecting it (i.e. there is no breakpoint on that instruction), it will report the exception to the user. The system's heap manager will generate such an exception if it discovers, on freeing a block, that the block has become corrupted. I suggest using the gflags utility to enable page granularity heap allocations, where the heap manager allocates two pages per heap allocation. The first page contains your allocated block (allocated at the end of the page), and the second page is marked no access. When you overflow a heap buffer, you get an immediate access violation at that point. IIRC, the heap manager by default only does heap checking if the executable image has the DEBUG flag in the header. VC's linker adds the DEBUG flag for a debug build. To set up gflags, run it as an administrator, enter the name of your executable in the 'Image File Name' box, then choose the 'Image File Options' radio button. Check the 'Enable page heap' box and click OK.

          M Offline
          M Offline
          Mike Danberg
          wrote on last edited by
          #4

          Ok I did that and it gave me an access violation. Doesn't really help me though. First off I'm not real good at debugging, so unless its an obvious problem, doing something like you suggested doesn't help me much. It's still the same thing that's causing it. When I try disconnecting from a database from my dll. It really doesn't make any sense to me. It worked before when I opened and closed the database from within an exported function. Then I decided it was a waste of resources to open and close each time I wanted to access it. So I declared a global instance of a CDatabase class. I connect once at program initialization and then call disconnect at close. Seemed pretty simple to me, but now its throwing an exception for no apparent reason. The only solution I can think of is to go back to the old way of opening and closing the DB each time I access it. Mike

          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