🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages Started by Konstantin Polyakov Sun, 06 Apr 2003 18:01
Remove multiple files to Recycle Bin
#17370
Author: Konstantin Polyakov
Date: Sun, 06 Apr 2003 18:01
43 lines
1983 bytes
Hello, All!

Please help me to correct the function of removing multiple
files to Recycle Bin. I've made the following:

void TForm1::SendToRecycleBinMulti(TStringList *m1)
{
if (m1->Count == 0) return;
int bfsize = 1;
for(int i=0; i<m1->Count; i++)
 {
  bfsize+=m1->Strings[i].Length()+1;
 }
SHFILEOPSTRUCT SHF;
SHF.hwnd=Application->Handle;
SHF.wFunc=FO_DELETE;
char *n1 = new char[bfsize];
strcpy(n1, m1->Strings[0].c_str());
char* tmp= &n1[strlen(n1)+1];
 for(int i=1; i<m1->Count; i++)
 {
    strcpy(tmp,m1->Strings[i].c_str());
    tmp+=strlen(tmp)+1;
 }
*tmp='\0';
SHF.fFlags=FOF_ALLOWUNDO|FOF_NOCONFIRMATION;
SHF.pFrom=n1;
if (SHFileOperation(&SHF)!=0) ShowMessage ("Error");
delete []n1;
}

It works but when I trying to put in to the big project, it causes "Access

violation in kernel.dll...". Why ? Please tell me what wrong with this code.



Thanks.




With best regards, Konstantin Polyakov.  E-mail: support@chemtable.com
Re: Remove multiple files to Recycle Bin
#17125
Author: Rudy Velthuis (TeamB)
Date: Sun, 06 Apr 2003 19:28
25 lines
1585 bytes
In <3e906b66@newsgroups.borland.com>, Konstantin Polyakov wrote:

> It works but when I trying to put in to the big project, it causes
> "Access violation in kernel.dll...". Why ? Please tell me what wrong 
> with this code.

If it works outside the big project, there must be something else, in the
big project, that causes the problems.

You can also use:

  AnsiString s;
  for (int i = 0; i < m1->Count; ++i)
      s += m1->Strings[i] + '\0';
  s += '\0';

  SHF.pFrom = s.c_str();
  if (SHFileOperation(&SHF) != 0) 
      ShowMessage ("Error");


-- 
Rudy Velthuis (TeamB)

Posted with XanaNews 1.14.3.3
Re: Remove multiple files to Recycle Bin
#17165
Author: Rodolfo Frino::Stargate Software
Date: Tue, 08 Apr 2003 10:27
42 lines
2107 bytes
I use this function:

void Delete_AllFiles(TForm* pForm, char* s)
{
    char Buffer[MAX_PATH];

    // Create an object of the class SHFILEOPSTRUCT.
    SHFILEOPSTRUCT oFile;

    memset(Buffer, 0, sizeof(Buffer));       //Init Buffer to 0
    memset(&oFile, 0, sizeof(oFile));        //Set Structure to 0

    // Make the application (Form1) to be the Owner of the
    // Progress Dialog Box that is displayed while
    // the delete operation takes place
    oFile.hwnd = pForm->Handle;

    //Set the Operation to be performed
    oFile.wFunc = FO_DELETE;

    //Set the directory you want to delete
    strcpy(Buffer, s);
    oFile.pFrom  = Buffer;
    oFile.fFlags = FOF_ALLOWUNDO;

    SHFileOperation(&oFile);
}
//----------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    //Examples
    //Delete_AllFiles(Form1, "c:\\__TEST\\*.*");

    Delete_AllFiles(Form1, Edit1->Text.c_str());
}

Rodolfo

"Konstantin Polyakov" <support@chemtable.com> wrote in message
news:3e906b66@newsgroups.borland.com...
> Hello, All!
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads