开始我以为ole32.dll是一个COM,一直想引用,结果发现它只是一个函数库, 必须对它进行dllimport.具体代码可以看后面. 另外,我还发现以前微软的virsual studio 6 里面的Depends工具,依然在virsual studio 2005中提供了,目录在?:\Program Files\Microsoft Visual Studio 8\Common7\Tools 用这个工具可以查看一个函数库有哪些公开方法.
补充点知识,先
调用方法SetProperty
/**//*pls visit this article * * http://msdn2.microsoft.com/en-us/library/aa380328.aspx * To open an existing file, use the StgOpenStorageEx function instead. notice: Applications written for Windows 2000, Windows Server 2003 and Windows XP must use StgCreateStorageEx rather than StgCreateDocfile to take advantage of the enhanced Windows 2000 and Windows XP Structured Storage features. * */ using System; using System.Collections.Generic; using System.Text; using StructuredStorageWrapper; namespace WindowsApplication8 { class FileSummary { publicstaticvoid SetProperty(string filename,string msg , SummaryPropId summaryType) { // first you need to either create or open a file and its // property set stream //申明接口(指针) IPropertySetStorage propSetStorage =null; //com 组件的 clsid 参见IPropertySetStorage定义 Guid IID_PropertySetStorage =new Guid("0000013A-0000-0000-C000-000000000046"); //Applications written for Windows 2000, Windows Server 2003 and Windows XP must use StgCreateStorageEx rather than StgCreateDocfile to take advantage of the enhanced Windows 2000 and Windows XP Structured Storage features uint hresult = ole32.StgOpenStorageEx( filename, (int)(STGM.SHARE_EXCLUSIVE | STGM.READWRITE), (int)STGFMT.FILE, 0, (IntPtr)0, (IntPtr)0, ref IID_PropertySetStorage, ref propSetStorage); //返回指针 // next you need to create or open the Summary Information property set Guid fmtid_SummaryProperties =new Guid("F29F85E0-4FF9-1068-AB91-08002B27B3D9"); IPropertyStorage propStorage =null; hresult = propSetStorage.Create( ref fmtid_SummaryProperties, (IntPtr)0, (int)PROPSETFLAG.DEFAULT, (int)(STGM.CREATE | STGM.READWRITE | STGM.SHARE_EXCLUSIVE), ref propStorage); // next, you assemble a property descriptor for the property you // want to write to, in our case the Comment property PropSpec propertySpecification =new PropSpec(); propertySpecification.ulKind =1; propertySpecification.Name_Or_ID =new IntPtr((int)summaryType); //now, set the value you want in a property variant PropVariant propertyValue =new PropVariant(); propertyValue.FromObject(msg); // Simply pass the property spec and its new value to the WriteMultiple // method and you're almost done propStorage.WriteMultiple(1, ref propertySpecification, ref propertyValue, 2); // the only thing left to do is commit your changes. Now you're done! hresult = propStorage.Commit((int)STGC.DEFAULT); //下面的很关键,如何关闭一个非托管的指针,如果不关闭,则本程序不关闭,文件被锁定! System.Runtime.InteropServices.Marshal.ReleaseComObject(propSetStorage); propSetStorage =null; GC.Collect(); } } }