我有个动态库,程序中动态加载。但是加载失败了,getlasterror() 返回 126,动态库依赖,路径都好着呢! 我把代码换个位置,竟然加载成功了。(就在同一代码段,往上移几行,竟然加载成功了,(中间就是几个if判断)。) 高手指点一下,这怎么回事啊?谢谢~!

解决方案 »

  1.   

    我用depends查看依赖都好着 啊,环境变量?
      

  2.   

    126 The specified module could not be found.
    路径不对吧 
      

  3.   

    IDE调试时,和直接双击运行,两个得当前路径是不同的
      

  4.   

    // TODO: Add your control notification handler code here
    //check the input paramters
    UpdateData();
    ShowWindow(SW_HIDE);
    SixS ss;
    BOOL tf = ss.LoadDLL("6S_DLL.dll");//就这个位置可以,往下面移几行就不行了
    if(!tf)
    {
    int err = GetLastError();
    AfxMessageBox("加载DLL失败!");
    PostMessage(WM_CLOSE,0,0);
    return ;
    } if(  m_strInFile      ==_T("")|| m_strInFile      ==_T("")
    || m_inSpatialRes  == 0.0 || m_outSpatialRes  ==0.0
    || m_inSpectralRes == 0.0 || m_outSpectralRes ==0.0) 
    {
    AfxMessageBox("Invalid Parameters!");
    PostMessage(WM_CLOSE,0,0);
    return;
    }

    if(header.Interleave!=0)
    {
    AfxMessageBox("Only BSQ Interleave Supported!");
    PostMessage(WM_CLOSE,0,0);
    return;
    }
    //check the waveLength data
    if(header.pWavelength == NULL)
    {
    CDialogWaveFile dlgwave;
    if(dlgwave.DoModal() == IDOK)
    {
    UpdateData();
    m_WaveFile = dlgwave.m_WaveFile;
    }
    if(m_WaveFile==_T(""))
    {
    AfxMessageBox("Invalid WaveLength File!");
    PostMessage(WM_CLOSE,0,0);
    return;
    }
    }

    //define transfor parameters
    SimulationInfo *pParams = new SimulationInfo();
    pParams->pSimulation    = this;
    pParams->pProgress      = NULL;
    pParams->pSixSACM       = NULL; //6s atmosphere correction
    if(m_Atomsphere)
    {
    CSixSAtomsphereCorrection *pSixSACM = new CSixSAtomsphereCorrection();
    CSixSAtomsphereCorrection sixSACM;
    if(sixSACM.DoModal() ==IDOK)
    {
    UpdateData();
    *pSixSACM = sixSACM;
    pParams->pSixSACM = pSixSACM;
    }
    }
     
    //Create Progress Bar...
    pParams->pProgress  = new CSixSACMProgress();
    pParams->pProgress->Create(IDD_DIALOG_6SACM_PROGRESS,this->GetParent());
    pParams->pProgress->ShowWindow(SW_SHOW);

    CWinThread *pThread = AfxBeginThread(SimulationThreadProc,pParams,THREAD_PRIORITY_HIGHEST);
      

  5.   

     ss;
    BOOL tf = ss.LoadDLL("6S_DLL.dll");
    加载dll 写在一个类 SixS 里面的;就是调用了LoadLibrary()
      

  6.   

    就是我在对话框的button相应函数中去加载dll,是不是这个有问题?(关键有时候不用加载,放在这里面)