程序在 Visual Studio 之外无法正常运行
我正在为学校编写一个程序,但有一个奇怪的问题,它无法在 Visual Studio 之外运行。无论是发布还是调试,无论是否运行调试,它都会在从 Visual Studio 运行时运行。但是,当我从资源管理器运行它时,它将打开并生成我需要的窗口,但当我运行“实际程序部分”时会失败。
对于上下文,该程序从多个设备(辐射探测器)获取数据并进行一些基本处理,并将原始数据保存到文本文件中。我使用硬件供应商提供的 DLL 和一些 ActiveX 控件,该程序基于他们的示例代码。当程序运行时,会出现一个带有“Spawn”按钮的简单框。点击此按钮将打开相同的窗口,每个窗口都可用于连接到不同的探测器。进行一些设置更改后,可以在每个设置上单击“开始”以启动一个线程,该线程不时轮询设备以获取数据等。当激活“开始”按钮时,程序会崩溃。
我正在使用 C++ 和 MFC。
我可以从整个事情中提取出的唯一错误是: 0xC0150010:正在停用的激活上下文对于当前执行线程来说不是活动的。
有什么想法吗?我可以提供其他有用的信息吗?
编辑1:int nResponse = dlg.DoModal();
这是堆栈跟踪中唯一的代码,一旦它破坏了我的代码中的任何内容。
我运行 Dependency Walker 并向目录添加了一些 DLL 文件:
mcbcio32.dll
mcbloc32.dll
ieshims.dll
编辑2: dependent.exe 不再出现错误。
这是“开始”代码:
void CCraneWowDlg::OnStart() { CStatic *pLatest = (CStatic *)GetDlgItem(IDC_LATEST); CEdit *pFilePath = (CEdit *)GetDlgItem(IDC_FILEPATH); CString strFilePath, strText; CFile dataFile; LISHDR myHeader; LPTSTR errText = "lol"; try { pFilePath->GetWindowText(strFilePath); if (!dataFile.Open(strFilePath, CFile::modeCreate | CFile::modeReadWrite, NULL)){ AfxThrowOleDispatchException(0xab,(LPCTSTR)"file open not work",0); } else { //lock the dropbox, set up the device. //TODO: lock dropbox pLatest->SetWindowText((LPCSTR)m_ConnCtl.Comm((LPCSTR)"STOP")); pLatest->SetWindowText((LPCSTR)m_ConnCtl.Comm((LPCSTR)"CLEAR_ALL")); pLatest->SetWindowText((LPCSTR)m_ConnCtl.Comm((LPCSTR)"START")); UpdateInfo(); //write the real header MakeHeader(&myHeader); dataFile.Write(&myHeader,256); dataFile.Close(); //end real header //begin getting data // AfxBeginThread((AFX_THREADPROC)GetData,(LPVOID)&dataFile,THREAD_PRIORITY_NORMAL,0,0,NULL); //TODO use thread ID to close it if stop is pressed // GetData(&dataFile); //make this a thread with a loop //use CThread CEdit *pSize = (CEdit *)GetDlgItem(IDC_SIZE); CEdit *pEvery = (CEdit *)GetDlgItem(IDC_EVERY); CEdit *pMax = (CEdit *)GetDlgItem(IDC_MAX); pSize->GetWindowText(strText); m_Size = _tstof(strText); pEvery->GetWindowText(strText); m_Every = _tstof(strText); pMax->GetWindowText(strText); m_Max = _tstof(strText); m_FilePath = strFilePath; m_Address = m_DListCtl.GetSelAddress(); OutputDebugString("here we are about to start the thread\n"); m_DataThread.m_pDlg = this; m_DataThread.Start(); //TODO: thread // GetData(); // dataFile.Close(); } } catch(COleDispatchException *pE) { pE->GetErrorMessage(errText, 30, NULL); pE->Delete(); pLatest->SetWindowText(errText); } UpdateInfo(); // m_ConnCtl.Comm((LPCSTR)"STOP"); }
谢谢
I am writing a program for school and I have the curious problem of it not running outside of Visual Studio. Whether release or debug, whether run with debugging or not, it will run when run from Visual Studio. However, when I run it from Explorer, it will open and spawn the windows I require, but fail when I run the "actual program part".
For context, the program takes data from a number of devices (radiation detectors) and does some basic processing as well as saving the raw data to a text file. I am using a DLL and some ActiveX controls provided by the hardware vendor, and the program is based upon their sample code. When the program runs, a simple box with a "Spawn" button appears. Hitting this will open up identical windows, which can each be used to connect to a different detector. After making some settings changes, one can hit "start" on each of these to begin a thread that polls the device for data from time to time, etc. The program crashes when the "start" button is activated.
I am using C++ with MFC.
The only error I can extract from the whole thing is:
0xC0150010: The activation context being deactivated is not active for the current thread of execution.
Are there any ideas? Is there any other information I can provide that will be useful?
EDIT1:int nResponse = dlg.DoModal();
This is the only bit of code in the stack trace once it breaks that is anything in my code.
I ran Dependency Walker and added a few DLL files to the directory:
mcbcio32.dll
mcbloc32.dll
ieshims.dll
EDIT2:
No more errors with depends.exe.
Here is the "start" code:
void CCraneWowDlg::OnStart() { CStatic *pLatest = (CStatic *)GetDlgItem(IDC_LATEST); CEdit *pFilePath = (CEdit *)GetDlgItem(IDC_FILEPATH); CString strFilePath, strText; CFile dataFile; LISHDR myHeader; LPTSTR errText = "lol"; try { pFilePath->GetWindowText(strFilePath); if (!dataFile.Open(strFilePath, CFile::modeCreate | CFile::modeReadWrite, NULL)){ AfxThrowOleDispatchException(0xab,(LPCTSTR)"file open not work",0); } else { //lock the dropbox, set up the device. //TODO: lock dropbox pLatest->SetWindowText((LPCSTR)m_ConnCtl.Comm((LPCSTR)"STOP")); pLatest->SetWindowText((LPCSTR)m_ConnCtl.Comm((LPCSTR)"CLEAR_ALL")); pLatest->SetWindowText((LPCSTR)m_ConnCtl.Comm((LPCSTR)"START")); UpdateInfo(); //write the real header MakeHeader(&myHeader); dataFile.Write(&myHeader,256); dataFile.Close(); //end real header //begin getting data // AfxBeginThread((AFX_THREADPROC)GetData,(LPVOID)&dataFile,THREAD_PRIORITY_NORMAL,0,0,NULL); //TODO use thread ID to close it if stop is pressed // GetData(&dataFile); //make this a thread with a loop //use CThread CEdit *pSize = (CEdit *)GetDlgItem(IDC_SIZE); CEdit *pEvery = (CEdit *)GetDlgItem(IDC_EVERY); CEdit *pMax = (CEdit *)GetDlgItem(IDC_MAX); pSize->GetWindowText(strText); m_Size = _tstof(strText); pEvery->GetWindowText(strText); m_Every = _tstof(strText); pMax->GetWindowText(strText); m_Max = _tstof(strText); m_FilePath = strFilePath; m_Address = m_DListCtl.GetSelAddress(); OutputDebugString("here we are about to start the thread\n"); m_DataThread.m_pDlg = this; m_DataThread.Start(); //TODO: thread // GetData(); // dataFile.Close(); } } catch(COleDispatchException *pE) { pE->GetErrorMessage(errText, 30, NULL); pE->Delete(); pLatest->SetWindowText(errText); } UpdateInfo(); // m_ConnCtl.Comm((LPCSTR)"STOP"); }
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最有可能的是,当前工作目录不同,因此 DLL 搜索路径是不同的。也许正在加载不同版本的设备库。
Dependency Walker 工具通常有助于解决这些问题。
Most likely, the current working directory is different, so the DLL search path is different. Maybe a different version of the device library is being loaded.
The Dependency Walker tool is often helpful in troubleshooting these problems.