lapucca
asked on
Vector of Objects getting Uninitilized Memory error in my debug tool, Rational Purify
Hi Expert,
I have a COM DLL that I'm working on using VS2005 with only the windows library. In this, I have declare a vector to store objects that are created based on my own class. I've also coded the copy constructor and the Operator = overload so the vector would accept it. Each field of each object that req mem allocation has memory allocated for it before I call the vector.Push_back. I'm getting Uninitilized Memory error in my debug tool, Rational Purify. If I'm just run Active Directory, client of my COM, my dll would crash with unhandled win32 error. I'm stuck here becuase I can't debug any further until I can resolve this bug.
I've listed some code and the error message below. Can you tell me what I'm missing here? Thank you.
vector <CUserContextData*> userDataObjects;
vector <CUserContextData*>::itera tor userDataIter;
CUserContextData *newUserData = new CUserContextData;
...allocated memory and assign values to the member data fields.
userDataObjects.push_back( newUserDat a);
class CUserContextData
{
public:
bool newObject, bWinLogOn, bUnifiedID, symarkEnabled, UIDChanged;
wchar_t *shell, *homeDir, *primaryGroup, *symarkUserRef, *LoginName,
*contextName;
LPCWSTR lpcwContextName;
int symarkUID, listViewIndex, UID;
void CUserContextData::Copier(c onst CUserContextData &newUserData)
{
LPCWSTR lpcTemp;
newObject = newUserData.newObject;
bWinLogOn = newUserData.bWinLogOn;
bUnifiedID = newUserData.bUnifiedID;
symarkEnabled = newUserData.symarkEnabled;
UIDChanged = newUserData.UIDChanged;
symarkUID = newUserData.symarkUID;
listViewIndex = newUserData.listViewIndex;
UID = newUserData.UID;
wchar_t *temp = new wchar_t[wcslen(newUserData .lpcwConte xtName)+1] ;
wcscpy(temp, newUserData.lpcwContextNam e);
lpcwContextName = T2CW(temp);
delete [] temp;
lpcTemp = T2CW(newUserData.contextNa me);
contextName = new wchar_t[wcslen(lpcTemp)+1] ;
wcscpy(contextName, (lpcTemp));
lpcTemp = T2CW(newUserData.LoginName );
LoginName = new wchar_t[wcslen(lpcTemp)+1] ;
wcscpy(LoginName, (lpcTemp));
lpcTemp = T2CW(newUserData.shell);
shell = new wchar_t[wcslen(lpcTemp)+1] ;
wcscpy(shell, (lpcTemp));
lpcTemp = T2CW(newUserData.homeDir);
homeDir = new wchar_t[wcslen(lpcTemp)+1] ;
wcscpy(homeDir, (lpcTemp));
lpcTemp = T2CW(newUserData.primaryGr oup);
primaryGroup = new wchar_t[wcslen(lpcTemp)+1] ;
wcscpy(primaryGroup, (lpcTemp));
lpcTemp = T2CW(newUserData.symarkUse rRef);
symarkUserRef = new wchar_t[wcslen(lpcTemp)+1] ;
wcscpy(symarkUserRef, (lpcTemp));
}
CUserContextData& CUserContextData::operator =(const CUserContextData&
newUserData)
{
if(this != &newUserData)
{
delete [] shell;
delete [] homeDir;
delete [] primaryGroup;
delete [] symarkUserRef;
delete [] LoginName;
delete [] contextName;
delete [] lpcwContextName;
Copier(newUserData);
}
return *this;
}
CUserContextData(void)
{
contextName = NULL;
shell = NULL;
homeDir = NULL;
primaryGroup = NULL;
symarkUserRef = NULL;
LoginName = NULL;
lpcwContextName = NULL;
}
CUserContextData::CUserCon textData(c onst CUserContextData &newUserData)
{
Copier(newUserData);
}
virtual ~CUserContextData(void)
{
//delete [] shell;
//delete [] homeDir;
//delete [] primaryGroup;
//delete [] symarkUserRef;
//if(LoginName != NULL)
// delete [] LoginName;
//delete [] contextName;
//delete [] lpcwContextName;
}
};
Error:
[W] UMR: Uninitialized memory read in
?_Debug_range@PAPAVCUserCo ntextData@ @@std@@YAX PAPAVCUser ContextDat a@@0PB_WI@ Z
{1 occurrence}
Reading 1 byte from 0x0809e7ef (1 byte at 0x0809e7ef uninitialized)
Address 0x0809e7ef points into a thread's stack
_Umove(_VEC_ITER_BASE(_Whe re), _Mylast, _Ptr); //
copy suffix
_CATCH_ALL
std::vector<CUserContextDa ta *,allocator<CUserContextDa ta
*>::std>::insert(_Vector_i terator<CU serContext Data
*,allocator<CUserContextDa ta *>::std>::std,CUserContext Data * const const&)
[g:\program files\microsoft visual studio 8\vc\include\vector.:854]
iterator insert(iterator _Where, const _Ty& _Val)
{ // insert _Val at _Where
size_type _Off = size() == 0 ? 0 : _Where - begin();
=> _Insert_n(_Where, (size_type)1, _Val);
return (begin() + _Off);
}
std::vector<CUserContextDa ta *,allocator<CUserContextDa ta
*>::std>::push_back(CUserC ontextData * const const&) [g:\program
files\microsoft visual studio 8\vc\include\vector.:800]
#endif /* _HAS_ITERATOR_DEBUGGING */
else
=> insert(end(), _Val);
}
#if _HAS_ITERATOR_DEBUGGING
CUserPage::RetrieveUserAtt (int,int,s truct HWND__ *,wchar_t *)
[c:\projects\unityextprope rty\cuserp age.cpp:55 4]
}
=> userDataObjects.push_back( newUserDat a);
//Retrieve record and fill the Dialog screen and select the
item
if( count == 0)
{
?_Uninit_move@PAPAVCUserCo ntextData@ @PAPAV1@V? $allocator @PAVCUserC ontextData @@@std@@U_ Undefined_ move_tag@3 @@std@@YAP APAVCUserC ontextData @@PAPAV1@0 0AAV?$allo cator@PAVC UserContex tData@@@0@ U_Undefine d_move_tag @0@U_Range _checked_i terator_ta g@0@@Z [g:\program files\microsoft visual studio 8\vc\include\memory.:160]
_FwdIt _Uninit_move(_InIt _First, _InIt _Last, _FwdIt _Dest,
_Alloc& _Al, _MoveCatTy, _Range_checked_iterator_ta g)
{ // move defaults to copy if there is not a more effecient way
=> return _STDEXT unchecked_uninitialized_co py(_First, _Last,
_Dest, _Al);
}
template<class _InIt, class _FwdIt, class _Alloc>
?_Unchecked_uninitialized_ move@PAPAV CUserConte xtData@@PA PAV1@V?$al locator@PA VCUserCont extData@@@ std@@@stde xt@@YAPAPA VCUserCont extData@@P APAV1@00AA V?$allocat or@PAVCUse rContextDa ta@@@std@@ @Z
[g:\program files\microsoft visual studio 8\vc\include\memory.:694]
_Alloc& _Al)
{ // move [_First, _Last) to raw _Dest, using _Al
return (_STD _Uninit_move(_CHECKED_BASE (_First),
_CHECKED_BASE(_Last), _Dest, _Al,
=> _STD _Move_cat(_Dest), _STD
_Range_checked_iterator_ta g()));
}
template<class _InIt,
?_Umove@PAPAVCUserContextD ata@@@?$ve ctor@PAVCU serContext Data@@V?$a llocator@P AVCUserCon textData@@ @std@@@std @@IAEPAPAV CUserConte xtData@@PA PAV2@00@Z
[g:\program files\microsoft visual studio 8\vc\include\vector.:1112]
pointer _Umove(_Iter _First, _Iter _Last, pointer _Ptr)
{ // move initializing [_First, _Last), using allocator
return (_STDEXT _Unchecked_uninitialized_m ove(_First , _Last,
=> _Ptr, this->_Alval));
}
void _Insert_n(iterator _Where,
std::vector<CUserContextDa ta *,allocator<CUserContextDa ta
*>::std>::_Insert_n(_Vecto r_iterator <CUserCont extData
*,allocator<CUserContextDa ta *>::std>::std,UINT,CUserCo ntextData * const
const&) [g:\program files\microsoft visual studio 8\vc\include\vector.:1143]
_TRY_BEGIN
_Ptr = _Umove(_Myfirst, _VEC_ITER_BASE(_Where),
=> _Newvec); // copy prefix
_Ptr = _Ufill(_Ptr, _Count, _Tmp); // add new stuff
_Umove(_VEC_ITER_BASE(_Whe re), _Mylast, _Ptr); //
copy suffix
_CATCH_ALL
Address 0x0809e7ef is 33 bytes above the frame pointer in
?_Debug_range@PAPAVCUserCo ntextData@ @@std@@YAX PAPAVCUser ContextDat a@@0PB_WI@ Z
Thread ID: 0xc8c
Error location
?_Debug_range@PAPAVCUserCo ntextData@ @@std@@YAX PAPAVCUser ContextDat a@@0PB_WI@ Z
[g:\program files\microsoft visual studio 8\vc\include\xutility.:136 8]
template<class _InIt> inline
void __CLRCALL_OR_CDECL _Debug_range(_InIt _First, _InIt _Last,
const wchar_t *_File, unsigned int _Line)
{ // test iterator pair for valid range
=> _Debug_range2(_First, _Last, _File, _Line, _Iter_cat(_First));
}
// TEMPLATE FUNCTION _Debug_order
?_Uninit_copy@PAPAVCUserCo ntextData@ @PAPAV1@V? $allocator @PAVCUserC ontextData @@@std@@@s td@@YAPAPA VCUserCont extData@@P APAV1@00AA V?$allocat or@PAVCUse rContextDa ta@@@0@U_S calar_ptr_ iterator_t ag@0@U_Ran ge_checked _iterator_ tag@0@@Z
[g:\program files\microsoft visual studio 8\vc\include\memory.:124]
_FwdIt _Uninit_copy(_InIt _First, _InIt _Last, _FwdIt _Dest,
_Alloc&, _Scalar_ptr_iterator_tag, _Range_checked_iterator_ta g)
{ // copy [_First, _Last) to raw _Dest, scalar type
=> _DEBUG_RANGE(_First, _Last);
_DEBUG_POINTER(_Dest);
size_t _Count = (size_t)(_Last - _First);
_FwdIt _Result = _Dest + _Count;
?unchecked_uninitialized_c opy@PAPAVC UserContex tData@@PAP AV1@V?$all ocator@PAV CUserConte xtData@@@s td@@@stdex t@@YAPAPAV CUserConte xtData@@PA PAV1@00AAV ?$allocato r@PAVCUser ContextDat a@@@std@@@ Z
[g:\program files\microsoft visual studio 8\vc\include\memory.:674]
_Alloc& _Al)
{ // copy [_First, _Last) to raw _Dest, using _Al
return (_STD _Uninit_copy(_CHECKED_BASE (_First),
_CHECKED_BASE(_Last), _Dest, _Al,
=> _STD _Ptr_cat(_First, _Dest), _STD
_Range_checked_iterator_ta g()));
}
template<class _InIt,
?_Uninit_move@PAPAVCUserCo ntextData@ @PAPAV1@V? $allocator @PAVCUserC ontextData @@@std@@U_ Undefined_ move_tag@3 @@std@@YAP APAVCUserC ontextData @@PAPAV1@0 0AAV?$allo cator@PAVC UserContex tData@@@0@ U_Undefine d_move_tag @0@U_Range _checked_i terator_ta g@0@@Z [g:\program files\microsoft visual studio 8\vc\include\memory.:160]
--
Thanks.
I have a COM DLL that I'm working on using VS2005 with only the windows library. In this, I have declare a vector to store objects that are created based on my own class. I've also coded the copy constructor and the Operator = overload so the vector would accept it. Each field of each object that req mem allocation has memory allocated for it before I call the vector.Push_back. I'm getting Uninitilized Memory error in my debug tool, Rational Purify. If I'm just run Active Directory, client of my COM, my dll would crash with unhandled win32 error. I'm stuck here becuase I can't debug any further until I can resolve this bug.
I've listed some code and the error message below. Can you tell me what I'm missing here? Thank you.
vector <CUserContextData*> userDataObjects;
vector <CUserContextData*>::itera
CUserContextData *newUserData = new CUserContextData;
...allocated memory and assign values to the member data fields.
userDataObjects.push_back(
class CUserContextData
{
public:
bool newObject, bWinLogOn, bUnifiedID, symarkEnabled, UIDChanged;
wchar_t *shell, *homeDir, *primaryGroup, *symarkUserRef, *LoginName,
*contextName;
LPCWSTR lpcwContextName;
int symarkUID, listViewIndex, UID;
void CUserContextData::Copier(c
{
LPCWSTR lpcTemp;
newObject = newUserData.newObject;
bWinLogOn = newUserData.bWinLogOn;
bUnifiedID = newUserData.bUnifiedID;
symarkEnabled = newUserData.symarkEnabled;
UIDChanged = newUserData.UIDChanged;
symarkUID = newUserData.symarkUID;
listViewIndex = newUserData.listViewIndex;
UID = newUserData.UID;
wchar_t *temp = new wchar_t[wcslen(newUserData
wcscpy(temp, newUserData.lpcwContextNam
lpcwContextName = T2CW(temp);
delete [] temp;
lpcTemp = T2CW(newUserData.contextNa
contextName = new wchar_t[wcslen(lpcTemp)+1]
wcscpy(contextName, (lpcTemp));
lpcTemp = T2CW(newUserData.LoginName
LoginName = new wchar_t[wcslen(lpcTemp)+1]
wcscpy(LoginName, (lpcTemp));
lpcTemp = T2CW(newUserData.shell);
shell = new wchar_t[wcslen(lpcTemp)+1]
wcscpy(shell, (lpcTemp));
lpcTemp = T2CW(newUserData.homeDir);
homeDir = new wchar_t[wcslen(lpcTemp)+1]
wcscpy(homeDir, (lpcTemp));
lpcTemp = T2CW(newUserData.primaryGr
primaryGroup = new wchar_t[wcslen(lpcTemp)+1]
wcscpy(primaryGroup, (lpcTemp));
lpcTemp = T2CW(newUserData.symarkUse
symarkUserRef = new wchar_t[wcslen(lpcTemp)+1]
wcscpy(symarkUserRef, (lpcTemp));
}
CUserContextData& CUserContextData::operator
newUserData)
{
if(this != &newUserData)
{
delete [] shell;
delete [] homeDir;
delete [] primaryGroup;
delete [] symarkUserRef;
delete [] LoginName;
delete [] contextName;
delete [] lpcwContextName;
Copier(newUserData);
}
return *this;
}
CUserContextData(void)
{
contextName = NULL;
shell = NULL;
homeDir = NULL;
primaryGroup = NULL;
symarkUserRef = NULL;
LoginName = NULL;
lpcwContextName = NULL;
}
CUserContextData::CUserCon
{
Copier(newUserData);
}
virtual ~CUserContextData(void)
{
//delete [] shell;
//delete [] homeDir;
//delete [] primaryGroup;
//delete [] symarkUserRef;
//if(LoginName != NULL)
// delete [] LoginName;
//delete [] contextName;
//delete [] lpcwContextName;
}
};
Error:
[W] UMR: Uninitialized memory read in
?_Debug_range@PAPAVCUserCo
{1 occurrence}
Reading 1 byte from 0x0809e7ef (1 byte at 0x0809e7ef uninitialized)
Address 0x0809e7ef points into a thread's stack
_Umove(_VEC_ITER_BASE(_Whe
copy suffix
_CATCH_ALL
std::vector<CUserContextDa
*>::std>::insert(_Vector_i
*,allocator<CUserContextDa
[g:\program files\microsoft visual studio 8\vc\include\vector.:854]
iterator insert(iterator _Where, const _Ty& _Val)
{ // insert _Val at _Where
size_type _Off = size() == 0 ? 0 : _Where - begin();
=> _Insert_n(_Where, (size_type)1, _Val);
return (begin() + _Off);
}
std::vector<CUserContextDa
*>::std>::push_back(CUserC
files\microsoft visual studio 8\vc\include\vector.:800]
#endif /* _HAS_ITERATOR_DEBUGGING */
else
=> insert(end(), _Val);
}
#if _HAS_ITERATOR_DEBUGGING
CUserPage::RetrieveUserAtt
[c:\projects\unityextprope
}
=> userDataObjects.push_back(
//Retrieve record and fill the Dialog screen and select the
item
if( count == 0)
{
?_Uninit_move@PAPAVCUserCo
_FwdIt _Uninit_move(_InIt _First, _InIt _Last, _FwdIt _Dest,
_Alloc& _Al, _MoveCatTy, _Range_checked_iterator_ta
{ // move defaults to copy if there is not a more effecient way
=> return _STDEXT unchecked_uninitialized_co
_Dest, _Al);
}
template<class _InIt, class _FwdIt, class _Alloc>
?_Unchecked_uninitialized_
[g:\program files\microsoft visual studio 8\vc\include\memory.:694]
_Alloc& _Al)
{ // move [_First, _Last) to raw _Dest, using _Al
return (_STD _Uninit_move(_CHECKED_BASE
_CHECKED_BASE(_Last), _Dest, _Al,
=> _STD _Move_cat(_Dest), _STD
_Range_checked_iterator_ta
}
template<class _InIt,
?_Umove@PAPAVCUserContextD
[g:\program files\microsoft visual studio 8\vc\include\vector.:1112]
pointer _Umove(_Iter _First, _Iter _Last, pointer _Ptr)
{ // move initializing [_First, _Last), using allocator
return (_STDEXT _Unchecked_uninitialized_m
=> _Ptr, this->_Alval));
}
void _Insert_n(iterator _Where,
std::vector<CUserContextDa
*>::std>::_Insert_n(_Vecto
*,allocator<CUserContextDa
const&) [g:\program files\microsoft visual studio 8\vc\include\vector.:1143]
_TRY_BEGIN
_Ptr = _Umove(_Myfirst, _VEC_ITER_BASE(_Where),
=> _Newvec); // copy prefix
_Ptr = _Ufill(_Ptr, _Count, _Tmp); // add new stuff
_Umove(_VEC_ITER_BASE(_Whe
copy suffix
_CATCH_ALL
Address 0x0809e7ef is 33 bytes above the frame pointer in
?_Debug_range@PAPAVCUserCo
Thread ID: 0xc8c
Error location
?_Debug_range@PAPAVCUserCo
[g:\program files\microsoft visual studio 8\vc\include\xutility.:136
template<class _InIt> inline
void __CLRCALL_OR_CDECL _Debug_range(_InIt _First, _InIt _Last,
const wchar_t *_File, unsigned int _Line)
{ // test iterator pair for valid range
=> _Debug_range2(_First, _Last, _File, _Line, _Iter_cat(_First));
}
// TEMPLATE FUNCTION _Debug_order
?_Uninit_copy@PAPAVCUserCo
[g:\program files\microsoft visual studio 8\vc\include\memory.:124]
_FwdIt _Uninit_copy(_InIt _First, _InIt _Last, _FwdIt _Dest,
_Alloc&, _Scalar_ptr_iterator_tag, _Range_checked_iterator_ta
{ // copy [_First, _Last) to raw _Dest, scalar type
=> _DEBUG_RANGE(_First, _Last);
_DEBUG_POINTER(_Dest);
size_t _Count = (size_t)(_Last - _First);
_FwdIt _Result = _Dest + _Count;
?unchecked_uninitialized_c
[g:\program files\microsoft visual studio 8\vc\include\memory.:674]
_Alloc& _Al)
{ // copy [_First, _Last) to raw _Dest, using _Al
return (_STD _Uninit_copy(_CHECKED_BASE
_CHECKED_BASE(_Last), _Dest, _Al,
=> _STD _Ptr_cat(_First, _Dest), _STD
_Range_checked_iterator_ta
}
template<class _InIt,
?_Uninit_move@PAPAVCUserCo
--
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi cwwkie,
I think it might be easier at this point for me to change the code and store bojects of my class in the vector, which means change the way I declare it and reference it. I'll try it tomorrow and see if it works. Also, do I need to change my class declaration, like the copy constructor or the operator=, descructor? Can you see if it might be cause by any one of them? I'm not sure about code that I wrote for those. Thanks.
class CUserContextData
{
public:
bool newObject, bWinLogOn, bUnifiedID, symarkEnabled, UIDChanged;
wchar_t *shell, *homeDir, *primaryGroup, *symarkUserRef, *LoginName, *contextName;
LPCWSTR lpcwContextName;
int symarkUID, listViewIndex, UID;
//std::wstring test;
void CUserContextData::Copier(c onst CUserContextData &newUserData)
{
const wchar_t *lpcTemp;
newObject = newUserData.newObject;
bWinLogOn = newUserData.bWinLogOn;
bUnifiedID = newUserData.bUnifiedID;
symarkEnabled = newUserData.symarkEnabled;
UIDChanged = newUserData.UIDChanged;
symarkUID = newUserData.symarkUID;
listViewIndex = newUserData.listViewIndex;
UID = newUserData.UID;
wchar_t *temp = new wchar_t[wcslen(newUserData .lpcwConte xtName)+1] ;
wcscpy_s(temp, wcslen(newUserData.lpcwCon textName)+ 1, newUserData.lpcwContextNam e);
lpcwContextName = (LPCWSTR)temp;
lpcTemp = T2CW(newUserData.contextNa me);
contextName = new wchar_t[wcslen(newUserData .contextNa me)+1];
wcscpy_s(contextName, wcslen(newUserData.context Name)+1, lpcTemp);
lpcTemp = T2CW(newUserData.LoginName );
LoginName = new wchar_t[wcslen(newUserData .LoginName )+1];
wcscpy_s(LoginName, wcslen(newUserData.LoginNa me)+1, (lpcTemp));
lpcTemp = T2CW(newUserData.shell);
shell = new wchar_t[wcslen(lpcTemp)+1] ;
wcscpy_s(shell, wcslen(lpcTemp)+1, (lpcTemp));
lpcTemp = T2CW(newUserData.homeDir);
homeDir = new wchar_t[wcslen(lpcTemp)+1] ;
wcscpy_s(homeDir, wcslen(lpcTemp)+1, (lpcTemp));
lpcTemp = T2CW(newUserData.primaryGr oup);
primaryGroup = new wchar_t[wcslen(lpcTemp)+1] ;
wcscpy_s(primaryGroup, wcslen(lpcTemp)+1, (lpcTemp));
lpcTemp = T2CW(newUserData.symarkUse rRef);
symarkUserRef = new wchar_t[wcslen(lpcTemp)+1] ;
wcscpy_s(symarkUserRef, wcslen(lpcTemp)+1, (lpcTemp));
}
void CUserContextData::DeleteUs erContextD ata()
{
delete [] shell;
delete [] homeDir;
delete [] primaryGroup;
delete [] symarkUserRef;
//if(LoginName != NULL)
delete [] LoginName;
delete [] contextName;
delete [] lpcwContextName;
}
CUserContextData& CUserContextData::operator =(const CUserContextData& newUserData)
{
if(this != &newUserData)
{
DeleteUserContextData();
Copier(newUserData);
}
return *this;
}
CUserContextData::CUserCon textData(v oid)
{
lpcwContextName = NULL;
contextName = NULL;
shell = NULL;
homeDir = NULL;
primaryGroup = NULL;
symarkUserRef = NULL;
LoginName = NULL;
listViewIndex = NULL;
UID = NULL;
symarkUID=NULL;
newObject = false; bWinLogOn = false; bUnifiedID = false; symarkEnabled = false; UIDChanged = false;
}
CUserContextData::CUserCon textData(c onst CUserContextData &newUserData)
{
Copier(newUserData);
}
~CUserContextData(void)
{
DeleteUserContextData();
}
};
I think it might be easier at this point for me to change the code and store bojects of my class in the vector, which means change the way I declare it and reference it. I'll try it tomorrow and see if it works. Also, do I need to change my class declaration, like the copy constructor or the operator=, descructor? Can you see if it might be cause by any one of them? I'm not sure about code that I wrote for those. Thanks.
class CUserContextData
{
public:
bool newObject, bWinLogOn, bUnifiedID, symarkEnabled, UIDChanged;
wchar_t *shell, *homeDir, *primaryGroup, *symarkUserRef, *LoginName, *contextName;
LPCWSTR lpcwContextName;
int symarkUID, listViewIndex, UID;
//std::wstring test;
void CUserContextData::Copier(c
{
const wchar_t *lpcTemp;
newObject = newUserData.newObject;
bWinLogOn = newUserData.bWinLogOn;
bUnifiedID = newUserData.bUnifiedID;
symarkEnabled = newUserData.symarkEnabled;
UIDChanged = newUserData.UIDChanged;
symarkUID = newUserData.symarkUID;
listViewIndex = newUserData.listViewIndex;
UID = newUserData.UID;
wchar_t *temp = new wchar_t[wcslen(newUserData
wcscpy_s(temp, wcslen(newUserData.lpcwCon
lpcwContextName = (LPCWSTR)temp;
lpcTemp = T2CW(newUserData.contextNa
contextName = new wchar_t[wcslen(newUserData
wcscpy_s(contextName, wcslen(newUserData.context
lpcTemp = T2CW(newUserData.LoginName
LoginName = new wchar_t[wcslen(newUserData
wcscpy_s(LoginName, wcslen(newUserData.LoginNa
lpcTemp = T2CW(newUserData.shell);
shell = new wchar_t[wcslen(lpcTemp)+1]
wcscpy_s(shell, wcslen(lpcTemp)+1, (lpcTemp));
lpcTemp = T2CW(newUserData.homeDir);
homeDir = new wchar_t[wcslen(lpcTemp)+1]
wcscpy_s(homeDir, wcslen(lpcTemp)+1, (lpcTemp));
lpcTemp = T2CW(newUserData.primaryGr
primaryGroup = new wchar_t[wcslen(lpcTemp)+1]
wcscpy_s(primaryGroup, wcslen(lpcTemp)+1, (lpcTemp));
lpcTemp = T2CW(newUserData.symarkUse
symarkUserRef = new wchar_t[wcslen(lpcTemp)+1]
wcscpy_s(symarkUserRef, wcslen(lpcTemp)+1, (lpcTemp));
}
void CUserContextData::DeleteUs
{
delete [] shell;
delete [] homeDir;
delete [] primaryGroup;
delete [] symarkUserRef;
//if(LoginName != NULL)
delete [] LoginName;
delete [] contextName;
delete [] lpcwContextName;
}
CUserContextData& CUserContextData::operator
{
if(this != &newUserData)
{
DeleteUserContextData();
Copier(newUserData);
}
return *this;
}
CUserContextData::CUserCon
{
lpcwContextName = NULL;
contextName = NULL;
shell = NULL;
homeDir = NULL;
primaryGroup = NULL;
symarkUserRef = NULL;
LoginName = NULL;
listViewIndex = NULL;
UID = NULL;
symarkUID=NULL;
newObject = false; bWinLogOn = false; bUnifiedID = false; symarkEnabled = false; UIDChanged = false;
}
CUserContextData::CUserCon
{
Copier(newUserData);
}
~CUserContextData(void)
{
DeleteUserContextData();
}
};
> Also, do I need to change my class declaration, like the copy constructor or the operator=, descructor?
They look fine to me, but I might overlook something.
But I think this is a bit strange:
> lpcTemp = T2CW(newUserData.contextNa me);
> contextName = new wchar_t[wcslen(newUserData .contextNa me)+1];
> wcscpy_s(contextName, wcslen(newUserData.context Name)+1, lpcTemp);
I don't see an error, but why not simply:
contextName = new wchar_t[wcslen(newUserData .contextNa me)+1];
wcscpy(contextName, newUserData.contextName);
or at least:
contextName = new wchar_t[wcslen(newUserData .contextNa me)+1];
wcscpy_s(contextName, wcslen(newUserData.context Name)+1, newUserData.contextName);
They look fine to me, but I might overlook something.
But I think this is a bit strange:
> lpcTemp = T2CW(newUserData.contextNa
> contextName = new wchar_t[wcslen(newUserData
> wcscpy_s(contextName, wcslen(newUserData.context
I don't see an error, but why not simply:
contextName = new wchar_t[wcslen(newUserData
wcscpy(contextName, newUserData.contextName);
or at least:
contextName = new wchar_t[wcslen(newUserData
wcscpy_s(contextName, wcslen(newUserData.context
btw,
> I have a COM DLL that I'm working on using VS2005
This is the c++builder TA. It would have been better if you asked this in the normal c++ TA;
https://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/
You would get more help there.
> I have a COM DLL that I'm working on using VS2005
This is the c++builder TA. It would have been better if you asked this in the normal c++ TA;
https://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/
You would get more help there.
ASKER
Thank you. I was thinkg about doing that.
BTW, I changed the code to store objects of my class but my program is staill crashing. Do you think it might be becase the objects have wchar_t*, pointer type for data fields?
vector <CUserContextData> userDataObjects;
vector <CUserContextData>::iterat or userDataIter;
Thanks.
BTW, I changed the code to store objects of my class but my program is staill crashing. Do you think it might be becase the objects have wchar_t*, pointer type for data fields?
vector <CUserContextData> userDataObjects;
vector <CUserContextData>::iterat
Thanks.
> Thank you. I was thinkg about doing that.
Just saw you already did so.
You can ask a moderator to delete this question (https://www.experts-exchange.com/help.jsp#hi71)
you can also ask there to unaccept the answer of chip3d in http:Q_21824169.html in case you selected the wrong comment.
Just saw you already did so.
You can ask a moderator to delete this question (https://www.experts-exchange.com/help.jsp#hi71)
you can also ask there to unaccept the answer of chip3d in http:Q_21824169.html in case you selected the wrong comment.
http://www.boost.org/libs/ptr_container/doc/ptr_vector.html
http://www.codeproject.com/vcpp/stl/ptr_vecto.asp
Or use a smart pointer like shared_ptr (http://www.boost.org/libs/smart_ptr/shared_ptr.htm).