_OLE2 AND .INI FILES by Billy Cousins Listing One // Classes for managing OLE compound files and storages within a file. //---------------------------------------------------------------------------- // CxOleDocFile class CxOleDocFile : public CObject { DECLARE_DYNAMIC(CxOleDocFile) // Constructors and Destructors public: CxOleDocFile (); ~CxOleDocFile (); // Operations // Create a compound file. BOOL CreateDocFile (const char * pszFilename, DWORD dwOpenFlags = CX_CREATE_DOCFILE_DEFAULT, CFileException * pError = NULL); // Open a compound file. BOOL OpenDocFile (const char * pszFilename, DWORD dwOpenFlags = CX_OPEN_DOCFILE_DEFAULT, CFileException * pError = NULL); // Get integer data from file. UINT GetProfileInt (const char* pszSection, const char* pszEntry, int iDefault, CFileException* pError = NULL); // Get string data from file. int GetProfileString (const char* pszSection, const char *pszEntry, const char* pszDefault, char* pszRetBuf, int cbRetBuf, CFileException* pError = NULL); // Get all of the sections. BOOL GetSections (CStringArray& rgSectionNamesRet); // Load the contents of an ini file into a compound file. BOOL LoadFromIni (const char * pszIniFilename); // Write a string to the doc file. BOOL WriteProfileString (const char * pszSection, const char * pszEntry, const char * pszValue, CFileException * pError = NULL); // Implementation public: virtual void Close (); virtual void Flush (); #ifdef _DEBUG virtual void Dump(CDumpContext&) const; virtual void AssertValid() const; #endif protected: CxOleStorage * m_pRootStg; }; // end class CxOleDocFile //---------------------------------------------------------------------------- // CxOleStorage class CxOleStorage : public CObject { DECLARE_DYNAMIC(CxOleStorage) // Constructors and Destructors public: CxOleStorage (LPSTORAGE lpStorage = NULL); ~CxOleStorage (); // Operations // Create a new storage BOOL CreateStorage (LPSTORAGE lpParentStg, const char * pszName, DWORD dwOpenFlags = CX_CREATE_STORAGE_DEFAULT, CFileException * pError = NULL); // Delete an storage or stream from the file. virtual BOOL DestroyElement (const char * pszName, CFileException * pError = NULL); // Enumerate the elements in a storage and return the ones // that match the specified type. BOOL EnumElements (enum tagSTGTY tyElem, CStringArray& rgNamesRet); // Open a storage. BOOL OpenStorage (LPSTORAGE lpParentStg, const char * pszName, DWORD dwOpenFlags = CX_OPEN_STORAGE_DEFAULT, CFileException * pError = NULL); // Implementation public: virtual void Close (); // May raise exception. virtual void Flush (); // May raise exception. #ifdef _DEBUG virtual void Dump(CDumpContext&) const; virtual void AssertValid() const; #endif protected: friend class CxOleDocFile; LPSTORAGE m_lpStorage; BOOL m_bCloseOnDelete; }; // end class CxOleStorage Listing Two // Just like the Windows APIs except a slightly different name. UINT CxGetPrivateProfileInt (LPCSTR lpszSection, LPCSTR lpszEntry, int iDefault, LPCSTR lpszFilename); int CxGetPrivateProfileString(LPCSTR lpszSection, LPCSTR lpszEntry, LPCSTR lpszDefault, LPSTR lpszReturnBuffer, int cbReturnBuffer, LPCSTR lpszFilename); BOOL CxWritePrivateProfileString (LPCSTR lpszSection, LPCSTR lpszEntry, LPCSTR lpszString, LPCSTR lpszFilename);