启动应用程序时出现DLL问题 [英] Dll issue while launching the application

查看:72
本文介绍了启动应用程序时出现DLL问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用一个dll来包含该dll提供的功能.我安装了一个msi后得到了这个dll.但是在我的应用程序中,我有一个要求,例如如果用户尚未安装该msi,则我们必须显示一条警告消息(例如,尚未安装msi,我已经在我的应用程序的main()中实现了此代码)退出应用程序.

但是问题是,如果用户尚未安装msi,则在启动应用程序本身时会显示一条错误消息,因为它无法获取dll,并且这次控件甚至没有到达我编写代码的main().为此msi检查(通过注册表项).

是否有任何有效的方法来解决此问题..

I am using one dll in my application for including the functionality provided by that dll . This dll i am getting after installing one msi . But in my application i have a requirement like if the user has not installed that msi then we have to show one warning message(e.g msi has not installed , code for this i have implemented in the main() of my application ) and have to exit from the application .

But the problem is if the user has not installed the msi , then while launching the application itself its showing one error message since its not able to get the dll and this time control not even coming to my main() where i have written the code for this msi checking (through registry entry).

Is there any efficient way to resolve this issue ..

推荐答案

从您的描述中看来,您好像是在静态加载DLL.

解决方案是动态加载dll.然后,您可以检查是否已安装msi以及dll本身是否存在.

缺点是,如果您使用此dll中的许多函数,更新代码可能很繁琐,因为现在您需要将这些函数更改为函数指针!

一种折衷方法是使用延迟加载的DLL-请参见http://msdn.microsoft.com/zh-cn/library/151kt790.aspx

该dll的行为就像静态加载的dll一样,但实际上是在您的应用程序调用其功能之一时加载的.

但是,使用延迟加载的dll有一些限制.例如,延迟加载的dll无法导入数据.
From your description it looks like you are statically loading the DLL.

The solution would be to dynamically load the dll. Then you can check if the msi is installed and also whether the dll itself is present.

The disadvantage is that it can be tedious to update your code if you are using a lot of functions from this dll, since, you now need to change these functions to function pointers!

A compromise can be to use Delay loaded DLLs - see http://msdn.microsoft.com/en-us/library/151kt790.aspx

The dll would behave just like a statically loaded dll but would actually be loaded at the point when one of its functions are called by your application.

However, there are some limitations in using delay loaded dlls. For example, delay loaded dlls cannot import data.


启动助手如何? :):
How about a starting helper ? :) :
int main()
{
  HMODULE hLib(::LoadLibrary(_T("yourMainProcess.EXE")));
  if (!hLib) {
    ::MessageBox(NULL,
                 _T("Please install..."),
                 _T("Your pack"),
                 MB_OK | MB_ICONSTOP);
    return -1;
  }
  ::FreeLibrary(hLib);
  
  ::CreateProcess(/*Parameter list for yourMainProcess.EXE*/);
    
  return 0;
}


这篇关于启动应用程序时出现DLL问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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