Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

can't open file with StgOpenStorage

Posted on 2000-03-11
5
Medium Priority
?
1,036 Views
Last Modified: 2008-03-04
I'm trying to deal with compound files using MFC. I've found some samples in MSDN and test it. But when I try to write my own code with StgOpenStorage it fails - I've got result - STG_E_FILENOTFOUND , that Indicates that the specified file does not exist.
I can create conpound file, but I can't open it after.
Could you help me  - what's wrong with my code?
#include "stdafx.h"
int main(int argc, char* argv[])
{
IStorage *pIStorage;
HRESULT hr;
TCHAR szFileName[MAX_PATH + 1];
TCHAR fname[MAX_PATH + 1];
HANDLE hConsoleInput, hConsoleOutput;
DWORD dwCharsOut;
LPTSTR szPathText = TEXT("Enter Path And File Name Of File To Be Created \
  \nOr Enter 'x' to Exit.\n\n\n");

ZeroMemory(szFileName, sizeof(szFileName));

hConsoleInput = GetStdHandle(STD_INPUT_HANDLE);
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);

WriteConsole(hConsoleOutput, (LPVOID)szPathText,
lstrlen(szPathText), &dwCharsOut, NULL);
    scanf("%s",&szFileName);

if (0 == (lstrcmp(szFileName, TEXT("x")))){
exit(0);
}

hr = CoInitialize(NULL);
    if (hr!=S_OK) {
printf("failed COM initialize\n");}
    hr=StgOpenStorage((const WCHAR *)szFileName, NULL, \
STGM_DIRECT | STGM_READ | STGM_SHARE_EXCLUSIVE, NULL, 0, &pIStorage);
....

Thank in advance!
0
Comment
Question by:junior_b
  • 4
5 Comments
 
LVL 5

Accepted Solution

by:
Wyn earned 400 total points
ID: 2609089
->(const WCHAR *)szFileName
You should not do this to convert a char to WCHAR string.
You'd conver it by API function.
continue.
Regards
W.Yinan
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2609091
However,if you all use neutral text-manipulation,you should define Unicode .
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2609096
1:Use
MultiByteToWideChar()
2:Declare it as wchar_t*
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2609253
btw:your usage of "\" is suspicious.How it got complied.....
0
 
LVL 1

Author Comment

by:junior_b
ID: 2617554
Thanks!
Now it works (though I've met other problem with IStorage - I can't enforce CopyTo method work. It seems I'll post next question soon :-)

Sorry for delay and thanks again.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question