程序无法在Visual Studio外部正常运行

时间:2011-03-20 00:40:10

标签: c++ visual-studio dll

我正在为学校编写一个程序,我有一个奇怪的问题,就是它不能在Visual Studio之外运行。无论是发布还是调试,无论是否运行调试,它都将在从Visual Studio运行时运行。但是,当我从资源管理器运行它时,它将打开并生成我需要的窗口,但是当我运行“实际程序部分”时失败。

对于上下文,程序从许多设备(辐射探测器)获取数据并进行一些基本处理以及将原始数据保存到文本文件。我正在使用DLL和硬件供应商提供的一些ActiveX控件,该程序基于他们的示例代码。程序运行时,会出现一个带有“Spawn”按钮的简单框。点击此将打开相同的窗口,每个窗口可用于连接到不同的探测器。在进行一些设置更改后,可以在每个设备上点击“开始”以开始一个不时轮询设备以获取数据的线程等。当“启动”按钮被激活时,程序崩溃。

我正在使用C ++和MFC。

我可以从整个事情中提取的唯一错误是: 0xC0150010:当前执行的线程未激活的激活上下文无效。

有什么想法吗?我能提供的其他信息是否有用?

EDIT1:
int nResponse = dlg.DoModal();
这是堆栈跟踪中的唯一一段代码,一旦它破坏了我的代码中的任何内容。

我运行了Dependency Walker并在目录中添加了一些DLL文件:
mcbcio32.dll
mcbloc32.dll
ieshims.dll

EDIT2: 使用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");
}

由于

1 个答案:

答案 0 :(得分:1)

最有可能的是,当前工作目录不同,因此DLL search path不同。可能正在加载不同版本的设备库。

Dependency Walker tool通常有助于解决这些问题。