Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,254 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,229 people online right now. Registration is fast and FREE... Join Now!




Structure Storage API

 
Reply to this topicStart new topic

Structure Storage API

Miss Hacker
12 Oct, 2008 - 05:58 AM
Post #1

New D.I.C Head
*

Joined: 12 Oct, 2008
Posts: 2

hi am working on Strcuture storage API

why this code isn't working

CODE
using System;
using System.Runtime.InteropServices;
namespace StgOpen
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class Class1
    {

        public enum STGM:int
        {
            DIRECT= 0X00000000,TRANSACTED=0X00010000,READ=0X00000000}
    
    

        [ComImport]
            [Guid("0000000b-0000-0000-C000-000000000046")]
            [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
            public interface IPropertyStorage
        {
            void CreateStream(
                /* [string][in] */ string pwcsName,
                /* [in] */ uint grfMode,
                /* [in] */ uint reserved1,
                /* [in] */ uint reserved2,
                /* [out] */ out IStream ppstm);

            void OpenStream(
                /* [string][in] */ string pwcsName,
                /* [unique][in] */ IntPtr reserved1,
                /* [in] */ uint grfMode,
                /* [in] */ uint reserved2,
                /* [out] */ out IStream ppstm);

            void CreateStorage(
                /* [string][in] */ string pwcsName,
                /* [in] */ uint grfMode,
                /* [in] */ uint reserved1,
                /* [in] */ uint reserved2,
                /* [out] */ out IStorage ppstg);

            void OpenStorage(
                /* [string][unique][in] */ string pwcsName,
                /* [unique][in] */ IStorage pstgPriority,
                /* [in] */ uint grfMode,
                /* [unique][in] */ IntPtr snbExclude,
                /* [in] */ uint reserved,
                /* [out] */ out IStorage ppstg);

            void CopyTo(
                /* [in] */ uint ciidExclude,
                /* [size_is][unique][in] */ Guid rgiidExclude, // should this be an array?
                /* [unique][in] */ IntPtr snbExclude,
                /* [unique][in] */ IStorage pstgDest);

            void MoveElementTo(
                /* [string][in] */ string pwcsName,
                /* [unique][in] */ IStorage pstgDest,
                /* [string][in] */ string pwcsNewName,
                /* [in] */ uint grfFlags);

            void Commit(
                /* [in] */ uint grfCommitFlags);

            void Revert();

            void EnumElements(
                /* [in] */ uint reserved1,
                /* [size_is][unique][in] */ IntPtr reserved2,
                /* [in] */ uint reserved3,
                /* [out] */ out IEnumSTATSTG ppenum);

            void DestroyElement(
                /* [string][in] */ string pwcsName);

            void RenameElement(
                /* [string][in] */ string pwcsOldName,
                /* [string][in] */ string pwcsNewName);

            void SetElementTimes(
                /* [string][unique][in] */ string pwcsName,
                /* [unique][in] */ FILETIME pctime,
                /* [unique][in] */ FILETIME patime,
                /* [unique][in] */ FILETIME pmtime);

            void SetClass(
                /* [in] */ Guid clsid);

            void SetStateBits(
                /* [in] */ uint grfStateBits,
                /* [in] */ uint grfMask);

            void Stat(
                /* [out] */ out STATSTG pstatstg,
                /* [in] */ uint grfStatFlag);

    
        }
        
        [StructLayout(LayoutKind.Sequential)]
            public struct STGOPTIONS
        {  
            [FieldOffset(0)] ushort usVersion;
            [FieldOffset(2)] ushort reserved;
            [FieldOffset(4)] uint uiSectorSize;
            [FieldOffset(8),MarshalAs(UnmanagedType.LPWStr)]string pwcsname;
        }


        [DllImport("ole32.dll")]
        public static extern int StgOpenStorageEx([MarshalAs(UnmanangedType.lPWStr)]
            string pwcsname,int grfMode,int stgfmt,int grfAttrs,ref STGOPTIONS pStgOptions,
            IntPtr reserved2,[In] ref Guid riid,[MarshalAs(UnmanangedType.IUnknown)] out object ppobjectOpen);
    }
    [STAThread]
    public static void Main(string[] args)
{
            


    string file=@"E:\\Miss_Hacker.doc";
    int result=StgOpenStorageEx(file,STGM.READ,STGFMT.DOCFILE,2,null,IntPtr.zero,ref IID_IPropertyStorage,out object ppObjectOpen);
    Console.WriteLine("{0}",result);
}
}
    

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 04:22AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month