problem using StgOpenStorage()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bhumesh
    New Member
    • Apr 2008
    • 4

    problem using StgOpenStorage()

    Hello, I am using the Marshalling of StgOpenStorage in my program. It is giving me the error Error as: The type or namespace name 'IStorage' could not be found (are you missing a using directive or an assembly reference?). Can I have a solution for this, please?
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by bhumesh
    Hello, I am using the Marshalling of StgOpenStorage in my program. It is giving me the error Error as: The type or namespace name 'IStorage' could not be found (are you missing a using directive or an assembly reference?). Can I have a solution for this, please?
    The ref pages say you need Ole32.dll

    Comment

    • bhumesh
      New Member
      • Apr 2008
      • 4

      #3
      Originally posted by r035198x
      The ref pages say you need Ole32.dll
      But here I am already calling the function as below:
      [DllImport("ole3 2.dll")]
      static extern int StgOpenStorage(
      [MarshalAs(Unman agedType.LPWStr )] string pwcsName
      , IStorage pstgPriority
      , STGM grfMode // Access Method (uint)
      , IntPtr snbExclude // Must be NULL
      , uint reserved // Reserved
      , out IStorage ppstgOpen); // Returned Storage

      So what could be the problem? The error is also raised on STGM enum. Am I supposed to give additional import statements? Please reply.

      Comment

      • Scandal
        New Member
        • Sep 2009
        • 1

        #4
        You must define IStorage using another declaration - here is a VB version that I once wrote in one of my apps;

        Code:
        <ComImportAttribute(), ComConversionLoss(), Guid("0000000b-0000-0000-c000-000000000046"), _
        InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
        Friend Interface IStorage
            ' Warning: all online examples of IStorage in VB.NET use "Sub" instead of "Function" - that will not work!
            Function CreateStream(ByVal pwcsName As String, ByVal grfMode As Integer, ByVal reserved1 As Integer, ByVal reserved2 As Integer, <Out()> ByRef ppstm As ComTypes.IStream) As Integer
            Function OpenStream(ByVal pwcsName As String, ByVal reserved1 As IntPtr, ByVal grfMode As Integer, ByVal reserved2 As Integer, <Out()> ByRef ppstm As ComTypes.IStream) As Integer
            Function CreateStorage(ByVal pwcsName As String, ByVal grfMode As Integer, ByVal reserved1 As Integer, ByVal reserved2 As Integer, <Out()> ByRef ppstg As IStorage) As Integer
            Function OpenStorage(ByVal pwcsName As String, ByVal pstgPriority As IStorage, ByVal grfMode As Integer, ByVal snbExclude As tagRemSNB, ByVal reserved As Integer, <Out()> ByRef ppstg As IStorage) As Integer
            Function CopyTo(ByVal ciidExclude As Integer, ByRef rgiidExclude() As Guid, ByRef snbExclude As tagRemSNB, ByVal pstgDest As IStorage) As Integer
            Function MoveElementTo(ByVal pwcsName As String, ByVal pstgDest As IStorage, ByVal pwcsNewName As String, ByVal grfFlags As Integer) As Integer
            Function Commit(ByVal grfCommitFlags As Integer) As Integer
            Function Revert() As Integer
            Function EnumElements(ByVal reserved1 As Integer, ByVal reserved2 As IntPtr, ByVal reserved3 As Integer, <Out()> ByRef ppenum As IEnumSTATSTG) As Integer
            Function DestroyElement(ByVal pwcsName As String) As Integer
            Function RenameElement(ByVal pwcsOldName As String, ByVal pwcsNewName As String) As Integer
            Function SetElementTimes(ByVal pwcsName As String, ByRef pctime As ComTypes.FILETIME, ByRef patime As ComTypes.FILETIME, ByRef pmtime As ComTypes.FILETIME) As Integer
            Function SetClass(ByRef clsid As Guid) As Integer
            Function SetStateBits(ByVal grfStateBits As Integer, ByVal grfMask As Integer) As Integer
            Function Stat(<Out()> ByRef pstatstg As ComTypes.STATSTG, ByVal grfStatFlag As Integer) As Integer
        End Interface

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          If you put your cursor over IStorage, the last letter will probably be underlined, which will give you a little drop down box. You get to pick if you want to add the namespace or enter a full reference to the class

          Comment

          Working...