void TakeData(myStruct &structRef)
CString str = TmpFileMgr->TmpFilePathName() ; //Returns file path
structRef.cstrFilePath = str ; //Crashes at this point on Windows 7
in a dll which takes Temporary folder path and assign it in a CString variables. This CString variable is member of structure object which is passed as a reference to TakeData(myStruct &structRef)function.
I am able to print temporary folder path in TakeData function and CString assigment works perfectly on Windows XP. But when I run this code on Windows 7 it crashes at the point where I am doing assigment of temp folder path in a CString variable. I have all admin rights on Windows 7 System , also I have put UAC to OFF.
You have supplied very little to go on, so in addition to suggesting you provide more information I'll ask a question: are you allocating memory in one module and freeing it in another (a module is a dll or exe)?
I am sorry for adding incomplete info.
I have allocated memory to object of structure myStruct in one dll and passed this struct object as a reference to another dll. This crash happens only while assinging value to
variable. Finally I was able to assign value inside CString variable using
method. I was able to resolve this crash with following code , but I am sure this is not the correct way to do it.
Unless you configure things properly each module (dll or exe or other executable module) has it's own heap. In this environment you can't allocate memory in one module and free it another. Given that CString manages a buffer using an instance in multiple modules could result in this happening. Forget wcscpy, it's ugly and isn't a fix for the root problem, whatever it is. If it's heap corruption, which is my guess, it's going to blow up sooner or later and "fixing" one problem with an ugly hack will just result in it popping up somewhere else.
Finally I have solved this issue.
The CString when used with GCC was Used as LinuxCString which is internally std::string. Capacity of std::string when calculated was every time 0. so when I tried to assign const char* to LinuxCString ( i.e. CString in MSVC ) it was crashing.
I have used std::string.reserve (200) method to specify the capacity first while initialization. This solves my issue.
I am still evaluating whether my fix is perfect or not.