本文整理汇总了C++中LPSTORAGE::CreateStorage方法的典型用法代码示例。如果您正苦于以下问题:C++ LPSTORAGE::CreateStorage方法的具体用法?C++ LPSTORAGE::CreateStorage怎么用?C++ LPSTORAGE::CreateStorage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPSTORAGE
的用法示例。
在下文中一共展示了LPSTORAGE::CreateStorage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dlg
void CEx27bView::OnEditCopyto()
{
// Copy text to an .STG file (nothing special about STG ext)
CFileDialog dlg(FALSE, "stg", "*.stg");
if (dlg.DoModal() != IDOK) {
return;
}
CEx27bDoc* pDoc = GetDocument();
// Create a structured storage home for the object (m_pStgSub).
// Create a root storage file, then a substorage named "sub."
LPSTORAGE pStgRoot;
VERIFY(::StgCreateDocfile(dlg.GetPathName().AllocSysString(),
STGM_READWRITE|STGM_SHARE_EXCLUSIVE|STGM_CREATE,
0, &pStgRoot) == S_OK);
ASSERT(pStgRoot != NULL);
LPSTORAGE pStgSub;
VERIFY(pStgRoot->CreateStorage(CEx27bDoc::s_szSub,
STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE,
0, 0, &pStgSub) == S_OK);
ASSERT(pStgSub != NULL);
// Get the IPersistStorage* for the object
LPPERSISTSTORAGE pPS = NULL;
VERIFY(pDoc->m_lpOleObj->QueryInterface(IID_IPersistStorage,
(void**) &pPS) == S_OK);
// Finally, save the object in its new home in the user's file
VERIFY(::OleSave(pPS, pStgSub, FALSE) == S_OK);
// FALSE means different stg
pPS->SaveCompleted(NULL); // What does this do?
pPS->Release();
pStgSub->Release();
pStgRoot->Release();
}
示例2: ReadDirectory
void ReadDirectory(const char* szPath, LPSTORAGE pStg)
{
// recursive function
USES_CONVERSION;
WIN32_FIND_DATA fData;
HANDLE h;
char szNewPath[MAX_PATH];
char szStorageName[100];
char szStreamName[100];
char szData[81];
char* pch = NULL;
LPSTORAGE pSubStg = NULL;
LPSTREAM pStream = NULL;
g_nIndent++;
strcpy(szNewPath, szPath);
strcat(szNewPath, "*.*");
h = ::FindFirstFile(szNewPath, &fData);
if (h == (HANDLE) 0xFFFFFFFF) return; // can't find directory
do {
if (!strcmp(fData.cFileName, "..") ||
!strcmp(fData.cFileName, ".") ) continue;
while((pch = strchr(fData.cFileName, '!')) != NULL) {
*pch = '|';
}
if (fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
// It's a directory, so make a storage
strcpy(szNewPath, szPath);
strcat(szNewPath,fData.cFileName);
strcat(szNewPath, "\\");
strcpy(szStorageName, fData.cFileName);
szStorageName[31] = '\0'; // limit imposed by OLE
TRACE("%0.*sStorage = %s\n", (g_nIndent - 1) * 4,
g_szBlanks, szStorageName);
VERIFY(pStg->CreateStorage(T2COLE(szStorageName),
STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
0, 0, &pSubStg) == S_OK);
ASSERT(pSubStg != NULL);
ReadDirectory(szNewPath, pSubStg);
pSubStg->Release();
}
else {
if ((pch = strrchr(fData.cFileName, '.')) != NULL) {
if (!stricmp(pch, ".TXT")) {
// It's a text file, so make a stream
strcpy(szStreamName, fData.cFileName);
strcpy(szNewPath, szPath);
strcat(szNewPath, szStreamName);
szStreamName[32] = '\0'; // OLE max length
TRACE("%0.*sStream = %s\n", (g_nIndent - 1) * 4,
g_szBlanks, szNewPath);
CStdioFile file(szNewPath, CFile::modeRead);
// Ignore zero-length files
if(file.ReadString(szData, 80)) {
TRACE("%s\n", szData);
VERIFY(pStg->CreateStream(T2COLE(szStreamName),
STGM_CREATE | STGM_READWRITE |
STGM_SHARE_EXCLUSIVE,
0, 0, &pStream) == S_OK);
ASSERT(pStream != NULL);
// Include the null terminator in the stream
pStream->Write(szData, strlen(szData) + 1, NULL);
pStream->Release();
}
}
}
}
} while (::FindNextFile(h, &fData));
g_nIndent--;
}