Using VLD, Dynamic load DLL failed - c++

We have a windows Application, some DLLs are dynamic loaded using LoadLibraryW(). These Dlls are put in different Directory。 When we turn on VLD memory leak check, these DLLs failed to load. It seems like not search folders normally when load library. When we turn off VLD, the Application can be Started normally. Is anyone know the reasons? Thanks.
We try to load Dll in the same folder of main application, it can be loaded successfully. But Dlls in children folders can not be loaded。

Related

Plugin DLL can't locate its DLL dependencies

I have a plugin application (.DLL) that links dynamically to multiple other QT DLLs.
When the plugin is loaded in the third party software, it fails to find the dependencies which are located exactly in the same folder as the plugin DLL.
The structure looks like this:
myplugin.dll
platforms\
qwindowsd.dll
QtQml\
qmlplugind.dll
...
The executable of the software that loads the Plugin is installed under C:/Program Files/MySoftware/Application.exe
Weirdly enough, when I copy the contents of my packaged plugin (dlls and its dependencies) directly into the software's executable directory, next to the executable, it works like a charm, and the plugin is able to find all its DLLs in that directory. So my guess is the DLL lookup isn’t appropriate?
This might relate to this: Search path for a DLL referenced by a plug-in DLL
but the solution to load every QT dll explicitly seems wrong.
Any help on that matter would be appreciated. Thanks
EDIT:
I tried to put the path to where the DLLs are explicitly in the PATH variable without success.

How do I control c++ DLL debug symbols loading?

I have an EXE application running in debug mode that loads a DLL at runtime.
When I load the dll it automatically loads the dll's debug symbols for it.
But when I call FreeLibrary() on the dll the symbols won't get unloaded.
That is a problem for me because I use cl.exe to rebuild the DLL while the EXE is running so it needs to be freed and unloaded before I rebuild it.
here is the visual studio runtime debug console output when I load and unload the DLL
'Editor.exe' (Win32): Loaded GameAssembly.dll'. Symbols loaded. <--- automatically loads the symbols when I load the dll
'Editor.exe' (Win32): Unloaded GameAssembly.dll' <--- Dosen't unload the symbols (I know so because when I try to rebuild the dll I get the error (LNK1201 error writing to program database 'GameAssembly.pdb'; check for insufficient disk space, invalid path, or insufficient privilege)
and the functions I use to load and free the dll:
m_DLL = LoadLibraryA("GameAssembly.dll");
FreeLibrary((HMODULE)m_DLL);
now I want a way to unload the symbols when I free the dll, Any idea on how it's done ?
The symbols are not loaded in the app itself, they are loaded in Visual Studio's debugger. The good news is that what you are trying to do works just fine as long as you are not debugging the application.
Unfortunately, there is no way to unload symbols from a debugging session (as far as I know).
One way to fix this would be to tell Visual Studio to simply not load those symbols in the first place. You can do that from the modules window. However, this will prevent you from debugging GameAssembly.dll.
So the only alternative is to not be debugging when you rebuild/reload the dll. To do this, you have to create multiple debugging sessions for a single run of your app. Here's how you go about it
Start debugging the application as you normally would.
When you want to rebuild the dll:
Unload the dll
Detach the debugger by using Debug -> Detach All
Rebuild the DLL
Restart debugging the app by using Debug -> Attach to process
Reload the DLL
The order of the steps can be swapped around a bit, of course. As long as you detach before rebuilding, and don't reload the dll until after the build is done, you should be ok.

Error when launching application

I have rebuilt the QGIS code on VC2008 on Windows 7.
I have all the correct DLLs in the folder of the exe, and can see that it knows where the QT DLLs are.
When I launch the app, I get this error:
The procedure entry point ??4QPixmap##QAEAAV0#$$QAV0##Z could not be
located in the dynamic link library QtGui4.dll
I'm not sure where to start to get this working. I checked the QtGUI4.dll to see that it is loading, with a dummy app. It seems fine.
Any help would be great.
Posting it as an answer since my hunch turned out correct:
This error shows that your application was loading the wrong Qt DLLs. For whatever reason, it was finding and loading DLLs different from the DLLs against which it was built. In your case it turned out it was finding Qt4 built for VS2010 DLLs, while it needed Qt4 built for VS2008.
The solution is to make sure it always finds the correct DLLs - place the correct DLLs in the EXE's folder, as this is usually the first place it looks for for DLLs. On Windows, it's not a good idea to rely on %PATH% or on the current directory.

Deploying Qt application using QtMultimedia in release mode

I am developing a Qt 5.0 dekstop application using mingw47. I use QtMultimedia in this application to record and play audio. I have tested it for debug and it works. When I try to build it for release and run the executable file, I can't play the audio file that can normally be played in debug mode. I've added the following dlls before running the executable file:
D3D_Compiler_43.dll,
icudt49.dll,
icuin49.dll,
icuuc49.dll,
libEGL.dll,
libgcc_s_sjlj-1.dll,
libGLESv2.dll,
liblibmpeg2_plugin.dll,
libstdc++-6.dll,
libwinpthread-1.dll,
Qt5Core.dll,
Qt5Gui.dll,
Qt5Multimedia.dll,
Qt5Network.dll,
Qt5Widgets.dll,
Qt5Xml.dll,
plugins/platforms/(all dlls),
plugins/mediaservice/(all dlls),
plugins/playlistformats(all dlls)
What is probably wrong? Or what other dlls am I missing?
UPDATE: Use windeployqt.exe! It works really well.
http://doc.qt.io/qt-5/windows-deployment.html#the-windows-deployment-tool
The simplest way to use windeployqt is to add the bin directory of
your Qt installation (e.g. ) to the PATH variable and then
run:
windeployqt <path-to-app-binary>
While you are running your application in release mode (when it is working, ran from inside Qt Creator), execute depends.exe and point it at the application.
Make note of all the dlls that are referenced from your Qt folder.
Alternate way if you want to take more time with it:
You can figure it out by hand by trying to delete files because Windows won't let you delete a folder or a dll while it is in use. So you could go and make a back up of your Qt installation, and then run you application, make sure it has connected to all the dll's it is going to use, and then try to delete folders and files in your Qt installation. Windows won't let you delete files that are in use by your release.
Also here is how Windows resolves dll's if you wanted to know:
http://msdn.microsoft.com/en-us/library/7d83bc18(v=vs.80).aspx
EDIT: Also, you don't need to make the folder called plugins in your exe directory. It should be something like this:
Qt 4.x:
./myexe.exe
./QtCore.dll
./imageformats/qjpegd4.dll // Note: there isn't a "plugins" folder here
Qt 5.x: (take from here)
The executable ./plugandpaint.exe
The Basic Tools plugin ./plugins/pnp_basictools.dll
The ExtraFilters plugin ./plugins/pnp_extrafilters.dll
The Qt Windows platform plugin ./platforms/qwindows.dll
The Qt Core module ./Qt5Core.dll
The Qt GUI module ./Qt5Gui.dll
The Qt Widgets module ./Qt5Widgets.dll
Also run qDebug() << QApplication::libraryPaths(), and make note of paths that are searched for dlls on your computer.
Hope that helps.
All of the DLL's in your list that have their import libraries linked to the application will be automatically loaded by the OS. If any of them are missing you will get a dialog telling you which DLL it failed to load. The only ones that look like they might be loaded manually by the application are the plugins. Make sure you are telling the QT multimedia system to load the them. Also make sure you check the error codes returned by the multiamedia manager.
Given your recent comment that the audio plays in debug mode but not in release mode is a good indication you have put the plugin DLL's in the wrong place. When you launch your application from Explorer or the command line the plugins directory needs to be in the same directory as the application. Your directory structure should look something like below
c:\stackoverflow\myprogram.exe
c:\stackoverflow\plugins\platforms\(all dlls)
c:\stackoverflow\plugins\mediaservice\(all dlls)
c:\stackoverflow\plugins\playlistformats\(all dlls)
c:\stackoverflow\D3D_Compiler_43.dll
c:\stackoverflow\icudt49.dll
... other dll's here...
c:\stackoverflow\Qt5Network.dll
c:\stackoverflow\Qt5Widgets.dll
c:\stackoverflow\Qt5Xml.dll
I've found the answer. Now my application works. It can play audio file while running the executable file.
Although not listed in depends.exe, we should add the following dlls when using QMediaPlayer:
Qt5MultimediaWidgets
Qt5OpenGL
Here is the reference: https://bugreports.qt-project.org/browse/QTBUG-30172

Debug version runs but release gives 0xc000007b - missing dlls?

When running my Visual Studio C++ application debug version through VS2010 by Project Only > ProjectName the generated exe runs well. However when I generate a release version and go to the folder where the exe is created I get the following error:
The application was unable to start correctly (0xc000007b). Click Ok to close the application
The files in the folder is only the exe file whereas my project uses various boost libraries.
Is it possible that its giving this message because of the missing boost dlls ? Is there a way to make the compiler paste all the necessary dlls in the exe folder.
Is there any way to launch the release version from VS2010 like we have for the debug version as in Debug >> Start new instance
I hate when that happens. It could be the fact that its missing the bloost DLL's: the easiest way to fix this is to add the folder to the Path environment variable. Sadly enough, we don't have enough information from your post to confirm that this is the problem. Common other problems include: you are linking to libraries that were built for a different architecture/are using a different runtime library, you are missing other 3rd party dlls, the .lib file you used in the linker is pointing to a different version of the code than the dll you are pointing to...the list goes on.
As for copying the dlls at runtime, you can do this using the custom build events [http://msdn.microsoft.com/en-us/library/e85wte0k%28v=vs.80%29.aspx]. Just write a batch script that copies the dlls as a "Post Build Event" and you should be good to go, but I'd suggest the Path way first.