SHCreateItemFromParsingName and System.AccessViolationException
See the question and my original answer on StackOverflowThe problem comes from the REFIID type parameter. It's not a GUID (a 16 bytes struct), but a GUID reference (REFIID), a pointer (so 4 or 8 bytes depending on process bitness).
So you could define the method like this, with a ref
keyword (so the struct would be passed by reference, as a pointer):
internal static extern uint SHCreateItemFromParsingName(
[MarshalAs(UnmanagedType.LPWStr)] string pszPath,
IBindCtx pbc,
ref Guid riid,
out IShellItem ppv);
But I recommend this way which is easier to use and avoids creating/copying GUIDs all around (you will call it the same way as you do):
internal static extern uint SHCreateItemFromParsingName(
[MarshalAs(UnmanagedType.LPWStr)] string pszPath,
IBindCtx pbc,
[MarshalAs(UnmanagedType.LPStruct)] Guid riid,
out IShellItem ppv);