Solved

can't open file with StgOpenStorage

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
object modeling - load and save functions 5 62
FMX StringGrid1->Canvas->FillRect Problem 3 175
passing data from one form to another form in c++ 27 83
max float value 3 53
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

830 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