Help, missing something here!
Let's say I have a .DLL with a function like this:
Code:
// function declaration
CString GetStringValue(const CString &fieldname);
// function definition
CString GetStringValue(const CString &fieldname)
{
CString str;
(some stuff to read a field value from a database)
str = db.getvalue(blah blah blah)
return(str);
}
and the function is used by the calling program like this:
Code:
CString str;
str = GetStringValue("State");
....
no problem, until 'str' goes out of scope in the calling program, then the runtime library crashes with a heap error when it runs the destructor ~CString().
Why is this?
Yes, however I think I am doing it that way
My link settings for both the .DLL and the calling program are set to "Use MFC in a Shared DLL" (using VC 6.0).
Is this what you were referring to? Any other thoughts?
Both are single-threaded projects,
created using Appwizard. Nothing special, I haven't made any changes.
Is/are there any compiler and/or linker settings that are messing me up? Both projects are optimized for speed.
BTW here is the exact message I get in VC's status pane:
HEAP[Report Creator.exe]: Invalid Address specified to RtlValidateHeap( 340000, dc43e4 )
Call Stack:
NTDLL! 77f97704()
NTDLL! 77fb6688()
NTDLL! 77f935f9()
KERNEL32! 77e9f540()
MSVCRTD! 102142c0()
MSVCRTD! 10213611()
MSVCRTD! 10213541()
operator delete(void * 0x00dc4404) line 351 + 12 bytes
CString::FreeData() line 146 + 15 bytes
CString::~CString() line 213
CMainFrame::OnCreate(tagCREATESTRUCTA * 0x0012fb80) line 151 + 34 bytes
CWnd::OnWndMsg(unsigned int 1, unsigned int 0, long 1244032, long * 0x0012fa08) line 1811 + 13 bytes
CWnd::WindowProc(unsigned int 1, unsigned int 0, long 1244032) line 1585 + 30 bytes
AfxCallWndProc(CWnd * 0x00345040 {CMainFrame hWnd=0x045306e0}, HWND__ * 0x045306e0, unsigned int 1, unsigned int 0, long 1244032) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x045306e0, unsigned int 1, unsigned int 0, long 1244032) line 368
AfxWndProcBase(HWND__ * 0x045306e0, unsigned int 1, unsigned int 0, long 1244032) line 220 + 21 bytes
USER32! 77e3a244()
USER32! 77e14730()
USER32! 77e1cf17()
NTDLL! 77fa02ff()
USER32! 77e1cf5a()
CWnd::CreateEx(unsigned long 0, const char * 0x001340b8, const char * 0x003453cc, unsigned long 13598720, int -2147483648, int -2147483648, int -2147483648, int -2147483648, HWND__ * 0x00000000, HMENU__ * 0x0e0c0bd5, void * 0x00000000) line 694 + 54 bytes
CFrameWnd::Create(const char * 0x001340b8, const char * 0x003453cc, unsigned long 13598720, const tagRECT & {top=-2147483648 bottom=0 left=-2147483648 right=0}, CWnd * 0x00000000 {CWnd hWnd=???}, const char * 0x00000080, unsigned long 0, CCreateContext * 0x00000000) line 564 + 79 bytes
CFrameWnd::LoadFrame(unsigned int 128, unsigned long 13598720, CWnd * 0x00000000 {CWnd hWnd=???}, CCreateContext * 0x00000000) line 695 + 45 bytes
CMDIFrameWnd::LoadFrame(unsigned int 128, unsigned long 13598720, CWnd * 0x00000000 {CWnd hWnd=???}, CCreateContext * 0x00000000) line 286 + 24 bytes
CReportCreatorApp::InitInstance() line 96 + 30 bytes
AfxWinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x001333ad, int 1) line 39 + 11 bytes
WinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x001333ad, int 1) line 30
WinMainCRTStartup() line 330 + 54 bytes
KERNEL32! 77ea847c()