Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

can't open file with StgOpenStorage

Posted on 2000-03-11
5
Medium Priority
?
1,012 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

715 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