Solved

can't open file with StgOpenStorage

Posted on 2000-03-11
5
945 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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn 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…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now