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