I have experienced much grief trying to figure out what to do about this error.
I have a project that make exstencive use of the Shell. And while working with this shell project in a stand alone project it is perfect.. Works like a champ.. Now when i get ready to intergrate the shell project into my main project i start getting weird jit errors and memory not accessable errors.. My other controls in the main form even start throwing errors when this shell project is added...
The only thing that i can think of is that there is a memory location is being overwritten while the address is in use by some other pointer.
Here is one of the main spots in my code that this is a for sure error thrower when the _ItemActivate even event is raised when an listitem is doubleClicked in the listView..
Here is the code
Orgin of error ---------------------
if (contextMenu.Handle != null)
Marshal.FreeCoTaskMem(contextMenu.Handle);
------------------------------------------------------
-----I know this is a lot of code ; however , i am hoping that someone can look and at least tell me what to look for because i have been on this puppy all weekend and have posted this into two other forms with no luck..
void FileView_ItemActivate(object sender, EventArgs e)
{
TreeNode parent = br.FolderView.SelectedNode;
if (parent != null && br.FileView.ArrayList_SelectedOrder.Count > 0)
{
ListViewItem listViewItem = (ListViewItem)br.FileView.ArrayList_SelectedOrder[0];
ShellItem shellItem = (ShellItem)listViewItem.Tag;
int startIndex = 0;
if ((Control.ModifierKeys & Keys.Alt) == 0)
{
if (shellItem.IsFolder)
{
if (!parent.IsExpanded)
parent.Expand();
br.FolderView.SelectedNode = parent.Nodes[listViewItem.Text];
startIndex = 1;
}
if (br.FileView.ArrayList_SelectedOrder.Count - startIndex > 0)
{
#region
Fields
IntPtr[] pidls = new IntPtr[br.FileView.ArrayList_SelectedOrder.Count - startIndex];
for (int i = startIndex; i < pidls.Length; i++)
{
pidls[i - startIndex] = ((
ShellItem)((ListViewItem)br.FileView.ArrayList_SelectedOrder
).Tag).PIDLRel.Ptr;
}
IntPtr icontextMenuPtr = IntPtr.Zero, context2Ptr = IntPtr.Zero, context3Ptr = IntPtr.Zero;
ContextMenu contextMenu = new ContextMenu();
ShellItem parentShellItem = (ShellItem)parent.Tag;
IShellFolder parentShellFolder = parentShellItem.ShellFolder;
#endregion
#region
Show / Invoke
try
{
if (ContextMenuHelper.GetIContextMenu(parentShellFolder, pidls, out icontextMenuPtr, out iContextMenu))
{
iContextMenu.QueryContextMenu(
contextMenu.Handle,
0,
ShellAPI.CMD_FIRST,
ShellAPI.CMD_LAST,
ShellAPI.CMF.DEFAULTONLY);
int defaultCommand = ShellAPI.GetMenuDefaultItem(contextMenu.Handle, false, 0);
if (defaultCommand >= ShellAPI.CMD_FIRST)
{
ContextMenuHelper.InvokeCommand(
iContextMenu,
(
uint)defaultCommand - ShellAPI.CMD_FIRST,
ShellItem.GetRealPath(parentShellItem),
Control.MousePosition);
}
}
}
#endregion
catch (Exception) { }
#region
Finally
finally
{
if (iContextMenu != null)
{
Marshal.ReleaseComObject(iContextMenu);
iContextMenu =
null;
}
if (contextMenu.Handle != null)
Marshal.FreeCoTaskMem(contextMenu.Handle);
Marshal.Release(icontextMenuPtr);
}
#endregion
}
}
else
{
IntPtr[] pidls = new IntPtr[br.FileView.ArrayList_SelectedOrder.Count - startIndex];
for (int i = startIndex; i < pidls.Length; i++)
{
pidls[i - startIndex] = ((
ShellItem)((ListViewItem)br.FileView.ArrayList_SelectedOrder
).Tag).PIDLRel.Ptr;
}
ContextMenuHelper.InvokeCommand(shellItem.ParentItem, pidls, "properties", Control.MousePosition);
}
}
}
************** Exception Text **************
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ListView.WndProc(Message& m)
at BrowserComponets.BrowserListView.WndProc(Message& m) in G:\Documents and Settings\Erik\My Documents\Visual Studio 2005\Projects\SuperDesktop\SuperIE\BrowserComponets\Controls\BrowserListView.cs:line 132
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
thanks a lot for any help..