Hi.

I am learning about dll. I created a simple dll with one class and one member function that returns a string object. The function looks something like this.

-----
string MyClass::MyFunc()
{
string text = TEXT("Testing 1 2 3");
return text;
}
-----

In the main program, I statatically link the dll to the program. Everything compiles fine. However, the program crashes right after MyFunc().

-----
// Statically link DLL.

#include "MyDLL.h"

void MyWinClass::F1()
{
// Instantiate MyClass as local variable

MyClass oneVar;

// Attempt to get text from oneVar's member function
// MyFunc() should return a string object. It does.

string newText = oneVar.MyFunc();
-----

Everything works up to and including the last line of code. I could even open the text MyFunc() returns. There is a big problem, however; the program crashes.

This is the error Visual C++ shows when the program crashes after calling a function via the DLL.

-----
HEAP[MyProgram.exe]: Invalid Address specified to RtlValidateHeap( 00360000, 00353FA0 )
Unhandled exception at 0x77f7f570 in MyProgram.exe.exe: User breakpoint.
-----

In debug mode, the debugger shows a message box that mentioned something about "_BLOCK_TYPE_IS_INVALID(pHead->nBlockUsed)."

Is there something wrong with the dll? The algorithm above works find if I call MyFunc() from inside another class. It seems that the program is trying to free something after return from the dll.

Thanks,
Kuphryn