Connecting Tech Pros Worldwide Help | Site Map

problem using StgOpenStorage()

Newbie
 
Join Date: Apr 2008
Posts: 4
#1: May 6 '08
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?
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: May 6 '08

re: problem using StgOpenStorage()


Quote:

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
Newbie
 
Join Date: Apr 2008
Posts: 4
#3: May 6 '08

re: problem using StgOpenStorage()


Quote:

Originally Posted by r035198x

The ref pages say you need Ole32.dll

But here I am already calling the function as below:
[DllImport("ole32.dll")]
static extern int StgOpenStorage(
[MarshalAs(UnmanagedType.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.
Newbie
 
Join Date: Sep 2009
Posts: 1
#4: Sep 11 '09

re: problem using StgOpenStorage()


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

Expand|Select|Wrap|Line Numbers
  1. <ComImportAttribute(), ComConversionLoss(), Guid("0000000b-0000-0000-c000-000000000046"), _
  2. InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
  3. Friend Interface IStorage
  4.     ' Warning: all online examples of IStorage in VB.NET use "Sub" instead of "Function" - that will not work!
  5.     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
  6.     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
  7.     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
  8.     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
  9.     Function CopyTo(ByVal ciidExclude As Integer, ByRef rgiidExclude() As Guid, ByRef snbExclude As tagRemSNB, ByVal pstgDest As IStorage) As Integer
  10.     Function MoveElementTo(ByVal pwcsName As String, ByVal pstgDest As IStorage, ByVal pwcsNewName As String, ByVal grfFlags As Integer) As Integer
  11.     Function Commit(ByVal grfCommitFlags As Integer) As Integer
  12.     Function Revert() As Integer
  13.     Function EnumElements(ByVal reserved1 As Integer, ByVal reserved2 As IntPtr, ByVal reserved3 As Integer, <Out()> ByRef ppenum As IEnumSTATSTG) As Integer
  14.     Function DestroyElement(ByVal pwcsName As String) As Integer
  15.     Function RenameElement(ByVal pwcsOldName As String, ByVal pwcsNewName As String) As Integer
  16.     Function SetElementTimes(ByVal pwcsName As String, ByRef pctime As ComTypes.FILETIME, ByRef patime As ComTypes.FILETIME, ByRef pmtime As ComTypes.FILETIME) As Integer
  17.     Function SetClass(ByRef clsid As Guid) As Integer
  18.     Function SetStateBits(ByVal grfStateBits As Integer, ByVal grfMask As Integer) As Integer
  19.     Function Stat(<Out()> ByRef pstatstg As ComTypes.STATSTG, ByVal grfStatFlag As Integer) As Integer
  20. End Interface
  21.  
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,148
#5: Sep 11 '09

re: problem using StgOpenStorage()


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
Reply