All,
I've written my own wrapping function around 'SHFileOperation' to remove files or folders(depending on the param). The code look like this:
function BOOL RemoveFileFolder(FileFolder)
FILEOPSTRUCT foData;
LONG nFlags;
INT Result;
STRING Msg;
begin
nFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT;
if (((FolderExists(FileFolder)) ||
(FileExists(FileFolder))) &&
(StrRemoveLastSlash(FileFolder) == 0)) then
FileFolder = FileFolder + "||";
CharReplace(FileFolder, STRTOCHAR("|"), STRTOCHAR("\0"), 0);
foData.hwnd = NULL;
foData.nFunc = FO_DELETE;
foData.pFrom = &FileFolder;
foData.pTo = NULL;
foData.nFlags = nFlags;
foData.bAnyOperationsAborted = FALSE;
foData.pNameMappings = NULL;
foData.pProgressTitle = NULL;
try
Result = SHFileOperation(&foData);
if (Result == 0) then
return TRUE;
else
Sprintf(Msg, "RemoveFileFolder(): Failed removing \"%s\".\r\n%s", FileFolder, GetErrorTextFromCode(Result));
_RaiseFileError(Result, Msg);
endif;
catch
Sprintf(Msg, "RemoveFileFolder(): Failed removing \"%s\".", FileFolder);
_RaiseFileError(Result, Msg);
endcatch;
else
return FALSE;
endif;
end;
I'm using this function in the following sequence:
DeshareFolder(folder1);
RemoveFileFolder(folder1);
DeshareFolder(folder2);
RemoveFileFolder(folder2);
...
Desharing and removing of the folder1 works fine(without any notifications as the flags are defined).
Desharing of folder2 works also fine but the call to RemoveFileFolder(folder2) shows a message which states that the folder is still shared however this is not the case.
My meaning is that when I call the function the first time, it allocates some memory but doesn't free this up when exiting the function. So the next time the function is called, it shows this dialog.
Is there some way to free up all memory allocations before leaving the function. I found some C++ code using SHFileOperation and they are using
ZeroMemory(&foData, sizeof(foData));.
However, I don't think I can call this function within installscript.
PS: For desharing a folder, I make use of the NETAPI32 call 'NetShareDel'. This function is called straightforward without any parameter preparation before or cleanup action afterwards. Could it be that this call give problems when calling 2 times after each other.
The thing is, when I use the function DeleteDir, everything works fine but I have my reasons to not use this function.
Any information what to do?
Regards,
Christoph
This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
SHFileOperation
Started by
Christoph
, Jan 23 2007 16:22
2 replies to this topic
Posted 23 January 2007 - 17:37
QUOTE |
However, I don't think I can call this function within installscript. |
Why don't you create the custom action as DLL in C instead of using InstallScript in this case?
Stefan Krüger
InstallSite.org twitter facebook