Click here to Skip to main content
15,892,059 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: overload operator... a begginner info Pin
Tomasz Sowinski30-Oct-01 10:08
Tomasz Sowinski30-Oct-01 10:08 
GeneralRe: overload operator... a begginner info Pin
Remi Morin30-Oct-01 10:26
Remi Morin30-Oct-01 10:26 
GeneralRe: overload operator... a begginner info Pin
Tomasz Sowinski30-Oct-01 10:39
Tomasz Sowinski30-Oct-01 10:39 
GeneralRe: overload operator... a begginner info Pin
Michael Dunn30-Oct-01 17:21
sitebuilderMichael Dunn30-Oct-01 17:21 
GeneralTaskbar and Systray Pin
30-Oct-01 7:49
suss30-Oct-01 7:49 
GeneralRe: Taskbar and Systray Pin
Michael P Butler30-Oct-01 8:47
Michael P Butler30-Oct-01 8:47 
GeneralRe: Taskbar and Systray Pin
Ravi Bhavnani30-Oct-01 8:51
professionalRavi Bhavnani30-Oct-01 8:51 
GeneralXML File Properties and ATL Pin
30-Oct-01 7:40
suss30-Oct-01 7:40 
I've been working on this task forever, but...

I am using IPropertyStorage and IPropertySetStorage to obtain and save the summary properties for an
xml file. When I save the xml file with new file data, it creates a new file and therefore doesn't
save the summary properties stream.

USES_CONVERSION;
TCHAR l_szChar[MAX_STR_SIZE+1];
long l_hGeneralInfo = 0;
CComBSTR l_vtPlanInfo;

CComPtr<ispwpersistenceagent> l_spIspwPersistenceAgent;
HRESULT hr = l_spIspwPersistenceAgent.CoCreateInstance(CLSID_spwPersistenceAgent);
if (FAILED(hr))
{
BSTR l_lErrMsg = L"Could not create instance of Persistence Agent";
MessageBox(p_hDlg, l_lErrMsg, _T(""), MB_ICONWARNING);
}

hr = l_spIspwPersistenceAgent->Load(m_szFilePath, VARIANT_TRUE, NULL);
if (FAILED(hr))
{
BSTR l_lErrMsg = L"Could not Load instance of Persistence Agent";
MessageBox(p_hDlg, l_lErrMsg, _T(""), MB_ICONWARNING);
}

// Prepare Persistence Agent for saving command and mission
hr = l_spIspwPersistenceAgent->CreateOrOpenSubElement(
0, GENERAL_INFO, &l_hGeneralInfo);

if (FAILED(hr))
{
BSTR l_lErrMsg = L"Could not Open subelement General Info";
MessageBox(p_hDlg, l_lErrMsg, _T(""), MB_ICONWARNING);
}

// Save the store plan command.
GetDlgItemText(p_hDlg, IDC_SOMEINFO, l_szChar, NSPW_PROP_MAX_STR_SIZE);

l_spIspwPersistenceAgent->put_SubElementValue(l_hGeneralInfo,
SOMEINFO,
CComVariant(T2OLE(l_szChar) ) );


// Save the store plan mission.
GetDlgItemText(p_hDlg, IDC_SOMEOTHERINFO, l_szChar, NSPW_PROP_MAX_STR_SIZE);

l_spIspwPersistenceAgent->put_SubElementValue(l_hGeneralInfo,
SOMEOTHERINFO,
CComVariant(T2OLE(l_szChar) ) );
l_spIspwPersistenceAgent->SaveAs(m_szFilePath, VARIANT_TRUE, NULL);

TCHAR szBuffer[256];

// Save the file properties.
CComPtr<ipropertysetstorage> l_spIPropertySetStorage;

// Open the existing root storage object in the file system.
HRESULT hr = StgOpenStorageEx(m_szFile, STGM_DIRECT|STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
STGFMT_ANY, NULL, NULL, NULL,
IID_IPropertySetStorage,
(void**)&l_spIPropertySetStorage );

