mfc工程拷贝到另一台电脑,提示“无法启动应用程序,请重装系统”错误

解决办法:

                 项目属性页,项目默认值->MFC的使用,将“在共享DLL中使用MFC”,改为"在静态库中使用MFC"。

原因:

1."Choosing Use MFC In A Shared DLL minimizes your application's executable file size by allowing MFC to be accessed from a DLL. If you choose Use MFC In A Static Library instead, Visual C++ links MFC code into your application's EXE file and the file size grows considerably. Static linking uses disk space less efficiently than dynamic linking because a hard disk containing 10 statically linked MFC applications contains 10 copies of the same MFC library code. On the other hand, an application that is statically linked can be run on any PC, whether or not the MFC DLL is present. It's your call whether to link to MFC statically or dynamically, but remember that if you distribute a dynamically linked EXE, you'll need to distribute the DLL that houses MFC, too. For a release-build MFC application created with Visual C++ version 6, that DLL is named Mfc42.dll if the program uses ANSI characters and Mfc42u.dll if it uses Unicode characters."
摘自<<programming windows with MFC>>

2.静态链接,将DLL库的内容,直接添加到生成的EXE中,并作为EXE文件的一个静态部分运行。作为静态链接,你不需要担心运行时需要的相关库文件,因为都链接到EXE文件中了。
动态链接,生成的EXE文件,公包括EXE内部的内容,运行时,根据需要,加载相应的DLL。作为动态链接,你需要将运行时相关的DLL库文件放到相关的地方(1、与EXE同文件夹;2、系统环境变量Path指定的其它路径)。

关于内存访问,使用静态链接,在DLL中动态分配(new)的内存,只能由DLL回收(delete),强制EXE回收可能会有异想不到的结果。动态链接,在DLL里动态分配(new)的内在,可由EXE回收(delete)。

3.共享DLL, EXE小,但是如果系统中没有这个DLL,就无法运行。

静态链接,是把代码链接到EXE中,EXE大,但是不依赖那个DLL了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhang11wu4

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值