Question

I'm using MYSQL library, and 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. What I'm basically want to do is to put that dll in my .exe file. build the .exe file with that dll and make the program read it from himself. I mean, give the program to people with that dll inside. It is possible ?

I tried this section: embed DLL in MFC C++ EXE? 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. But the program still asking for the libmysql.dll .. All the point is to use it inside the .exe file.. thanks.

Was it helpful?

Solution

What you are asking for cannot be done if you statically link to the DLL at compile-time. 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). 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). When you are done using the DLL, you can unload it from memory and delete the temp file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top