if (FAILED(hr))
{
wsprintf(szBuffer, _T("StgOpenStorageEx: 0x%x\n"), hr);
::MessageBox(NULL, szBuffer, _T("StgOpenStorageEx Call"), MB_OK);

I've been working on this task forever, but...

I am using IPropertyStorage and IPropertySetStorage to obtain and save the summary properties for an xml file. When I save the xml file with new file data, it creates a new file and therefore doesn't save the summary properties stream.

USES_CONVERSION;
TCHAR l_szChar[MAX_STR_SIZE+1];
long l_hGeneralInfo = 0;
CComBSTR l_vtPlanInfo;

CComPtr<ispwpersistenceagent> l_spIspwPersistenceAgent;
HRESULT hr = l_spIspwPersistenceAgent.CoCreateInstance(CLSID_spwPersistenceAgent);
if (FAILED(hr))
{
BSTR l_lErrMsg = L"Could not create instance of Persistence Agent";
MessageBox(p_hDlg, l_lErrMsg, _T(""), MB_ICONWARNING);
}

hr = l_spIspwPersistenceAgent->Load(m_szFilePath, VARIANT_TRUE, NULL);
if (FAILED(hr))
{
BSTR l_lErrMsg = L"Could not Load instance of Persistence Agent";
MessageBox(p_hDlg, l_lErrMsg, _T(""), MB_ICONWARNING);
}

// Prepare Persistence Agent for saving command and mission
hr = l_spIspwPersistenceAgent->CreateOrOpenSubElement(
0, GENERAL_INFO, &l_hGeneralInfo);

if (FAILED(hr))
{
BSTR l_lErrMsg = L"Could not Open subelement General Info";
MessageBox(p_hDlg, l_lErrMsg, _T(""), MB_ICONWARNING);
}

// Save the store plan command.
GetDlgItemText(p_hDlg, IDC_SOMEINFO, l_szChar, MAX_STR_SIZE);

l_spIspwPersistenceAgent->put_SubElementValue(l_hGeneralInfo,
SOMEINFO,
CComVariant(T2OLE(l_szChar) ) );


// Save the store plan mission.
GetDlgItemText(p_hDlg, SOMEOTHERINFO, l_szChar, MAX_STR_SIZE);

l_spIspwPersistenceAgent->put_SubElementValue(l_hGeneralInfo,
SOMEOTHERINFO,
CComVariant(T2OLE(l_szChar) ) );
l_spIspwPersistenceAgent->SaveAs(m_szFilePath, VARIANT_TRUE, NULL);

TCHAR szBuffer[256];

// Save the file properties.
CComPtr<ipropertysetstorage> l_spIPropertySetStorage;

// Open the existing root storage object in the file system.
HRESULT hr = StgOpenStorageEx(m_szFile, STGM_DIRECT|STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
STGFMT_ANY, NULL, NULL, NULL,
IID_IPropertySetStorage,
(void**)&l_spIPropertySetStorage );

if (FAILED(hr))
{
wsprintf(szBuffer, _T("StgOpenStorageEx: 0x%x\n"), hr);
::MessageBox(NULL, szBuffer, _T("StgOpenStorageEx Call"), MB_OK);

::MessageBox(NULL, L"StgOpenStorageEx FAILED", L"ApplySummaryDialog", MB_OK);
return S_OK;
}

CComPtr<ipropertystorage> l_spIPropertyStorage;

// Open an interface pointer to the existing property set.
hr = l_spIPropertySetStorage->Open(FMTID_SummaryInformation,
STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
&l_spIPropertyStorage);

wsprintf(szBuffer, _T("Open Summary: 0x%x\n"), hr);
::MessageBox(NULL, szBuffer, _T("HI"), MB_OK);
// If there is no existing property set,
if (FAILED(hr))
{

::MessageBox(NULL, L"l_spIPropertySetStorage->Open returned a FAILED", L"ApplySummaryDialog", MB_OK);

if (hr == STG_E_FILENOTFOUND )
::MessageBox(NULL, L"l_spIPropertySetStorage->Open returned STG_E_FILENOTFOUND so creating one", L"ApplySummaryDialog", MB_OK);
// Create the property set.
hr = l_spIPropertySetStorage->Create(FMTID_SummaryInformation,
&CLSID_spwFilePropShlExt,
PROPSETFLAG_DEFAULT,
STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
&l_spIPropertyStorage);
{

TCHAR tchBuffer[256];
_stprintf(tchBuffer, __TEXT("l_spIPropertySetStorage->Create failed w/error 0x%x\n", hr));

CComBSTR l_bstrErrorMsg(tchBuffer);
::MessageBox(NULL, l_bstrErrorMsg, L"ApplySummaryDialog", MB_OK);

}

return S_OK;
}

PROPSPEC l_aPropertySpec[1];
l_aPropertySpec[0].ulKind = PRSPEC_PROPID;
l_aPropertySpec[0].propid = PIDSI_AUTHOR;

PROPVARIANT l_aResults[1];

// Obtain the author.
hr = l_spIPropertyStorage->ReadMultiple( 1, l_aPropertySpec, l_aResults);

if (FAILED(hr))
{
wsprintf(szBuffer, _T("l_spIPropertyStorage->ReadMultiple: 0x%x\n"), hr);
::MessageBox(NULL, szBuffer, _T("l_spIPropertyStorage->ReadMultiple Call"), MB_OK);

l_aResults[0].pszVal = "";
}

if ( l_aResults[0].vt != VT_LPSTR ) throw _T("vt is not VT_LPSTR");
CComBSTR l_bstrAuthor = l_aResults[0].pszVal;

// Save the author.
hr = l_spIPropertyStorage->WriteMultiple( 1, l_aPropertySpec, l_aResults, NULL );
if (FAILED(hr))
{
wsprintf(szBuffer, _T("l_spIPropertyStorage->WriteMultiple: 0x%x\n"), hr);
::MessageBox(NULL,
szBuffer,
_T("l_spIPropertyStorage->WriteMultiple Call"),
MB_OK);

NSPWPASSERROR(hr,
L"Failed to write author property to storage stream ",
CspwPropPageCtrl::ApplySummaryDialog);
}

l_aPropertySpec[0].ulKind = PRSPEC_PROPID;
l_aPropertySpec[0].propid = PIDSI_COMMENTS;

::MessageBox(NULL,
L"CALLING l_spIPropertyStorage->ReadMultiple",
_T("l_spIPropertyStorage->WriteMultiple Call"),
MB_OK);

// Obtain the comments.
hr = l_spIPropertyStorage->ReadMultiple( 1, l_aPropertySpec, l_aResults);

if (FAILED(hr))
{
wsprintf(szBuffer, _T("l_spIPropertyStorage->ReadMultiple: 0x%x\n"), hr);
::MessageBox(NULL,
szBuffer,
_T("l_spIPropertyStorage->ReadMultiple Call"),
MB_OK);

l_aResults[0].pszVal = "";
}

CComBSTR l_bstrComment = l_aResults[0].pszVal;
::MessageBox(NULL,
L"Calling l_spIPropertyStorage->WriteMultiple",
_T("Comments"),
MB_OK);
// Save the comments.
hr = l_spIPropertyStorage->WriteMultiple( 1, l_aPropertySpec, l_aResults, NULL );
if (FAILED(hr))
{
wsprintf(szBuffer, _T("l_spIPropertyStorage->WriteMultiple: 0x%x\n"), hr);
::MessageBox(NULL, szBuffer, _T("l_spIPropertyStorage->WriteMultiple Call"), MB_OK);

NSPWPASSERROR(hr,
L"Failed to write comments property to storage stream ",
CspwPropPageCtrl::ApplySummaryDialog);
}
::MessageBox(NULL,
L"Calling FreePropVariantArray",
_T("Comments"),
MB_OK);

hr = FreePropVariantArray(2, l_aResults);
::MessageBox(NULL, L"CALLED FreePropVariantArray", _T("FreePropVariantArray Call"), MB_OK);

A colleague has told me it's because I'm trying to save a compound document as a non-compound document.
The l_spIPropertySetStorage->Open call normally fails, so I create the interface pointer. Can someone
please tell me how to fix this?
return S_OK;
}

