MS C ++可执行文件刚刚开始失败 [英] MS C++ executable just started failing

查看:79
本文介绍了MS C ++可执行文件刚刚开始失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我突然发现应用程序已经运行了15年,并且可执行文件在过去的6个月内没有被重新编译。



我正在使用:

1.操作系统:Windows 10

2.编译器:Microsoft Visual Studio 2010

3.代码:Microsoft C ++ MFC SDK



突然,Microsoft程序CRecentFileList中的所有保存都失败[请参阅下面的Microsoft代码]。直到打印到屏幕后才会失败。对于从6个月前开始工作到目前为止的可执行文件,情况确实如此。并且发生在不同的Windows
10台机器上。



问题:

1.有什么方法可以解决这个问题吗? />
2.如果我无法修复它,我可以消除:ENSURE(SUCCEEDED(hr));添加(psi,strAppID);所以它不会失败?

3.我试过这个,它不承认我改变了它。如何让编译器重新编译并识别我chaned filelist.cpp?

4.是否有助于访问Microsoft Visual Studio 2015?



---------------------------------------------- -----
$




MICROSOFT CODE WITH CALL ....



失败在下面的代码中。



调用以下afxGlobalData.ShellCreateItemFromParsingName失败。

返回:hr = 0x800401f0 CoInitialize没有被称为。 (通常为hr == S_OK)

调用:lpWPath = 0x00a5eee0" C:\ winfree \ __small.fre"

$


filelist.cpp:

void CRecentFileList :: Add(LPCTSTR lpszPathName,LPCTSTR lpszAppID)

{

< span style ="white-space:pre"> if(!afxGlobalData.bIsWindows7)

{

添加(lpszPathName);

返回;

}



CString strAppID = lpszAppID == NULL? _T(""):lpszAppID;



#if(WINVER> = 0x0601)

ASSERT(AfxIsValidString(lpszPathName));
$


添加(lpszPathName);
$


HRESULT hr = S_OK;

< span style ="white-space:pre"> CComPtr< IShellItem> psi = NULL;



#ifdef UNICODE

hr = afxGlobalData .ShellCreateItemFromParsingName(lpszPathName,NULL,IID_IShellItem,reinterpret_cast< void **>(& psi));
$
#else

{

USES_CONVERSION;

LPOLESTR lpWPath = A2W(lpszPathName);

hr = afxGlobalData.ShellCreateItemFromParsingName(lpWPath,NULL, IID_IShellItem,(LPVOID *)& psi);  < ----------------------失败点

}

#endif



ENSURE(SUCCEEDED( hr));
$


添加(psi,strAppID);

#endif

}

解决方案

嗨Dick Stone,


感谢您在此发帖。


1。有没有办法解决这个问题?


根据错误消息,你错过了某处的CoInitialize。您需要调用
CoInitialize函数才能为您初始化COM库应用程序的线程。并注意到新应用程序应该调用
CoInitializeEx 而不是CoInitialize。 如果你想要使用Windows运行时,你必须调用Windows :: Foundation :: Initialize。请告诉我们你如何调用CRecentFileList :: Add
方法。这样我们就可以找到根本原因。   2。如果我无法修复它,我可以消除:确定(成功(小时));添加(psi,strAppID);这样它不会失败?


确定(成功(小时));不会阻止失败。如果你错过了CoInitialize,它仍然会导致问题。

3。我试过这个,它不承认我改变了它。如何让编译器重新编译并识别我chaned filelist.cpp?


您可以单击"清理",然后"构建"应用程序,或单击"重建"。


这里是您可以参考的文件。


https://msdn.microsoft.com/en-us/library/5tdasz7h.aspx?f=255&MSPPError=-2147217396

4。是否有助于访问Microsoft Visual Studio 2015?


您可以下载并尝试一下。


这是一个类似的案例,也许可以帮助你。


