Click to See Complete Forum and Search --> : Problem in instantiate object in gcroot


sganeshcse
December 19th, 2006, 11:49 PM
Please look at this code
Please advice what I have to do.

below two classes are in one header file.
__gc class myclass
{
public:
myclass()
{ }
ArrayList* FEOmniFunds;
};

class TCFData
{
public:
TCFData();
~TCFData();
gcroot<myclass *> newobj;
}
extern TCFData *CFData

below code is in other cpp file

Below two line is in one function.
CFData = new TCFData();
memset(CFData, '\0', sizeof(TCFData));

Below two line is in another function.
CFData->newobj = new myclass();//Error is coming here
CFData->newobj->FEOmniFunds = new ArrayList(); //Here also

If I try to instantiate this object then I am getting the below error.

"An unhandled exception of type 'System.ExecutionEngineException' occurred in system.windows.forms.dll"

Please let me know why this error is coming?

darwen
December 20th, 2006, 03:39 AM
Check for #define new DEBUG_NEW at the top of the .cpp file. This should be removed if it exists.

Otherwise, I've no idea. This has always worked fine for me.

Darwen.

P.S. I would like to bet it's the


memset(CFData, '\0', sizeof(TCFData));


line. Remove it. There's no need to initialise the gcroot to NULL as it does this already in its constructor.

Darwen.

sganeshcse
December 20th, 2006, 08:44 AM
Darwen,

In the TCFData class i am having some other structures and char members.
If I didn't do this then I am getting errors.

My TCFData class is like that

class TCFData
{
TCFData()
{}
~TCFData()
{}

char a1[12];
char a2[12];
char a3[12];
mystruct *stru1;// Structure
mystruct *stru2;// Structure
mystruct *stru3;// Structure
gcroot<myclass *> newobj;
};
extern TCFData *CFData;

But I found something. If I memset the CFData object then gcroot's _handle is having "0" is the value and code is giving exception. If didn't memset then _handle is having some garbage values and the code is working fine.

I am new to gcroot.
Let me know why this discrepancies happening.