Discussion:
Structured Storage and Property Sets Wierd Problem with image file types
(too old to reply)
Adam E
19 years ago
Permalink
ok.. lets assume that the pbc is null..
why then would i be getting :

System.AccessViolationException when i call the BindToStorage (or even
BindToObject). The the COMPlusExceptionCode is -532459699


thanks,
adam
...
Jim Barry
19 years ago
Permalink
Post by Adam E
ok.. lets assume that the pbc is null..
System.AccessViolationException when i call the BindToStorage (or
even BindToObject). The the COMPlusExceptionCode is -532459699
I would have to guess that there is something bad about the ID-list you are passing in. Maybe you could post some code to show what you are doing.
--
Jim Barry, MVP (Windows SDK)
Adam E
19 years ago
Permalink
ok here's the code that i've written (its not the complete class file), i'm also using the library from the 'C# does shell' series of article library that is posted on codeproject.com for some of the shell interop. I've included the main code i've written and associated methods from the ShellApi Libary (from the article). please have a look at where i call BindtoStorage (highlighted in red), and walk backwards.. everything seems to OK up until that point, ie i can see S_OK being returned, and i've tested that the values of structures are what i'm expecting etc
any help here is greatly appreciated
thanks,
Adam


#####Begin Code #########

string fullName; //this is the full pathname of the file eg 'c:\docdrop\test.doc'

/// <summary>

/// This is meant to reuturn the correct storage interface pointer for a file

/// </summary>

PropertySetStorage GetPropertySetStorage()

{

ShellLib.IMalloc pMalloc = null;

pMalloc = ShellFunctions.GetMalloc();

ShellLib.IShellFolder shellFolder = null;


System.Text.StringBuilder path = new System.Text.StringBuilder(256);

Guid IID_IShellFolder = new Guid("{000214E6-0000-0000-C000-000000000046}");

Guid IID_IPropertySetStorage = new Guid("0000000B-0000-0000-C000-000000000046");


IntPtr pFile =IntPtr.Zero ; //pointer to PIDL

IntPtr fullPpidl = IntPtr.Zero;

IntPtr ppvOut =IntPtr.Zero;

IntPtr ptrParent;

IntPtr pidlRelative = IntPtr.Zero;

int hr;



GetDisplayName(this.fullName,ref pFile ); //this works



ShellApi.SHGetPathFromIDList(pFile,path);// this works

Debug.WriteLineIf(path.ToString() != this.fullName,path.ToString());

hr = ShellApi.SHBindToParent(pFile, IID_IShellFolder, out ptrParent, ref pidlRelative); //this works

if (hr == 0)

shellFolder = ShellFunctions.GetShellFolder(ptrParent); //this works

else

throw new COMException("COM Error:", hr);




//the following 4 lines are for testing and debugging to make sure everything is working ok:

ShellApi.STRRET ptrString;

System.Text.StringBuilder strDisplay = new System.Text.StringBuilder(256);

int h = shellFolder.GetDisplayNameOf(pidlRelative, (uint)ShellApi.SHGNO.SHGDN_NORMAL, out ptrString); //this works and i can see the values are ok

int retVal = ShellLib.ShellApi.StrRetToBuf(ref ptrString, pFile, strDisplay, (uint)strDisplay.Capacity); //this works too and the filenames are the same







IntPtr itemIDList = GetITEMIDLIST(shellFolder, strDisplay.ToString()); //THIS WORKS OK AND RETURN SEEMINGLY VALID POINTER

ulong flag;



PropertySetStorage propSetStorage = null;

try

{

IntPtr nullPtr = IntPtr.Zero;

//HERES WHERE IT BREAKS:

hr = shellFolder.BindToStorage(pidlRelative, nullPtr, IID_IPropertySetStorage, out ppvOut);

if (hr == 0) //S_OK

{

if (ppvOut != null) // check that a real interface pointer was returned

{

Object obj1 = Marshal.GetTypedObjectForIUnknown(ppvOut, typeof(PropertySetStorage));

propSetStorage = (PropertySetStorage)obj1;

}

}

}

catch (System.AccessViolationException ex)

{

throw ex; //this is thrown all the time, with COMPlusExceptionCode is -532459699


}

//Free Up Resources

if (pFile != IntPtr.Zero)

pMalloc.Free(pFile);


Marshal.ReleaseComObject(pMalloc);

return propSetStorage;

}



IntPtr GetITEMIDLIST(IShellFolder shellFolder,string strDisplay)

{

IntPtr attribute = IntPtr.Zero;

IntPtr itemIdList = IntPtr.Zero;

IntPtr dummy = IntPtr.Zero;

uint dummy2 =0;

int h = shellFolder.ParseDisplayName(IntPtr.Zero, IntPtr.Zero, strDisplay, ref dummy2, out itemIdList, ref dummy2);

return itemIdList;

}



void GetDisplayName(string sPath,ref IntPtr pidlRoot)

{

ShellLib.IMalloc pMalloc;

pMalloc = ShellLib.ShellFunctions.GetMalloc();

// IntPtr pidlRoot;


uint iAttribute;

ShellLib.ShellApi.SHParseDisplayName(sPath, IntPtr.Zero, out pidlRoot, 0,

out iAttribute);

// if (pidlRoot != IntPtr.Zero)

// pMalloc.Free(pidlRoot);

System.Runtime.InteropServices.Marshal.ReleaseComObject(pMalloc);

// return pidlRoot;

}

// this comes from the ShellAPI library:

public static IMalloc GetMalloc()

{

IntPtr ptrRet;

ShellApi.SHGetMalloc(out ptrRet);


Object obj = Marshal.GetTypedObjectForIUnknown(ptrRet,GetMallocType());

IMalloc imalloc = (IMalloc)obj;


return imalloc;

}

public static IShellFolder GetShellFolder(IntPtr ptrShellFolder)

{

System.Type shellFolderType = GetShellFolderType();

Object obj = Marshal.GetTypedObjectForIUnknown(ptrShellFolder,shellFolderType);

IShellFolder RetVal = (IShellFolder)obj;

return RetVal;

}

// This is the declaration for the ISHellfolder.BindToStorage:



[PreserveSig]

Int32 BindToStorage( IntPtr pidl, IntPtr pbc, Guid riid, out IntPtr ppv);

####End Code ###########
Post by Adam E
ok.. lets assume that the pbc is null..
System.AccessViolationException when i call the BindToStorage (or
even BindToObject). The the COMPlusExceptionCode is -532459699
I would have to guess that there is something bad about the ID-list you are passing in. Maybe you could post some code to show what you are doing.
--
Jim Barry, MVP (Windows SDK)
Loading...