CComPtr<ipropertystorage> l_spIPropertyStorage;

// Open an interface pointer to the existing property set.
hr = l_spIPropertySetStorage->Open(FMTID_SummaryInformation,
STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
&l_spIPropertyStorage);

wsprintf(szBuffer, _T("Open Summary: 0x%x\n"), hr);
::MessageBox(NULL, szBuffer, _T("HI"), MB_OK);
// If there is no existing property set,
if (FAILED(hr))
{

::MessageBox(NULL, L"l_spIPropertySetStorage->Open returned a FAILED", L"ApplySummaryDialog", MB_OK);

if (hr == STG_E_FILENOTFOUND )
::MessageBox(NULL, L"l_spIPropertySetStorage->Open returned STG_E_FILENOTFOUND so creating one", L"ApplySummaryDialog", MB_OK);
// Create the property set.
hr = l_spIPropertySetStorage->Create(FMTID_SummaryInformation,
&CLSID_spwFilePropShlExt,
PROPSETFLAG_DEFAULT,
STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
&l_spIPropertyStorage);
{

TCHAR tchBuffer[256];
_stprintf(tchBuffer, __TEXT("l_spIPropertySetStorage->Create failed w/error 0x%x\n", hr));

CComBSTR l_bstrErrorMsg(tchBuffer);
::MessageBox(NULL, l_bstrErrorMsg, L"ApplySummaryDialog", MB_OK);

}

return S_OK;
}

