Implementing IPersistStream?
-
I'm writing an MMC snapin using C#. So far I've got most things working and I've moved onto persistance. I need to implement the IPersistStream interface. I've defined the IPersistStream, IPersist and IStream interface in my C# code plus all the structure etc required as parameters. However when MMC or my C++ test harness calls the GetSizeMax method which has an out parameter of type ULARGE_INTEGER (which is a structure wrapping a ulong) I get an access violation. Am I doing anything wrong? I'm quite experienced with COM and C++ but marshalling between managed and unmanaged code is all quite new to me. Can anyone help?
-
I'm writing an MMC snapin using C#. So far I've got most things working and I've moved onto persistance. I need to implement the IPersistStream interface. I've defined the IPersistStream, IPersist and IStream interface in my C# code plus all the structure etc required as parameters. However when MMC or my C++ test harness calls the GetSizeMax method which has an out parameter of type ULARGE_INTEGER (which is a structure wrapping a ulong) I get an access violation. Am I doing anything wrong? I'm quite experienced with COM and C++ but marshalling between managed and unmanaged code is all quite new to me. Can anyone help?
solidstore wrote: ULARGE_INTEGER (which is a structure wrapping a ulong) I get an access violation. ulong is 4 bytes AFAIK. so use a UInt32 :) Dont get confused with C's long type. Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
-
solidstore wrote: ULARGE_INTEGER (which is a structure wrapping a ulong) I get an access violation. ulong is 4 bytes AFAIK. so use a UInt32 :) Dont get confused with C's long type. Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
Please find below my definitions. When stepping into some of these interfaces from C++ client the code either works, crashes or steps into the wrong functions. Any ideas?
[ StructLayout(LayoutKind.Sequential) ] public struct _GUID { public uint x; public ushort s1; public ushort s2; [MarshalAs(UnmanagedType.ByValArray, SizeConst=8)] public byte[] c; } [ StructLayout(LayoutKind.Sequential) ] public struct _FILETIME { public uint dwLowDateTime; public uint dwHighDateTime; } [ StructLayout(LayoutKind.Sequential) ] public struct tagSTATSTG { [MarshalAs(UnmanagedType.LPWStr)] public string pwcsName; public uint type; public _ULARGE_INTEGER cbSize; public _FILETIME mtime; public _FILETIME ctime; public _FILETIME atime; public uint grfMode; public uint grfLocksSupported; public _GUID clsid; public uint grfStateBits; public uint reserved; } [ InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("0c733a30-2a1c-11ce-ade5-00aa0044773d") ] public interface ISequentialStream { void Read(out byte pv, uint cb, out uint pcbRead); void Write(out byte pv, uint cb, out uint pcbWritten); } [ InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("0000000C-0000-0000-C000-000000000046") ] public interface IStream : ISequentialStream { void Seek(_LARGE_INTEGER dlibMove, uint dwOrigin, out _ULARGE_INTEGER plibNewPosition); void SetSize(_ULARGE_INTEGER libNewSize); void CopyTo(IStream pstm, _ULARGE_INTEGER cb, out _ULARGE_INTEGER pcbRead, out _ULARGE_INTEGER pcbWritten); void Commit(uint grfCommitFlags); void Revert(); void LockRegion(_ULARGE_INTEGER libOffset, _ULARGE_INTEGER cb, uint dwLockType); void UnlockRegion(_ULARGE_INTEGER libOffset, _ULARGE_INTEGER cb, uint dwLockType); void Stat(out tagSTATSTG pstatstg, uint grfStatFlag); void Clone(out IStream ppstm); } [ InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("0000010C-0000-0000-C000-000000000046") ] public interface IPersist { void GetClassID(out _GUID a); } [ StructLayout(LayoutKind.Sequential) ] public struct _ULARGE_INTEGER { public ulong QuadPart; } [ StructLayout(LayoutKind.Sequential) ] public struct _LARGE_INTEGER { public long QuadPart; } [ InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("00000109-0000-0000-C000-000000000046") ] public interface IPersistStream : IPersist { [Pre