无法在MFC中打开FIle [英] Can not open FIle in MFC
问题描述
我无法使用
StgOpenStorageEx()
以下是我用来打开文件的代码..
LpStorage是一个包含 Open()函数的类..
这里调用打开函数
REFIID riid-> riid收到的价值是
IID_IPropertyStorage
LpStorage lpstor;
IPropertySetStorage * pPropSetStg = NULL;
DWORD dwError = lpstor。打开(strFileName,STGM_READ | STGM_SHARE_EXCLUSIVE,
STGFMT_FILE, 0 ,NULL,NULL,IID_IPropertyStorage,reinterpret_cast< void **>(& pPropSetStg));
//打开函数
DWORD LpStorage
::打开
(CString strFile,DWORD grfMode,STGFMT stgfmt,DWORD grfAttrs ,STGOPTIONS * pstgOptions, void * reserved,REFIID riid, void ** ppobjection)
{
USES_CONVERSION;
strFile_ = strFile;
TRACE(LINE_INFO + 开头:%s \ n \%d仍然存在open \\\
,LPCSTR(strFile_),__ allGlobalOpen.GetCount());
// 从Open获取的参数传递给StgOpenStorage函数
DWORD结果= StgOpenStorageEx (T2COLE((LPCSTR)strFile),grfMode,
stgfmt,grfAttrs,pstgOptions,reserved, RIID,ppobjection);
如果(S_OK ==结果)
__llGlobalOpen。 AddHead( this );
返回结果;
}
//注意
StgOpenStorageEx
返回的结果不是 S_OK
我只是想知道我哪里错了?
如果您提供错误代码会很有帮助。
但是,您使用错误的铸件CString
到char指针(LPCSTR
)。它应该是LPCTSTR
。您的代码仅对非Unicode构建有效。
为避免此类错误,您应始终使用C ++强制转换而不是C强化转换。在使用CString
的情况下,最好使用corrsponding成员函数:
DWORD result = StgOpenStorageEx (T2COLE(strFile.GetString()),grfMode,
stgfmt,grfAttrs,pstgOptions,reserved,riid,ppobjection);
[更新]
您发布了错误代码作为评论。
2147500034是0x80004002,E_NOINTERFACE
。
对应的消息是'请求的COM接口不可用'。
所以你应该检查传递的值为riid
的参数StgOpenStorageEx功能(Windows) [ ^ ]。
正如Richard已经建议的那样,你应该展示一个如何调用函数的例子(参数值)。
Hi,
I am unable to open the file using
StgOpenStorageEx()
below is the code which I am using to open the file..
LpStorage is a class which contains Open() function..
Open function is called here
REFIID riid->Value received by riid is
IID_IPropertyStorage
LpStorage lpstor;
IPropertySetStorage* pPropSetStg = NULL;
DWORD dwError = lpstor.Open(strFileName, STGM_READ | STGM_SHARE_EXCLUSIVE,
STGFMT_FILE,0,NULL,NULL,IID_IPropertyStorage,reinterpret_cast<void**>(&pPropSetStg));
//Open function
DWORD LpStorage
::Open
(CString strFile,DWORD grfMode,STGFMT stgfmt,DWORD grfAttrs,STGOPTIONS* pstgOptions,void* reserved,REFIID riid,void** ppobjection)
{
USES_CONVERSION;
strFile_ = strFile;
TRACE (LINE_INFO + "Opening: %s\n\t%d remain open\n", LPCSTR(strFile_), __llGlobalOpen.GetCount());
//Parameters taken from Open is passed to StgOpenStorage function
DWORD result = StgOpenStorageEx(T2COLE( (LPCSTR)strFile),grfMode,
stgfmt,grfAttrs, pstgOptions,reserved,riid,ppobjection);
if (S_OK == result)
__llGlobalOpen.AddHead (this);
return result;
}
//NOTE the result returned by the
StgOpenStorageEx
is not S_OK
I just want to know where I am wrong ?
It would be helpful if you provide the error code.
However, you are using wrong castings forCString
to char pointer (LPCSTR
). It should beLPCTSTR
. Your code is only valid for non Unicode builds.
To avoid such mistakes, you should always use C++ casts rather than C casts. In this case whereCString
is used it is even better to use the corrsponding member function instead:
DWORD result = StgOpenStorageEx(T2COLE(strFile.GetString()),grfMode, stgfmt,grfAttrs, pstgOptions,reserved,riid,ppobjection);
[UPDATE]
You posted the error code as comment.
2147500034 is 0x80004002 which isE_NOINTERFACE
.
The correspoding message is 'The requested COM interface is not available'.
So you should check the value passed asriid
parameter of the StgOpenStorageEx function (Windows)[^].
As already suggested by Richard, you should show an example how the function is called (the parameter values).
这篇关于无法在MFC中打开FIle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!