delphi 读写文件属性

uses comobj,activex;
const
  IID_IPropertySetStorage:TGUID = '{0000013A-0000-0000-C000-000000000046}';

  FMTID_SummaryInformation:TGUID='{F29F85E0-4FF9-1068-AB91-08002B27B3D9}';


function StgOpenStorageEx( pwcsName: POleStr; grfMode: dword;
  stgfmt: DWORD; grfAttrs: DWORD; pStgOptions: STGOPTIONS; reserved2: Pointer;
  riid: PGUID; out ppObjectOpen: IPropertySetStorage): HResult; stdcall;external 'ole32.dll';

var
  pPropSetStg: IPropertySetStorage;
  pPropStg:IPropertyStorage;
  propspec:TPropSpec;
  propWrite:TPropVariant;


StgOpenStorageEx(PWChar('文件名'),STGM_DIRECT or STGM_SHARE_EXCLUSIVE or STGM_READWRITE,STGFMT_ANY, 0,nil,nil ,@IID_IPropertySetStorage, pPropSetStg);
//写入
pPropSetStg.Create( FMTID_SummaryInformation, FMTID_SummaryInformation,0,STGM_CREATE or STGM_READWRITE or STGM_SHARE_EXCLUSIVE,pPropStg);
propWrite.vt:= VT_LPWSTR;
propWrite.pwszVal:= pwchar('写入的数据');
pPropStg.WriteMultiple( 1, @propspec,@propWrite, PID_FIRST_USABLE );
//读出
pPropSetStg.Open( FMTID_SummaryInformation,STGM_READ or STGM_SHARE_EXCLUSIVE,pPropStg );
pPropStg.ReadMultiple( 1, @propspec, @propWrite );

你可能感兴趣的:(Delphi)