运行时检查失败#3-变量'pStg'在使用时未初始化. [英] Run-Time Check Failure #3 - The variable 'pStg' is being used without being initialized.

查看:212
本文介绍了运行时检查失败#3-变量'pStg'在使用时未初始化.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对象pStg的运行时中断,指出运行时检查失败#3-使用变量" pStg"而未初始化."而且对于在代码中早于pStg使用的pIstor对象,我没有收到此错误.是什么原因?

Im getting runtime break for object pStg stating "Run-Time Check Failure #3 - The variable ''pStg'' is being used without being initialized.". And im not getting this error for pIstor object which is used earlier than pStg in the code. what is the reason??

EXTERN_C void wmain()
{
   HRESULT hr = S_OK;
  IStorage *pIstor;
  IStorage *pIstor1;
   WCHAR *pwszError = L"";
	
IStream* pStream;

   StgCreateDocfile(L"sumit444",STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &pIstor);
   hr=pIstor->CreateStorage(L"sumit444",STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,0, 0, &pIstor1);
	       
if (pIstor->CreateStream(L"MyStreamName",STGM_CREATE |STGM_READWRITE | STGM_SHARE_EXCLUSIVE,0, 0, &pStream) == S_OK)
{
  //some code 
}
	
SetCurrentDirectory(L"E:");

IStorage* pStg;

hr=StgCreateStorageEx(L"E",STGM_CREATE | STGM_READWRITE | STGM_TRANSACTED,STGFMT_STORAGE,0,0,0,IID_IStorage,(void**)pStg);
.
.// some code follows


提前感谢

[edit]已添加代码块-OriginalGriff [/edit]


Thanx in advance

[edit]Code block added - OriginalGriff[/edit]

推荐答案

^ ]说:
MSDN[^] says:
WINOLEAPI StgCreateStorageEx(
  __in   const WCHAR *pwcsName,
  __in   DWORD grfMode,
  __in   STGFMT stgfmt,
  __in   DWORD grfAttrs,
  __in   STGOPTIONS *pStgOptions,
  __in   PSECURITY_DESCRIPTOR *pSecurityDescriptor,
  __in   REFIID riid,
  __out  void **ppObjectOpen
);

这意味着您的pStg是OUT参数:即,指向接口指针变量的指针,该变量接收新存储对象上的接口的指针. pStg没有初始化为指向任何地方,所以会出现错误!

Which means that your pStg is an OUT parameter: I.e A pointer to an interface pointer variable that receives a pointer for an interface on the new storage object. pStg is not initialized to point anywhere, so you get an error!


问题应该是(void **)pStg",因为您必须传递pStg的地址.尝试使用"reinterpret_cast< void **>& pStg".
The problem should be "(void**)pStg" because you have to pass address of pStg. Try using "reinterpret_cast<void**> &pStg".
hr=StgCreateStorageEx(L"E",STGM_CREATE | STGM_READWRITE | STGM_TRANSACTED,STGFMT_STORAGE,0,0,0,IID_IStorage,reinterpret_cast<void**> &pStg);


这篇关于运行时检查失败#3-变量'pStg'在使用时未初始化.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