PROPSPEC l_aPropertySpec[1];
l_aPropertySpec[0].ulKind = PRSPEC_PROPID;
l_aPropertySpec[0].propid = PIDSI_AUTHOR;

PROPVARIANT l_aResults[1];

// Obtain the author.
hr = l_spIPropertyStorage->ReadMultiple( 1, l_aPropertySpec, l_aResults);

if (FAILED(hr))
{
wsprintf(szBuffer, _T("l_spIPropertyStorage->ReadMultiple: 0x%x\n"), hr);
::MessageBox(NULL, szBuffer, _T("l_spIPropertyStorage->ReadMultiple Call"), MB_OK);

l_aResults[0].pszVal = "";
}

if ( l_aResults[0].vt != VT_LPSTR ) throw _T("vt is not VT_LPSTR");
CComBSTR l_bstrAuthor = l_aResults[0].pszVal;

// Save the author.
hr = l_spIPropertyStorage->WriteMultiple( 1, l_aPropertySpec, l_aResults, NULL );
if (FAILED(hr))
{
wsprintf(szBuffer, _T("l_spIPropertyStorage->WriteMultiple: 0x%x\n"), hr);
::MessageBox(NULL,
szBuffer,
_T("l_spIPropertyStorage->WriteMultiple Call"),
MB_OK);

NSPWPASSERROR(hr,
L"Failed to write author property to storage stream ",
CspwPropPageCtrl::ApplySummaryDialog);
}

l_aPropertySpec[0].ulKind = PRSPEC_PROPID;
l_aPropertySpec[0].propid = PIDSI_COMMENTS;

::MessageBox(NULL,
L"CALLING l_spIPropertyStorage->ReadMultiple",
_T("l_spIPropertyStorage->WriteMultiple Call"),
MB_OK);

// Obtain the comments.
hr = l_spIPropertyStorage->ReadMultiple( 1, l_aPropertySpec, l_aResults);

