V
Vinayak Raghuvamshi
I have a simple, non-managed structure. When I create an array of this
struct, only the first item in the array gets created, the others are
not. Here is my sample code.
This works when I build using a plain Windows application. But it does
not work when i build using a .Net console application. Does anybody
have an idea what could be the issue here? Any help would greatly be
appreciated. This looks like a bug in the way VC.Net handles mixed
mode object creation.
#pragma once
namespace ADCache
{
//! stations seldom have more than two streams per box (one for
narrow band and one for broadband)
//! but lets be paranoid and be ready to handle upto 12 streams per
station
const int MAX_STREAMS = 12;
//! Settings related to a given station.
struct LCStationSettings
{
//! Settings related to a single stream. A physical machine can have
more than one media streams on it
struct LCStream
{
TCHAR name [MAX_PATH]; //!< a descriptive name for the stream
TCHAR id [MAX_PATH]; //!< the stream id. this value is provisioned
by the admgmt system for each station
LCStream(const LCStream& other)
{
*this = other;
}
LCStream& operator = (const LCStream& other)
{
_tcscpy(name,other.name);
_tcscpy(id,other.id);
return *this;
}
LCStream()
{
MessageBox(NULL,0,0,MB_OK);
_tcscpy(name,"NOTSET");
_tcscpy(id,"NOTSET");
}
};
LCStream lcstreams[MAX_STREAMS]; //!< an array of stream infos
};
}
// I try to create the object in the form_load
System::Void Form1::Form1_Load(System::Object * sender,
System::EventArgs * e)
{
LCStationSettings stationSettings;
}
When I check the memory of the stationSettings object right after the
creation, I can see just the first LCStream being created.
What is even more wierd is that the ctor of the LCStream does get
invoked 12 times, but somehow, only the first one seems to really
succeed.
Regards,
-Vinayak
struct, only the first item in the array gets created, the others are
not. Here is my sample code.
This works when I build using a plain Windows application. But it does
not work when i build using a .Net console application. Does anybody
have an idea what could be the issue here? Any help would greatly be
appreciated. This looks like a bug in the way VC.Net handles mixed
mode object creation.
#pragma once
namespace ADCache
{
//! stations seldom have more than two streams per box (one for
narrow band and one for broadband)
//! but lets be paranoid and be ready to handle upto 12 streams per
station
const int MAX_STREAMS = 12;
//! Settings related to a given station.
struct LCStationSettings
{
//! Settings related to a single stream. A physical machine can have
more than one media streams on it
struct LCStream
{
TCHAR name [MAX_PATH]; //!< a descriptive name for the stream
TCHAR id [MAX_PATH]; //!< the stream id. this value is provisioned
by the admgmt system for each station
LCStream(const LCStream& other)
{
*this = other;
}
LCStream& operator = (const LCStream& other)
{
_tcscpy(name,other.name);
_tcscpy(id,other.id);
return *this;
}
LCStream()
{
MessageBox(NULL,0,0,MB_OK);
_tcscpy(name,"NOTSET");
_tcscpy(id,"NOTSET");
}
};
LCStream lcstreams[MAX_STREAMS]; //!< an array of stream infos
};
}
// I try to create the object in the form_load
System::Void Form1::Form1_Load(System::Object * sender,
System::EventArgs * e)
{
LCStationSettings stationSettings;
}
When I check the memory of the stationSettings object right after the
creation, I can see just the first LCStream being created.
What is even more wierd is that the ctor of the LCStream does get
invoked 12 times, but somehow, only the first one seems to really
succeed.
Regards,
-Vinayak