Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Implementing IPersistStream?

Implementing IPersistStream?

Scheduled Pinned Locked Moved C#
csharpc++comhelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    solidstore
    wrote on last edited by
    #1

    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?

    L 1 Reply Last reply
    0
    • S solidstore

      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?

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • L leppie

        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

        S Offline
        S Offline
        solidstore
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups