x
This website is using cookies. We use cookies to ensure that we give you the best experience on our website. More info. That's Fine
HPC:Factor Logo 
 
Latest Forum Activity

Windows CE and the Recycle bin

[Frozen]
1 2
Frozen
Dexxta
Dexxta Page Icon Posted 2005-08-09 8:31 AM
#
Status:
Well I have found some undocumented things before, but damn if I can find anything on this one. The best I can get is a post that says "Pocket PC's dont have a recycle bin so use DeleteFile()"

Im coding in eVC3, win api only, not MFC. Its for HPC Pro, windows CE 2.11

Im trying to send a file to the recycle bin when its deleted, I know DeleteFile wont send to the recycle bin so Im using SHFileOperation() and its deleting the file but still no go with the bin.

Anyone done this before? This is what I got so far...

SHFILEOPSTRUCT shf; shf.hwnd = g_hWnd; shf.wFunc = FO_DELETE; shf.fFlags = FOF_ALLOWUNDO; shf.pFrom = (LPCWSTR) szFileName; shf.pTo = NULL; if( SHFileOperation(&shf) != 0) ErrorHandler();


Error handler isnt triggered so Im getting a success. And Im testing it on a doc file in my documents that does get deleted.

Any help would be greatly appreciated

 Top of the page
skyfox01_99 Page Icon Posted 2005-08-09 8:55 AM
#
Avatar image of skyfox01_99
Factorite (Senior)

Posts:
80
Location:
UK
Status:
Is szFileName just the file name or is it the full path? If it's just the file name it won't be moved to the recycle bin, even if FOF_ALLOWUNDO is set.
 Top of the page
Snappy! Page Icon Posted 2005-08-09 10:28 AM
#
Avatar image of Snappy!
H/PC Elder

Posts:
1,712
Location:
New Mexico, US
Status:
First off ... I'm not entirely sure if "SHFileOperation" is supported in CE3.0 or even CE2.11. I could not find it in the SDK documentation for HPCPro.

MSDN

From the MSDN, I've found SHFileOperation under CE.NET 4.2, 5.0 and Win9x, NT etc, but not under CE2.11 ...

can you point me to the sdk doc that documents SHFileOperation?


Quote

This function can be used to copy, move, rename, or delete a file system object.

int SHFileOperation(
LPSHFILEOPSTRUCT lpFileOp
);

Parameters

lpFileOp
[in] Address of an SHFILEOPSTRUCT structure that contains information this function needs to carry out the specified operation.

Return Values

Returns zero if successful, or nonzero otherwise.
Remarks

You should use fully qualified path names with this function. Using it with relative path names is not thread-safe.

When used to delete a file, SHFileOperation attempts to place the deleted file in the Recycle Bin. If you wish to delete a file and guarantee that it is not placed in the Recycle Bin, use DeleteFile.
Requirements

OS Versions: Windows CE .NET 4.2 and later.
Header: Shellapi.h.
Link Library: Ceshell.lib.


Further, from the above snippet, MSDN states that "If you wish to delete a file and guarantee that it is not placed in the Recycle Bin, use DeleteFile." so I am not sure how things are working out here.

Can you confirm if ""DeleteFile" will send the file to recycle bin and "SHFileOperation" is available to ce2.11?

From my experience, DeleteFile is pretty middle level IO and it does not support the "delete to recycle bin and restore" functionality in the recycle bin.

I'll write a little app to test out. Will post in awhile.



(recycle1.JPG)



(recycle2.JPG)



Attachments
----------------
Attachments recycle.zip (44KB - 37 downloads)
Attachments recycle1.JPG (35KB - 36 downloads)
Attachments recycle2.JPG (42KB - 28 downloads)
 Top of the page
Dexxta
Dexxta Page Icon Posted 2005-08-09 5:45 PM
#
Status:
szFileName is the path and file name. Its been memset to nulls before the filename and path get put in, so there should be more than 1 null after the end of the filename satisfying the need to have a double null to terminate.

I did notice that when run in the debugger, SHFileOperation throws a first chance exeption of an access violation. But Im yet to work out what its violating. And it still deletes the file.

DeleteFile will never move to recycle bin as far as I know.

