简体   繁体   English

C.Winapi在.exe文件中包含DLL

[英]C++ Winapi Including DLL in the .exe file

I'm using MYSQL library, and libmysql.lib /.dll. 我正在使用MYSQL库和libmysql.lib /.dll。 My program cannot be working without the libmysql.dll When I'm trying to run my project without the dll I'm getting that error message. 如果没有libmysql.dll,我的程序将无法运行。当我尝试不使用dll的情况下运行项目时,我将收到该错误消息。 What I'm basically want to do is to put that dll in my .exe file. 我基本上想要做的是将该dll放入我的.exe文件中。 build the .exe file with that dll and make the program read it from himself. 使用该dll构建.exe文件,并使程序从他自己那里读取文件。 I mean, give the program to people with that dll inside. 我的意思是,将程序提供给内部带有该dll的人。 It is possible ? 有可能的 ?

I tried this section: embed DLL in MFC C++ EXE? 我尝试了本节: 在MFC C ++ EXE中嵌入DLL? But the program still asking for the dll .. (But I do see that the size of the .exe has been changed) so that dll has been added. 但是程序仍然要求dll ..(但是我确实看到.exe的大小已更改),因此已添加dll。 But the program still asking for the libmysql.dll .. All the point is to use it inside the .exe file.. thanks. 但是程序仍然要求libmysql.dll ..关键是要在.exe文件中使用它。.谢谢。

What you are asking for cannot be done if you statically link to the DLL at compile-time. 如果您在编译时静态链接到DLL,那么您所要求的将无法完成。 You need to dynamically link to the DLL at run-time instead, either by explicit calls to LoadLibrary() and GetProcAddress() to access the DLL functions directly, or by utilizing your compiler's delay-load functionality (which uses LoadLibrary() and GetProcAddress() internally, but hides that fact from your code). 您需要在运行时动态链接到DLL,方法是显式调用LoadLibrary()GetProcAddress()以直接访问DLL函数,或者利用编译器的延迟加载功能(使用LoadLibrary()GetProcAddress()内部,但在您的代码中隐藏了该事实)。 Either way, you can then store the DLL in your EXE's resources at compile-time, then extract the resource to a temporary file at run-time and load/use it as needed (you can't use the DLL from inside the EXE's resources directly. Well, there is a way to do it, but it is a VERY complicated and advanced technique, as it requires implementing your own executable loader that basically mimics what the OS's built-in executable loader already does). 无论哪种方式,您都可以在编译时将DLL存储在EXE的资源中,然后在运行时将资源提取到临时文件中,并根据需要加载/使用它(您不能从EXE的资源内部使用DLL。嗯,有一种方法可以做到,但是这是一种非常复杂和高级的技术,因为它需要实现自己的可执行加载器,该可执行加载器基本上可以模仿OS的内置可执行加载器已经执行的操作。 When you are done using the DLL, you can unload it from memory and delete the temp file. 使用完DLL后,可以将其从内存中卸载并删除临时文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM