Solved

can't open file with StgOpenStorage

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 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.

707 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

15 Experts available now in Live!

Get 1:1 Help Now