Dokumententitel auslesen
-
ja, merk ich auch grade.
gibts da was büchermäßiges für,w as du empfehlen kannst, das einen zumindest einen groben einstieg in das thema gibt ?!
-
Die ersten Kapitel von "Indside OLE2" für die Basics
"ATL Internals" für den Umgang mit ATL und Safe-Pointern...
"Essential COM" fürs eingemachte.Tutorials sind etwas mit dem ich mich (seit Jahren) nicht (mehr) beschäftige. Vielleicht haben andere das Tipps!
-
ok, danke.
wegen dem problem was ich ursprünglich hatte/hab. habe jetzt funktionierende code-schnipsel gefunden die DetailsOf verwenden, nur leider krieg ich die spalte mit dem titel inhalt nicht abgefragt, da diese scheinbar nicht existiert?!
hab mir das im Debug mal angeschaut, bis zur spaltennummer 7 liefert mir der Return Value S_OK und danach halt S_FALSE.
Leider steht in keiner Spalte der Titel drin, hab bei MSDN gelesen das wohl nur die ersten 4 IDs fest definiert sind und der rest mehr oder weniger willkürlich gesetzt ist. Komme ich mit DetailsOf also doch nicht an den titel ode rmuss ich da noch etwas anderes beachten?.
hr = isfCur->GetDetailsOf(pidl, 0, &sd); hr = isfCur->GetDetailsOf(pidl, 1, &sd); hr = isfCur->GetDetailsOf(pidl, 2, &sd); hr = isfCur->GetDetailsOf(pidl, 3, &sd); hr = isfCur->GetDetailsOf(pidl, 4, &sd); hr = isfCur->GetDetailsOf(pidl, 5, &sd); hr = isfCur->GetDetailsOf(pidl, 6, &sd); hr = isfCur->GetDetailsOf(pidl, 7, &sd); hr = isfCur->GetDetailsOf(pidl, 8, &sd); hr = isfCur->GetDetailsOf(pidl, 9, &sd);
-
wenn man lang genug blutet gehts auch anders

