Trying to use the StgCreateDocfile or StgOpenStorage functions, MSDN says the first parameter, pwcsName, should point to the path of the file containing the storage object. I use the following code to get the filename of an existing file:
Then, since I need it in Wide Character String format, I do the following:Code:OPENFILENAME ofn; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); // OS specific - may need to change for different Windows versions ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Word Documents (*.doc)\0*.doc\0All files (*.*)\0*.*\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "doc"; if (GetOpenFileName(&ofn)) { // Do something with the file name ...
This I *assume* has converted correctly, since I can't figure out how to view the contents of it in Debug modeCode:MessageBox(NULL, szFileName, "", MB_OK); // Debugging purposes - supplies correct filename, e.g "C:\My Documents\test.doc" CharsConverted = mbstowcs(wcsFileName, szFileName, NULL);
So, I try to open this storage file:
But this returns STG_E_INVALIDNAME in hresFile:Code:hresFile = StgOpenStorage(wcsFileName, NULL, grfDocFileFlags, NULL, 0, ppstgDocFile);
Any ideas what I'm doing wrong?STG_E_INVALIDNAME
Indicates bad name in the pwcsName parameter.
Thanks
Chris
[Edit: Okay, i got it now. Stupid stupid me:
should be:Code:CharsConverted = mbstowcs(wcsFileName, szFileName, NULL);
I thought NULL would mean carry on until you get to the end, but it's just an alias for /0, so it converted no charactersCode:CharsConverted = mbstowcs(wcsFileName, szFileName, MAX_PATH);]





]
Reply With Quote