if (FAILED(hr))
{
wsprintf(szBuffer, _T("l_spIPropertyStorage->ReadMultiple: 0x%x\n"), hr);
::MessageBox(NULL,
szBuffer,
_T("l_spIPropertyStorage->ReadMultiple Call"),
MB_OK);

l_aResults[0].pszVal = "";
}

CComBSTR l_bstrComment = l_aResults[0].pszVal;
::MessageBox(NULL,
L"Calling l_spIPropertyStorage->WriteMultiple",
_T("Comments"),
MB_OK);
// Save the comments.
hr = l_spIPropertyStorage->WriteMultiple( 1, l_aPropertySpec, l_aResults, NULL );
if (FAILED(hr))
{
wsprintf(szBuffer, _T("l_spIPropertyStorage->WriteMultiple: 0x%x\n"), hr);
::MessageBox(NULL, szBuffer, _T("l_spIPropertyStorage->WriteMultiple Call"), MB_OK);

NSPWPASSERROR(hr,
L"Failed to write comments property to storage stream ",
CspwPropPageCtrl::ApplySummaryDialog);
}
::MessageBox(NULL,
L"Calling FreePropVariantArray",
_T("Comments"),
MB_OK);

hr = FreePropVariantArray(2, l_aResults);
::MessageBox(NULL, L"CALLED FreePropVariantArray", _T("FreePropVariantArray Call"), MB_OK);

A colleague has told me it's because I'm trying to save a compound document as a non-compound document. The l_spIPropertySetStorage->Open call normally fails, so I create the interface pointer.
Can someone please tell me how to fix this?

Lilian
GeneralTooltips for ActiveX control on a CFormView Pin
Craig Miller30-Oct-01 7:25
Craig Miller30-Oct-01 7:25 
GeneralSmallest and common Font ( for printing) Pin
Braulio Dez30-Oct-01 6:21
Braulio Dez30-Oct-01 6:21 
GeneralRe: Smallest and common Font ( for printing) Pin
Roger Allen30-Oct-01 6:34
Roger Allen30-Oct-01 6:34 
GeneralAccessing history using CHtmlView (WebBrowser ActiveX control) Pin
JRP30-Oct-01 6:16
JRP30-Oct-01 6:16 
GeneralRe: Accessing history using CHtmlView (WebBrowser ActiveX control) Pin
JRP30-Oct-01 8:00
JRP30-Oct-01 8:00 
GeneralCommand Line Operation of VC++ Pin
Chris Meech30-Oct-01 6:13
Chris Meech30-Oct-01 6:13 
GeneralRe: Command Line Operation of VC++ Pin
Tomasz Sowinski30-Oct-01 9:59
Tomasz Sowinski30-Oct-01 9:59 
GeneralRe: Command Line Operation of VC++ Pin
Chris Meech30-Oct-01 10:28
Chris Meech30-Oct-01 10:28 
GeneralBrowse Pin
meirav30-Oct-01 6:12
meirav30-Oct-01 6:12 
GeneralRe: Browse Pin
Oscar Vazquez30-Oct-01 8:49
Oscar Vazquez30-Oct-01 8:49 
Generalvisible/invisible Pin
meirav30-Oct-01 6:08
meirav30-Oct-01 6:08 
GeneralRe: visible/invisible Pin
Chris Meech30-Oct-01 6:17
Chris Meech30-Oct-01 6:17 
GeneralRe: visible/invisible Pin
Michael P Butler30-Oct-01 6:48
Michael P Butler30-Oct-01 6:48 
GeneralRe: visible/invisible Pin
Chris Meech30-Oct-01 7:23
Chris Meech30-Oct-01 7:23 
QuestionClipping needed for better (GDI) performance? Pin
30-Oct-01 5:31
suss30-Oct-01 5:31 
QuestionLock std::ifstream? Pin
Derek Price30-Oct-01 5:02
Derek Price30-Oct-01 5:02 
AnswerRe: Lock std::ifstream? Pin
Todd Smith30-Oct-01 5:50
Todd Smith30-Oct-01 5:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.