我正在为学校编写一个程序,我有一个奇怪的问题,它不能在 Visual Studio 之外运行。无论是发布还是调试,无论是否运行调试,它都会在从 Visual Studio 运行时运行。但是,当我从资源管理器运行它时,它会打开并生成我需要的窗口,但当我运行“实际程序部分”时会失败。
就上下文而言,该程序从许多设备(辐射探测器)获取数据并进行一些基本处理,并将原始数据保存到文本文件中。我正在使用硬件供应商提供的 DLL 和一些 ActiveX 控件,程序基于他们的示例代码。当程序运行时,会出现一个带有“生成”按钮的简单框。点击它会打开相同的窗口,每个窗口都可以用来连接到不同的检测器。进行一些设置更改后,可以在每个设置上点击“开始”以启动一个线程,该线程不时轮询设备以获取数据等。当“开始”按钮被激活时,程序崩溃。
我正在使用 C++ 和 MFC。
我可以从整个事情中提取的唯一错误是: 0xC0150010: 被停用的激活上下文对于当前执行线程不活跃。
有什么想法吗?我可以提供任何其他有用的信息吗?
编辑1:
int nResponse = dlg.DoModal();
一旦中断,这是堆栈跟踪中唯一的代码,这是我的代码中的任何内容。
我运行了 Dependency Walker 并在目录中添加了一些 DLL 文件:
mcbcio32.dll
mcbloc32.dll
ieshims.dll
编辑2: depends.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"); }
谢谢
最佳答案
很有可能,当前工作目录不同,所以 DLL search path是不同的。可能正在加载不同版本的设备库。
Dependency Walker tool通常有助于解决这些问题。
关于c++ - 程序将无法在 Visual Studio 之外正常运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5365964/