IPropertyStorage *pPropStg = NULL; IPropertySetStorage *pPropSetStg = NULL; PROPSPEC propspec; PROPVARIANT propRead; hr = StgOpenStorageEx( L"C:\\temp\\test\\test.doc", STGM_SHARE_EXCLUSIVE| STGM_READ, STGFMT_ANY, 0, NULL, NULL, IID_IPropertySetStorage, reinterpret_cast<void**>(&pPropSetStg) ); hr = pPropSetStg->Open(PropSetfmtid, STGM_READ|STGM_SHARE_EXCLUSIVE, &pPropStg ); propspec.ulKind = PRSPEC_PROPID; propspec.propid = 0x00000002; hr = pPropStg->ReadMultiple(1, &propspec, &propRead);gemäß: http://www.codeproject.com/KB/files/SummInfoPropSetFile.aspx
in der propRead struktur steht dann der titel drin.
P.s: mit GetDetailsOf / GetDetailsEx hab ich es nicht hinbekommen
gruß
-
hallo,
ich muss das alte Thema noch mal ausbuddeln:
Kurz worum es geht:
Ich habe eine Möglichkeit gesucht mit der ich die "Titel"-Information eines Worddokumentes auslesen kann, das ist die Information die man sieht, wenn man im Explorer die Spalte "Titel" Information aktiviert. Solch ein Text ist in der Regel nur bei Office-Dokumenten,sprich Word, Excel usw vorhanden. Das habe ich auch geschafft.Nun mein Folgeproblem:
Als Konsequenz aus dem lesen hab ich jetzt eine Funktion gebaut um den Titeltext einer Datei neu zu setzen. Das funktioniert auch soweit, im Explorer sehe ich den von mir gesetzten Titeltext in der vorgesehenen Spalte.Öffne ich aber jetzt das (Word-)dokument mit Word und wähle über Datei->Eigenschaften die Funktion aus um über Word den Titel des Dokumentes (neu) zu setzen bzw. zu editieren, steht dort komischerweise nur der erste Buchstabe, des von mir gesetzten Textes.
Hat jemand eine Idee woran das liegen könnte?(Im Explorer steht er komplett und richtig drin)
Hier mal der Code mit dem ich den Titeltext setze:
bool FileManager::setNewTitelOfFile(std::wstring path, std::wstring titel) { FMTID PropSetfmtid={0xf29f85e0,0x4ff9,0x1068,{0xab, 0x91, 0x08, 0x00, 0x2b, 0x27, 0xb3, 0xd9 }}; HRESULT hr = S_OK; IPropertyStorage *pPropStg = NULL; IPropertySetStorage *pPropSetStg = NULL; PROPSPEC propspec; PROPVARIANT propWrite; hr = StgOpenStorageEx( path.c_str(), STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, STGFMT_ANY, 0, NULL, NULL, IID_IPropertySetStorage, reinterpret_cast<void**>(&pPropSetStg) ); if (hr == S_OK) { hr = pPropSetStg->Create(PropSetfmtid, NULL, PROPSETFLAG_DEFAULT, STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &pPropStg); if (hr == S_OK) { propspec.ulKind = PRSPEC_PROPID; propspec.propid = 0x00000002; //String umsetzen in TCHAR TCHAR titelAsTCHAR[1024]={0}; StringCbPrintf(titelAsTCHAR, 1024, L"%s", titel.c_str()); //von TCHAR nach char char titelAsChar[1024] = {0}; WideCharToMultiByte(CP_ACP, NULL, titelAsTCHAR, static_cast<int>(titel.length()), titelAsChar, static_cast<int>(titel.length()), NULL, NULL); propWrite.pszVal = titelAsChar; propWrite.vt = VT_LPSTR; hr = pPropStg->WriteMultiple(1, &propspec, &propWrite, PID_FIRST_USABLE); if (hr == S_OK) { pPropSetStg->Release(); pPropStg->Release(); return true; } } else { pPropSetStg->Release(); pPropStg->Release(); } } return false;
-
korig schrieb:
hallo,
ich muss das alte Thema noch mal ausbuddeln:
Kurz worum es geht:
Ich habe eine Möglichkeit gesucht mit der ich die "Titel"-Information eines Worddokumentes auslesen kann, das ist die Information die man sieht, wenn man im Explorer die Spalte "Titel" Information aktiviert. Solch ein Text ist in der Regel nur bei Office-Dokumenten,sprich Word, Excel usw vorhanden. Das habe ich auch geschafft.Nun mein Folgeproblem:
Als Konsequenz aus dem lesen hab ich jetzt eine Funktion gebaut um den Titeltext einer Datei neu zu setzen. Das funktioniert auch soweit, im Explorer sehe ich den von mir gesetzten Titeltext in der vorgesehenen Spalte.Öffne ich aber jetzt das (Word-)dokument mit Word und wähle über Datei->Eigenschaften die Funktion aus um über Word den Titel des Dokumentes (neu) zu setzen bzw. zu editieren, steht dort komischerweise nur der erste Buchstabe, des von mir gesetzten Textes.
Hat jemand eine Idee woran das liegen könnte?(Im Explorer steht er komplett und richtig drin)
Hier mal der Code mit dem ich den Titeltext setze:
bool FileManager::setNewTitelOfFile(std::wstring path, std::wstring titel) { FMTID PropSetfmtid={0xf29f85e0,0x4ff9,0x1068,{0xab, 0x91, 0x08, 0x00, 0x2b, 0x27, 0xb3, 0xd9 }}; HRESULT hr = S_OK; IPropertyStorage *pPropStg = NULL; IPropertySetStorage *pPropSetStg = NULL; PROPSPEC propspec; PROPVARIANT propWrite; hr = StgOpenStorageEx( path.c_str(), STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, STGFMT_ANY, 0, NULL, NULL, IID_IPropertySetStorage, reinterpret_cast<void**>(&pPropSetStg) ); if (hr == S_OK) { hr = pPropSetStg->Create(PropSetfmtid, NULL, PROPSETFLAG_DEFAULT, STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &pPropStg); if (hr == S_OK) { propspec.ulKind = PRSPEC_PROPID; propspec.propid = 0x00000002; //String umsetzen in TCHAR TCHAR titelAsTCHAR[1024]={0}; StringCbPrintf(titelAsTCHAR, 1024, L"%s", titel.c_str()); //von TCHAR nach char char titelAsChar[1024] = {0}; WideCharToMultiByte(CP_ACP, NULL, titelAsTCHAR, static_cast<int>(titel.length()), titelAsChar, static_cast<int>(titel.length()), NULL, NULL); propWrite.pszVal = titelAsChar; propWrite.vt = VT_LPSTR; hr = pPropStg->WriteMultiple(1, &propspec, &propWrite, PID_FIRST_USABLE); if (hr == S_OK) { pPropSetStg->Release(); pPropStg->Release(); return true; } } else { pPropSetStg->Release(); pPropStg->Release(); } } return false;ich wäre wirklich für jede art von tipp dankbar. es reicht auch schon wenn jemand ein forum kennt, wo leute unterwegs sind die sich mit programmierung rund um ms-office produkte auskennt.
hab jetzt meine mittel ausgeschöpft, mit Black-box testing komm ich nicht mehr weiter, ich brauch jemand der ahnung von der materie hat und weis wie office-arbeitet
-
eventuell die Newsgroup microsoft.public.win32.programmer.ole
-
Funktioniert dieser Code bei dir?
#include <windows.h> #include <iostream> const FMTID FMTID_SummaryInformation = {0xf29f85e0, 0x4ff9, 0x1068, {0xab, 0x91, 0x08, 0x00, 0x2b, 0x27, 0xb3, 0xd9}}; bool setTitle(wchar_t* filename, char* title) { HRESULT hr; IStorage* pStorage; hr = StgOpenStorage(filename, NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, NULL, 0, &pStorage); if(FAILED(hr)) { std::cout << "StgOpenStorage failed!" << '\n'; return false; } IPropertySetStorage* pPropertySetStorage; hr = pStorage->QueryInterface(IID_IPropertySetStorage, reinterpret_cast<void**>(&pPropertySetStorage)); if(FAILED(hr)) { std::cout << "IStorage::QueryInterface for IPropertySetStorage failed!" << '\n'; pStorage->Release(); return false; } IPropertyStorage* pPropertyStorage; hr = pPropertySetStorage->Open(FMTID_SummaryInformation, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &pPropertyStorage); if(FAILED(hr)) { std::cout << "IPropertyStorage::Open failed!" << '\n'; pPropertySetStorage->Release(); pStorage->Release(); return false; } PROPSPEC propertySpecification; propertySpecification.ulKind = PRSPEC_PROPID; propertySpecification.propid = PIDSI_TITLE; PROPVARIANT property; property.vt = VT_LPSTR; property.pszVal = title; hr = pPropertyStorage->WriteMultiple(1, &propertySpecification, &property, 2); if(FAILED(hr)) { std::cout << "IPropertyStorage::WriteMultiple failed!" << '\n'; return false; } pPropertyStorage->Release(); pPropertySetStorage->Release(); pStorage->Release(); return true; } int main() { setTitle(L"C:\\test.doc", "Test"); }
-
Konnte den Fehler auch nachvollziehen als ich jetzt mal Create statt Open von IPropertySetStorage ausprobiert habe.
Lösungen damit der Fehler nicht auftritt:
PROPSETFLAG_ANSI statt PROPSETFLAG_DEFAULT benutzen.
oder
Die Property als Widestring also VT_LPWSTR schreiben.
-
.......... schrieb:
Funktioniert dieser Code bei dir?
nein, bei
hr = pPropertySetStorage->Open(FMTID_SummaryInformation, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &pPropertyStorage);bricht er ab und bekommt in hr den wert "wurde nicht gefunden"
-
Hast du das Dokument im Explorer über Neu -> Microsoft Word Dokument angelegt? In dem Fall geht es auch bei mir nicht. Dann muss man erst ein Property Set mit pPropertySetStorage->Create anlegen.
Und hast du meinen dritten Beitrag übersehen oder warum hast du dich dazu nicht geäußert?

-
ja super, besten dank.
hatte deinen beitrag überlesen, weil ich was länger gebraucht hab um meine antwort zu tippen.
danke, denke so ist das ok. ist es ein problem, bei jedem mal wenn ich den text setzen will ein Create zu machen? oder gibt das irgendwie probleme?(bisher keine festgestellt, frag nur so)
und noch was, ich hab auch eine routine zum lesen der titel information, die im wesentlich gleich aufgebaut ist. Bei PDF-Dokumenten versagt die Funktion, liegt das an meinem code oder kann man über das Ipropertystorage interface nicht an den titel ovn PDFs kommen?
Mein code zum lesen
std::wstring FileManager::readTitelOfFile(std::wstring path) { //Typ des Titel - Propertysets FMTID PropSetfmtid={0xf29f85e0,0x4ff9,0x1068,{0xab, 0x91, 0x08, 0x00, 0x2b, 0x27, 0xb3, 0xd9 }}; HRESULT hr = S_OK; IPropertyStorage *pPropStg = NULL; IPropertySetStorage *pPropSetStg = NULL; PROPSPEC propspec; PROPVARIANT propRead; //Datei öffnen hr = StgOpenStorageEx(path.c_str(), STGM_READ | STGM_SHARE_DENY_WRITE, STGFMT_ANY, 0, NULL, NULL, IID_IPropertySetStorage, reinterpret_cast<void**>(&pPropSetStg) ); if (hr != S_OK) return std::wstring(L""); //Eigenschaften öffnen hr = pPropSetStg->Open(PropSetfmtid, STGM_DIRECT | STGM_SHARE_EXCLUSIVE | STGM_READ, &pPropStg ); if (hr != S_OK) return std::wstring(L""); //Setzen welche Information gelesen werden soll propspec.ulKind = PRSPEC_PROPID; propspec.propid = 0x00000002; //Titel //Titel lesen hr = pPropStg->ReadMultiple(1, &propspec, &propRead); if (hr != S_OK) return std::wstring(L""); //char-ANSI nach TCHAR-Unicode umsetzen std::string temp = propRead.pszVal; TCHAR rtTC[1024]={0}; MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, temp.c_str(), static_cast<int>(temp.length()), rtTC, static_cast<int>(temp.length())); //aus TCHAR-Array neuen String erzeugen std::wstring rtn = rtTC; pPropSetStg->Release(); pPropStg->Release(); return rtn; }
-
Eine PDF Datei ist keine COM-Structured storage!
-
mr schrieb:
Eine PDF Datei ist keine COM-Structured storage!
hm, wie komm da dann an die Information die ich brauche. hatte es mal mit GetDetailsOf probiert, aber keine der information die ich damit bekommen hab, war die, die ich gesucht hab.....
-
Ich hab mal nach GetDetailsOf bei Codeproject gesucht und darauf gestossen:
http://www.codeproject.com/KB/files/detailedfileinfo.aspx
Bei mir kanns die PDF Informationen auslesen, wenn Adobe Acrobat Reader installiert ist.
-
hatte dazu schonmal eine "eigene" routine gebastelt, (ok, sind zusammenkopierte code-schnipsel).
damit kann ich informationen lesen wie dateiname, änderungsdatum, erstellungsdatum usw. aber halt nicht die titelinformation
würde mich interessieren was ich falsch gemacht hab, aber aufjedenfall schonmal danke für den link. (würd am liebsten aber keine fremden klassen benutzen, dann weis ich wenigsten das ich schuld bin, wenns nicht funktioniert
).kannst du mir evtl sagen was ich da falsch machen, ich komm an alles ran, nur nicht an den doofen titel.
// GetDetailsOf.cpp : Defines the entry point for the console application. // #include "stdafx.h" // ListDirCon.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung. // #include "stdafx.h" #include "windows.h" #include "shlobj.h" #include <iostream> using namespace std; int _tmain(int argc, TCHAR* argv[]) { char path[MAX_PATH] = "C:\\temp\\"; HRESULT hr; IShellFolder * isfDesktop = NULL; IShellFolder2 * isfCur = NULL; hr = CoInitialize(NULL); // initialize COM LPMALLOC pMalloc = NULL; // memory manager, for freeing up PIDLs hr = SHGetMalloc(&pMalloc); hr = SHGetDesktopFolder(&isfDesktop); isfDesktop->QueryInterface(IID_IShellFolder2, (LPVOID*)&isfCur); // IShellFolder::ParseDisplayName requires the path name in Unicode. OLECHAR olePath[MAX_PATH]; // wide-char version of path name MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, olePath, MAX_PATH); // parse path for absolute PIDL, and connect to target folder LPITEMIDLIST pidl = NULL; // general purpose hr = isfDesktop->ParseDisplayName(NULL, NULL, olePath, NULL, &pidl, NULL); LPSHELLFOLDER psfFolder = NULL; hr = isfDesktop->BindToObject(pidl, NULL, IID_IShellFolder, (void**)&psfFolder); isfDesktop->Release(); // no longer required pMalloc->Free(pidl); LPENUMIDLIST penumIDL = NULL; // IEnumIDList interface for reading contents hr = psfFolder->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &penumIDL); while(1) { // retrieve a copy of next local item ID list hr = penumIDL->Next(1, &pidl, NULL); if(hr == NOERROR) { WIN32_FIND_DATA ffd; hr = SHGetDataFromIDList(psfFolder, pidl, SHGDFIL_FINDDATA, &ffd, sizeof(WIN32_FIND_DATA)); SHELLDETAILS sd; hr = isfCur->GetDetailsOf(pidl, 0, &sd); wcout<<sd.str.pOleStr<<endl; hr = isfCur->GetDetailsOf(pidl, 1, &sd); wcout<<sd.str.pOleStr<<endl; hr = isfCur->GetDetailsOf(pidl, 2, &sd); wcout<<sd.str.pOleStr<<endl; hr = isfCur->GetDetailsOf(pidl, 3, &sd); wcout<<sd.str.pOleStr<<endl; hr = isfCur->GetDetailsOf(pidl, 4, &sd); wcout<<sd.str.pOleStr<<endl; hr = isfCur->GetDetailsOf(pidl, 5, &sd); wcout<<sd.str.pOleStr<<endl; hr = isfCur->GetDetailsOf(pidl, 6, &sd); wcout<<sd.str.pOleStr<<endl; hr = isfCur->GetDetailsOf(pidl, 7, &sd); wcout<<sd.str.pOleStr<<endl; hr = isfCur->GetDetailsOf(pidl, -1, &sd); wcout<<sd.str.pOleStr<<endl; wcout << L"Name = " << ffd.cFileName << endl; wcout << L"Type = " << ( (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? "dir\n" : "file\n" ); wcout << L"Size = " << ffd.nFileSizeLow << endl; pMalloc->Free(pidl); } else break; } // release all remaining interface pointers penumIDL->Release(); psfFolder->Release(); pMalloc->Release(); CoUninitialize(); // shut down COM return 0; }
-
Ich werd demnächst mal gucken ob ich den Fehler finde, aber ich kann da nichts versprechen, ich kenn mich damit nämlich auch nicht aus. Aber ich hatte gar nicht gesehen das Martin Richter dir schon einen Link gegeben hat. Da kannst du doch einfach ein paar Debug-Ausgaben reinbauen um z.B. zu sehen welche ID der Titel hat.
-
Ich wüsste auch nicht wie man das mit GetDetailsOf zuverlässig hinbekommen soll wenn die ID immer unterschiedlich sein kann.
Deshalb habe ich nach einem Beispiel für GetDetailsEx gegoogled und bin auf das gestossen: http://www.experts-exchange.com/Programming/Languages/CPP/Q_21038514.htmlKanns im Moment nicht ausprobieren, aber es sieht gut aus.

-
Schade, klappt doch nicht, wenn man GetDetailsEx mit FMTID_SummaryInformation benutzt funktioniert es nur bei Dateien mit Structured Storage.
-
Ah es geht doch, hatte nur ein CoInitializeEx oder OleInitialize vergessen.

#include <windows.h> #include <shlobj.h> #include <iostream> #include <string> std::wstring getTitle(const std::wstring& path, const std::wstring& filename) { IMalloc* pMalloc; SHGetMalloc(&pMalloc); IShellFolder* pDesktopFolder; SHGetDesktopFolder(&pDesktopFolder); ITEMIDLIST* pidlShellItem; pDesktopFolder->ParseDisplayName(NULL, NULL, const_cast<wchar_t*>(path.c_str()), NULL, &pidlShellItem, NULL); IShellFolder2* pFolder; pDesktopFolder->BindToObject(pidlShellItem, NULL, IID_IShellFolder2, reinterpret_cast<void**>(&pFolder)); pMalloc->Free(pidlShellItem); pFolder->ParseDisplayName(NULL, NULL, const_cast<wchar_t*>(filename.c_str()), NULL, &pidlShellItem, NULL); SHCOLUMNID columnId; columnId.fmtid = FMTID_SummaryInformation; columnId.pid = PIDSI_TITLE; VARIANT variant; pFolder->GetDetailsEx(pidlShellItem, &columnId, &variant); pMalloc->Free(pidlShellItem); pMalloc->Release(); pFolder->Release(); pDesktopFolder->Release(); return variant.bstrVal; } int main() { OleInitialize(NULL); std::wcout << getTitle(L"C:\\", L"test.pdf") << '\n'; }Der Code braucht natürlich noch eine Überarbeitung, speziell in Sachen Fehlerbehandlung.