Drag and drop files from CD / DVD error

Nov 17, 2008 at 3:22 PM
Hi,

Dragging and dropping files from a DVD / CD drive with certain extentsions such as

*.jpg
*.tif
*.rrd
*.dbf
*.shp
*.sbx
*.jpgw
*.pdf
*.xml

causes an error

Title: Membe Velodoc Package Editor
Message: Win32 handle that was passed to Icon is not valid or is the wrong type.

But if i copy the files to that hard drive and try the exact same operation it does not cause the error
Nov 20, 2008 at 8:48 AM
Edited Nov 20, 2008 at 9:06 AM
I have a CD full of JPG files and could not reproduce the problem whether I drag and drop 1 item or 100 items into the package editor both on XP + Office 2003 and Vista + Office 2007. Unfortunately, I do not have a CD which mixes all the file types you are listing.

So I have searched for the error on the web and found what looks like a relevant post at http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/2bc19f67-673f-4fa3-82d1-0c069f1dcf1d/. According to this post,
I have used the code published at http://support.microsoft.com/kb/319350 to try and reproduce the error but without success.

I have considered the fact that both in your case and in the post above, there are many different types of files so I have tried to drag and drop the entire C:\WINDOWS directory structure but after some time I have hit a ContextSwitchDeadlock which is not surprising considering teh windows directory and its subdirectory contains thousands of files. Note though that hundreds of files have been loaded into the package editor before getting this error.

I am afraid I have exhausted all possibilities to reproduce the defect you are reporting.
Nov 20, 2008 at 10:15 AM
After several tests and looking at the code, there is no obvious reason why the issue you have experienced would be caused by the CD/DVD being the source of files to include in a package.

After enquiring further, SHGetFileInfo seems to have a limit on the number of CGI+ icon handles it can have open. After a certain number (around 3000 in one of my tests), it just returns an invalid handle of 0, without indicating failure. Could this be the cause of the issue you have reported?

I have fixed the ContextSwitchDeadlock mentioned above by pumping messages in the AddFile method and I have modified the code in ShellIconHelper.cs in order to destroy properly icon handlers after using them. I can now drag and drop the entire C\WINDOWS directory structure with tens of thousands of files into the packaged editor, so I hope this will solve this issue.

public static Icon GetShellIcon(string fileName)
{
    SHFILEINFO objShellInfo = new SHFILEINFO();
    IntPtr handle = Win32.SHGetFileInfo(fileName, 0, ref objShellInfo, (uint)Marshal.SizeOf(objShellInfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON | Win32.SHGFI_USEFILEATTRIBUTES);
    Icon objIconRet = (Icon)Icon.FromHandle(objShellInfo.hIcon).Clone();
    Win32.DestroyIcon(objShellInfo.hIcon); //<--- NEW!
    return objIconRet;
}

This will be included in the next build.
Nov 20, 2008 at 9:56 PM
Thanks, any idea when the next build will be?
Nov 21, 2008 at 11:24 AM
Certainly before the end of the year, maybe before. We have made a major change in the design to solve the issue described at http://www.codeplex.com/velodocaddin/WorkItem/View.aspx?WorkItemId=1397 and this requires a bit of testing before we can consider publishing.