如果应用程序从安装选项启动,则LoadLibrary失败,错误代码为126 [英] LoadLibrary failed with error code 126 if app started from installation option

查看:228
本文介绍了如果应用程序从安装选项启动,则LoadLibrary失败,错误代码为126的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个应用程序,并且安装在不同的文件夹中,分别称为应用程序A和B,A是主应用程序,B是COM模块,A在启动后将通过COM API启动B,需要一些DLL B启动时由B加载,如果我通过双击A的快捷方式启动A,一切正常,但是如果我安装A,并通过在安装的最后一个对话框中检查start A选项来启动A,则B为启动,但其中一个DLL加载失败,错误代码为126(ERROR_MOD_NOT_FOUND),如果我退出并通过双击快捷方式再次重新启动,它将再次起作用.

I have two application and install in different folders, let call it app A and B, A is main application and B is an COM module, A will start B through COM API after A started, there are some DLLs need to be loaded by B while B started, if I start A by double click the shortcut of A, every thing is ok, but if I install A, and start A by check the start A option in the last dialog of the installation, then B is started, but one of the DLLs load failed with error code 126 (ERROR_MOD_NOT_FOUND), if I exit and restart again by double click the shortcut, it works again.

已经做了一些谷歌,似乎从快捷方式启动和安装之间的唯一区别是当前目录,即,如果从安装选项开始,则与从带有cmd的安装程序包文件夹开始一样,例如打开cmd,切换到以下文件夹安装程序包,然后使用完整路径启动应用程序A,我已经尝试过了,效果也很好.

Already do some googles and seems the only difference between start from shortcut and installation is current directory, ie, if start from installation option, same as start from the installer package folder with cmd, like open cmd, switch to the folder of installer package, then start app A with full path, I have try this, also works well.

我的安装程序包是由installshield构建的.

My installer package is build by installshield.

有人对此问题有一些线索吗?

Is anyone have some clues about this issue?

  1. 已经尝试将当前目录切换到A和B的安装路径,但都无法解决此问题.
  2. 已经尝试将dll目录设置为B的安装路径,它也是失败的DLL的路径,也行不通.
  3. 已经尝试用完整路径加载DLL,也失败了.

    //SetCurrentDirectory(L"C:\Program Files (x86)\install path of A"); <<<not work
    //SetCurrentDirectory(L"C:\Program Files (x86)\install paht of B");   <<<not work
    //SetDllDirectory(L"C:\Program Files (x86)\DLL path");   <<<not work
    //m_hLibrary = LoadLibrary((LPCWSTR)DLL full path);   //not work
    m_hLibrary = LoadLibrary((LPCWSTR)dllName.c_str());   //failed with error code 126

推荐答案

听起来您已经诊断出症状.解决这些问题可能很棘手,因为至少某些版本的InstallShield调用API降低了在建立应用程序文件夹之前加载意外DLL的能力.当您直接从安装程序启动流程时,这些调用的效果似乎会延续到您的流程中.

It sounds like you have diagnosed the symptoms. Solving them may be tricky, as at least some versions of InstallShield call APIs that reduce the ability to load unexpected DLLs before an application folder is established. It appears that the effects of these calls carry over to your process when you launch it directly from the installer.

因此,首先,过度简化的选项1:从向导的最后一页中删除该选项以启动您的应用程序. ,问题消失了.但这可能会使其他人感到不开心.

So first, oversimplified option 1: remove the option to start your app from the last page of the wizard. Poof, problem goes away. But this probably makes someone else unhappy.

让我们尝试深入探讨正在发生的事情.根据某些

Instead let's try to dive into what's going on. Depending on the exact version of InstallShield, it may be calling some combination of APIs, but the most likely culprit is a call to SetDllDirectory(L""); According to some quick research, this should only have an effect on implicitly loaded DLLs in child processes, but that doesn't appear to be the scenario you describe.

您已经尝试通过显式添加目录来撤消此调用;这是我推荐(但未经测试)的选项2和3:

You've tried undoing this call by explicitly adding a directory; here are my recommended (but untested) options 2 and 3:

  • As documented on SetDllDirectory, call SetDllDirectory(NULL) to restore the default search order, or
  • Call SetDllDirectory or AddDllDirectory to add your folder, and then call LoadLibraryEx(..., LOAD_LIBRARY_SEARCH_USER_DIRS)

这篇关于如果应用程序从安装选项启动,则LoadLibrary失败,错误代码为126的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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