http://stackoverflow.com/questions/6633515/mfc-app-assert-fail -at-crecentfilelistadd-on-command-line-fileopen


最好的问候,

Sera Yu


I suddenly have a failure on an application has been working for 15 years, and the executable has not been recompiled for the last 6 months.

I am using:
1. Operating System: Windows 10
2. Compiler: Microsoft Visual Studio 2010
3. Code: Microsoft C++ MFC SDK

Suddenly, all saves fail in a Microsoft procedure CRecentFileList [see Microsoft code below]. It doesn't fail until after a print to screen. This is true of executables from 6 months ago that have been working un until now. and happens on different Windows 10 machines.

Questions:
1. Is there any way to fix this?
2. If I can't fix it, can I eliminate: ENSURE(SUCCEEDED(hr)); Add(psi, strAppID); so that it doesn't fail?
3. I tried this, and it doesn't recognize that I changed it. How do I get the compiler to recompile and recognize that I chaned filelist.cpp?
4. Would it help to go to Microsoft Visual Studio 2015?

---------------------------------------------------


MICROSOFT CODE WITH CALL....

The failure is in the code below.

Fails in call to afxGlobalData.ShellCreateItemFromParsingName below.
Returns: hr = 0x800401f0 CoInitialize has not been called. (normally hr==S_OK)
Called with: lpWPath = 0x00a5eee0 "C:\winfree\_small.fre"


filelist.cpp:
void CRecentFileList::Add(LPCTSTR lpszPathName, LPCTSTR lpszAppID)
{
if (!afxGlobalData.bIsWindows7)
{
Add(lpszPathName);
return;
}

CString strAppID = lpszAppID == NULL ? _T("") : lpszAppID;

#if (WINVER >= 0x0601)
ASSERT(AfxIsValidString(lpszPathName));

Add(lpszPathName);

HRESULT hr = S_OK;
CComPtr<IShellItem> psi = NULL;

#ifdef UNICODE
hr = afxGlobalData.ShellCreateItemFromParsingName(lpszPathName, NULL, IID_IShellItem, reinterpret_cast<void**>(&psi));
#else
{
USES_CONVERSION;
LPOLESTR lpWPath = A2W(lpszPathName);
hr = afxGlobalData.ShellCreateItemFromParsingName(lpWPath, NULL, IID_IShellItem, (LPVOID*)&psi);  <---------------------- Point of failure
}
#endif

ENSURE(SUCCEEDED(hr));

Add(psi, strAppID);
#endif
}

解决方案

Hi Dick Stone,

thanks for posting here.

1. Is there any way to fix this?

According to the error message, you have missed CoInitialize somewhere. You need to call the CoInitialize function in order to initialize the COM library for your application's thread. And notes that new applications should call CoInitializeEx instead of CoInitialize. If you want to use the Windows Runtime, you must call Windows::Foundation::Initialize instead. Please show us how do you call CRecentFileList::Add method. So that we could find the root cause. 2. If I can't fix it, can I eliminate: ENSURE(SUCCEEDED(hr)); Add(psi, strAppID); so that it doesn't fail?

The ENSURE(SUCCEEDED(hr)); won't prevent the failure. It will still cause the problem if you miss the CoInitialize .
3. I tried this, and it doesn't recognize that I changed it. How do I get the compiler to recompile and recognize that I chaned filelist.cpp?

You could would click "Clean", and then "Build" the app, or click "Rebuild".

Here is a document you could refer to.

https://msdn.microsoft.com/en-us/library/5tdasz7h.aspx?f=255&MSPPError=-2147217396
4. Would it help to go to Microsoft Visual Studio 2015?

You could download and try it.

Here is a similar case for you, maybe could be help of you.

http://stackoverflow.com/questions/6633515/mfc-app-assert-fail-at-crecentfilelistadd-on-command-line-fileopen

Best Regards,
Sera Yu


这篇关于MS C ++可执行文件刚刚开始失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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