SHFileOperation isnt documented but is in the shellapi.h and another file I cant remember *I just woke up need coffee*, if you look in shellapi it says some more stuff.

While laying in bed last night I thought of a possible dodgy way to do it, but I would rather do it in code the right way if I can. I have never used SHFileOperation before on one of these devices and have never used the recycle bin for that matter.

I guess its going to be something that only the shell knows how to do in the end, so I could possibly just ask the shell to do it for me......

OH and MSDN no longer has the documentation for 2.11, although I did notice that its not documented till 4.1, its half working, and there has to be some way to use the recycle bin, after all its there and exporer uses it.

Edited by Dexxta 2005-08-09 5:52 PM
 Top of the page
Dexxta
Dexxta Page Icon Posted 2005-08-10 4:11 PM
#
Status:
After several days of searching and a lot of testing, I have not been successful at puting a file into the recycle bin. I have sent several emails to people, like the guy that wrote the windows ce programming book, but I doubt anyone will have an answer.

I think Ill move on and just use DeleteFile() which is a shame realy. The recycle bin is a part of the system and should be usable. Maybe Ill come back to it later.
 Top of the page
Snappy! Page Icon Posted 2005-08-10 10:39 PM
#
Avatar image of Snappy!
H/PC Elder

Posts:
1,712
Location:
New Mexico, US
Status:
Dexxta, this is so embarrassing! I mistaken your first post to mean the reverse! OOoops ....

I'll see what I find and let you know.
 Top of the page
Dexxta
Dexxta Page Icon Posted 2005-08-11 4:58 AM
#
Status:
HEHE no worries, when I read your post I wondered for a bit, but thought I had just not understood and went back to look at something to do with DeleteFile(). After that I just kept looking.

It would be cool if someone could find something, as yet I still cant get SHFileOperation not to error, and nothing goes to the recycle bin.

Thanks

Im thinking that there has to be a format, structure, or something that would mean I can move the files there myself as long as the correct data is put into place. Im thinkin about looking into the offsets and things to do that, but hey that seems like too much work. I have moved things to the recycle bin just to see what would happen, it ends up with no name, and no deleted from path, and is unrestoreable ( <- lol ) perhaps if those things were filled in it would work.

its a thought anyway.
 Top of the page
C:Amie Page Icon Posted 2005-08-11 6:50 AM
#
Avatar image of C:Amie
Administrator
H/PC Oracle

Posts:
18,007
Location:
United Kingdom
Status:
Guys,

this is a hunch here, but I think that since you are dealing with a shell folder, and not any form of actual intellect, that you simply have to move the file you're deleting into the recycle bin with CE, rather than actually sending a delete command to the file system or object store driver.

You can call the path's up by using:
SHGetSpecialFolderPath
 Top of the page
Dexxta
Dexxta Page Icon Posted 2005-08-11 7:01 AM
#
Status:
I went so far as to LocalAlloc the SHFILEOPERATION structure, as well as the string ptFrom.

Still no luck.

