Stack overflow in mixed native/managed DLL

G

Graham

Hi everyone,

I have a DLL which contains both native and managed C++. To
the best of my knowledge, the native code does not use MFC.

The managed C++ is basically a wrapper around the native
C++ ... so the relevant code would look like this:

public __gc class ManagedWrapper {

private:
MyNativeClass * m_pNative;

public:
ManagedWrapper() {
m_pNative = new MyNativeClass();
}
}

The native constructor isn't even getting a chance to run;
I get a stack overflow on the "new" operator. The stack
looks like this: (I'll write it out in the opposite order
to which it appears in VS.NET's call stack window, as this
is clearer in email)

VBNetApp.frmMain_Load()
ManagedWrapperDLL.ManagedWrapper()
_nh_malloc_dbg(unsigned int nSize=24, ...) Line 254 + 0x7
_lock(int locknum=4) Line 311 + 0x9
_mtinitlocknum(int locknum=4) Line 251 + 0x13
_malloc_dbg(unsigned int nSize=24, ...) Line 176 + 0x1b

Then these last four lines repeat ad infinitum until a
stack overflow occurs. The loop is clearly visible in the
code (dbgheap.c and mlock.c).

I'm using VS.NET 2003. The DLL is built in debug mode right
now (/MTd).

Can anyone tell me what I've done wrong, and/or how to
correct the problem?

Thanks.

-- graham
 
G

Graham

The answer I found is "don't use /MT(d) for a DLL, it won't
work -- use /MD(d) instead".

This also means using msvcrt(d) instead of libcmt(d).

That's the limit of my understanding, at this point...
maybe who actually knows what all this means can briefly
explain what all of this means.

-- graham
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top