|
I see the above as obvious memory leak in code. Also Sarath (in the reply below) pointed to the same problem. Try fixing the problem and then see if there is still memory leak.
You may also want to re-think about how m_name is deallocated when object lifetime ends.
modified 21-Apr-21 21:01pm.
|
|
|
|
|
The program will be having memory leak, if you call set twice. You can rewrite the code better.
class test
{
char* m_name;
public:
test():m_name(NULL)
{}
void Set(const char* name)
{
if( name == NULL || 0 == strlen(name))
return;
if( m_name )
delete []m_name;
m_name = new char[strlen(name)+1];
strcpy(m_name,name);
}
~test()
{
if( m_name )
delete [] m_name;
}
void display()
{
cout<<m_name<<endl;
}
};
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Thanks for your better code reply.
|
|
|
|
|
Hi All
I have a problem to copy .exe file.I am useing
GetLastError()
then found error no.32 and 3.
error No. 3 show
The system cannot find the path specified.
And Error no. 32 show
The process cannot access the file because it is being used by another process.
Code is
void On_FileAdded(const CString & strFileName)
{
USES_CONVERSION;
CString CStrfilename=strFileName;
char* charfilename;
charfilename=CStrfilename.GetBuffer();
LPCTSTR lp;
lp=CStrfilename;
PathSkipRoot(lp);
CString cs = "C:\\Backup\\";
cs += PathSkipRoot(lp);
CString st;
if ( CopyFile(strFileName, cs, TRUE) != TRUE)
{
DWORD dwError = GetLastError();
CString szMsg;
szMsg.Format("Error number %d", dwError);
AfxMessageBox(szMsg);
}
else
{
AfxMessageBox("Success");
}
CopyFile(strFileName, cs,TRUE);
}
Plz help me
|
|
|
|
|
vcprog wrote: if ( CopyFile(strFileName, cs, TRUE) != TRUE)
Did you check the contents of strFileName and cs when you use them in CopyFile.
vcprog wrote: else
{
AfxMessageBox("Success");
}
CopyFile(strFileName, cs,TRUE);
}
BTW why do you wan't to do CopyFile again?
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Thx's for reply
yes i check the contents of strFileName and cs both are right.
And when comment these line
CopyFile(strFileName, cs,TRUE);
then file is not not copy..
Plz help me
|
|
|
|
|
Did you try with SHFileOperation ?
|
|
|
|
|
No i have no idea about SHFileOperation..
Can you give me example..
Plz help me
|
|
|
|
|
ShFileOperation Demo[^]
The secret of life is not enjoyment
but education through experience.
- Swami Vivekananda.
|
|
|
|
|
Like this:
TCHAR m_Files[256];
sfo.wFunc = FO_COPY;
sfo.hwnd = NULL;
sfo.pFrom = m_Files;
sfo.pTo = "c:\\Pics";
sfo.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR;
hr = SHFileOperation(&sfo);
|
|
|
|
|
vcprog wrote: The process cannot access the file because it is being used by another process.
Which part of this error message do you not understand?
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
yes you are right i am not understand where is error showing?Can you help me?
|
|
|
|
|
The error means that this particular file is being exclusively locked by another process. So, until that process would release this lock, you will not be able to copy this file. You may try copying some other file to verify this.
See if this[^] helps.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Sir it's not help me..Plz tell me how can i solve that problem..
Plz help me
|
|
|
|
|
|
There is no point in all that, because the problem is that the OP is trying to copy a file which is being exclusively locked by another process.
The problem is not in choosing the method to copy a file, but with copying the file itself, as it is locked.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Yeah thats right I forgot what was problem!
|
|
|
|
|
Hi Can i send you code.How can i attached the code here plz tell me or give me mail Id i will send you code..Plz help me
|
|
|
|
|
There is no problem with your code. The problem is, that the file is locked for copying. You may try copying some other file and see if that works first, to confirm what I say.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Sir how can i solve that problem.I need some vital help from forum side..
|
|
|
|
|
|
Hi Rajesh R Subramanian
I ask to Mr. toxcct but i havn't got any reply from toxcct side.
|
|
|
|
|
What did I ask you to do and what have you done?
"Hello sir plz i need help" Is that a query? Help you with what? Did you explain him the problem? Did you tell that you are facing a similar situation and you need help with exactly "this X thing"? It would be impossible to help you.
That, you've just posted it 2 hours back and you write to me because he hasn't replied? If you don't have the manners and social skills, there is zero chance of getting any help from a community.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Before any thing to say plz check all things.
Plz see it..
<a href="http://www.codeproject.com/script/Forums/View.aspx?fid=1647&msg=2738614">http:
|
|
|
|
|
You see, you don't know how to ask a question. I did see that post, it. You've made it before a 4 odd hours. So what? You can't wait for a day at least?
Fair enough - your' answer is with process explorer, download it and find out which process is having a handle on the file that you want to copy, release the handles and try copying the file. I won't write any further in this regard.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|