Its causing an exception error, Access Violation, but I cant read the dissasembly.
19FABD9C ldr r3, [r0, #4]!
is the line it errors on, but I doubt that means much to anyone.

I also get an error in the debug window:
Data Abort: Thread=88d619a8 Proc=8807ecd4 'Dexxplorer.exe'
AKY=00000801 PC=01fabd9c RA=01fabd98 BVA=00000014

Dont know if that will help either though.

I could try to do a GetProcAddress, see if that one works any better, but Im thinkin now that Im rowing upstream in that smelly river, you know the one.

Anyone, thanks for any help anyone can offer.

EDIT: In reply to just moving it to the recycle bin path, that left the file unnamed and unrestorable. I still cannot believe there isnt a simple function DeleteToRecycleBin() Wishfull thinking I guess.

Edited by Dexxta 2005-08-11 7:15 AM
 Top of the page
Dexxta
Dexxta Page Icon Posted 2005-08-19 5:45 AM
#
Status:
After a few days break cause this was annoying me, I went back to it today. I did a LoadLibrary() on ceshell.dll and a GetProcAddress() for SHFileOperationW and got the function fine. I was actualy thinking that might fail, but it didnt. Then I filled out the structure like before in the first post, and got the same error. I dont know where the access violation is coming from, and I realy dont know enough about debugging and assembly to be able to make sence out of any output.

So thats where I am at, I would realy like to get this working if anyone has any ideas. Once this works, if it ever does, then Ill be able to cut copy paste, and delete properly. Then I can upload it for everyone to play with.
 Top of the page
Snappy! Page Icon Posted 2005-08-19 9:07 AM
#
Avatar image of Snappy!
H/PC Elder

Posts:
1,712
Location:
New Mexico, US
Status:
Hi Dexxta,

I just retried my recycle app and it works deleting the file with "SHFileOperation" function ... It currently deletes the file ... BUT does not appear in recycle bin, so just to keep your motivation there ...

I'm attaching the project file inside. Note that you need to include ceshell.lib into the link options under project settings.

I'll post an update if I get it into the recycle bin, or you may tinker with the attached project and see if you can move from there ...

Quote

void CRecycleDlg:nDelete()
{
CString sRecycledFileName = m_szRecycleBin;

sRecycledFileName += "\\newfile.txt";

SHFILEOPSTRUCT FileOp;
FILEOP_FLAGS flag = FOF_ALLOWUNDO;

memset(&FileOp, 0, sizeof(SHFILEOPSTRUCT));

FileOp.hwnd = m_hWnd;
FileOp.wFunc = FO_DELETE;
FileOp.pFrom = L"\\newfile.txt";
FileOp.pTo = NULL;
FileOp.fFlags = flag;
FileOp.fAnyOperationsAborted = false;
FileOp.hNameMappings = NULL;
FileOp.lpszProgressTitle = NULL; // only used if FOF_SIMPLEPROGRESS


if (SHFileOperation(&FileOp) == 0)
{
MessageBox(L"\"\\newfile.txt\" recycled";
}
else
{
MessageBox(L"\"\\newfile.txt\" recycling failed!";
}


/*
if (DeleteFile(L"\\newfile.txt")
{
MessageBox(L"\"\\newfile.txt\" deleted";
}
else
{
MessageBox(L"\"\\newfile.txt\" deletion failed!";
}
*/
}




Attachments
----------------
Attachments recycle.zip (46KB - 28 downloads)
 Top of the page
Dexxta
Dexxta Page Icon Posted 2005-08-19 9:43 AM
#
Status:
Did you get an exception when you debug it? Its basicly what I have and gets the same result. Thanks for looking into it though.

I have passed my dissassembly code, C++ code, and registers to someone who can read that sort of thing, if they cannot come up with something then I think that I will have to change my direction with it.

The strange thing is that it will move and copy files without a problem. Rather frustrating.

 Top of the page
Dexxta
Dexxta Page Icon Posted 2005-08-20 8:19 PM
#
Status:
Ok its come down to this, cause Im realy persistant and wont give up easy.

If there is anyone out there with platform builder (you know at work or something) and can debug explorer.exe to tell me what API calls are made when a file is deleted and sent to the recycle bin it may be possible to crack this once and for all.

Im hesitant to download something I havent paid for, but if someone say uses it at work or has a deptment at work that has platform builder, then from what I have read it may be possible.

Other than that, Im truly dissapointed that MS didnt include a way to make use of the recycle bin seeing as its a big part of windows.

Thanks
 Top of the page
Dexxta
Dexxta Page Icon Posted 2005-08-20 9:39 PM
#
Status:
Just for the info of anyone interested, I have found that its possible to debug the emulator and apps running in it. That may be well known anyway. I dont know how to work the debugger well enough yet but SHFileOperation fails on
COREDLL!PegReadRecordProps+0x6e53:
which is still pointing to my theory that its got something to do with writing the extra file info the recycle bin needs EG: Original file name, time of delete, etc..
Although this function should do that itself, there may be some other function call needed in there, or it may be possible to go around the SHFileOperation, and replicate it with the right calls.

Either way, this is beyond my knowlege for now I think.
 Top of the page
C:Amie Page Icon Posted 2005-08-21 7:08 AM
#
Avatar image of C:Amie
Administrator
H/PC Oracle

Posts:
18,007
Location:
United Kingdom
Status:
Dexxta, are you trying to delete a system database here?
 Top of the page
1 2
Frozen
Jump to forum:
Seconds to generate: 0.203 - Cached queries : 63 - Executed queries : 11