I have the following structure:
class myInterface
{
public:
virtual bool Send(char* myChar);
}
class myClass;
public ref class Parser
{
bool Transmit(String^ mString);
}
class myClass : public myInterface
{
public:
virtual bool Send(char* myChar);
private:
gcroot<Parser^> pParser;
}
My problem is that somewhere in my unmanaged code I have to call the send function. It calls a function from the sent managed code, but the Send function calls the transfer method from the Parser class. The problem is that when I debug, the pParser instance is empty (even if I already created it earlier in the constructor).
Is this a garbage collector or erroneous virtual table problem? How can I fix it? Thank!
UPDATE:
After some additional debugging, I realized that if I included other instances of gcroot, for example:
gcroot<AppDomaion^> pDomain;
and then in code I tried to execute:
pDomain = AppDomain::CurrentDomain;
The debugger will show the same empty value as for pParser. Is there something wrong with what I'm doing? Should I create an instance of the class differently?
UPDATE2:
/ :
: (wrapper.h)
public ref class Wrapper
{
public:
Send(String^ mSendMessage);
Parse(String^ mMessageString);
...
private:
ComLayer* mComm;
CInferface mInterface;
};
private class CInterface : public IIterface
{
public:
virtual bool Deliver(CMessage mMessage);
...
private:
gcroot<Wrapper^> mParent;
};
(wrapper.cpp)
Wrapper::Send(String^ mSendMessage)
{
...
mComm->Send(mMessage);
}
Wrapper::Parse(String^ mMessageString)
{
...
}
CInterface::Deliver(CMessage* mMessage)
{
...
mParent->Parse(mMessageString)
}
: (commLayer.h)
class CommLayer
{
public:
bool Send(CMessage* mMessage);
...
private:
IInterface mInterface;
};
: (IInterface.h)
class IInterface
{
public:
virtual bool Deliver(CMessage mMessage);
};
, mInferface- > Deliver (mMessage); mParent . Wrapper mParent (value = null); IInterface, Wrapper ^ CInterface.