I have a CArchive
Which contains a serialized CMapStringToString
.
From my research it is my understanding that it is quite difficult to directly read a CArchive
from within a C# DLL. So I decided to read it in the MFC application and feed it into the DLL interface.
At the moment I am doing the following:
m_pInterface->UpgradeDatabase();
CFile fileNotes;
CFileException ex;
TCHAR szError[_MAX_PATH];
CMapStringToString mapSSBrotherNotes;
if (fileNotes.Open(_T("d:\\BrotherNotes.BIN"), CFile::modeRead, &ex))
{
TRY
{
CArchive ar(&fileNotes, CArchive::load);
mapSSBrotherNotes.Serialize(ar);
ar.Close();
POSITION sPos = mapSSBrotherNotes.GetStartPosition();
while (sPos != NULL)
{
CString strName, strNotes;
CComBSTR bstrName, bstrNotes;
mapSSBrotherNotes.GetNextAssoc(sPos, strName, strNotes);
bstrName = strName.AllocSysString();
bstrNotes = strNotes.AllocSysString();
m_pInterface->SetPublisherNotes(bstrName, bstrNotes);
}
}
CATCH(CException, pEx)
{
pEx->GetErrorMessage(szError, _MAX_PATH);
AfxMessageBox(szError, MB_OK | MB_ICONERROR);
}
END_CATCH
fileNotes.Close();
}
else
{
// If the file was not found, this is probably not an error
if (ex.m_cause != CFileException::fileNotFound)
{
ex.GetErrorMessage(szError, _MAX_PATH);
AfxMessageBox(szError, MB_OK | MB_ICONERROR);
}
}
m_pInterface->SavePublisherData(&iResult);
It works fine but is there a better way to read this data file from within the C# DLL?
Side question - can my use of CString
/ CComBSTR
be simplified in my current code?