Handmade Hero » Forums » Code » Day 021: DLL Dependancy Errors?
3 posts
#11698 Day 021: DLL Dependancy Errors?
10 months, 2 weeks ago

Hello All,
Bit of a newbie here following along, I'm on Day 21, live code editing and I'm running into an issue loading and unloading DLLs. I'm using Sublime and VS 2015.

When building and running from Sublime, the function pointers do populate correctly, however making a change in the code appears to have no effect. So I open up VS to debug, unsurprisingly the functions are blank because of the PDB file lock issue Casey mentions in the stream. However, I notice that the HMODULE is now NULL, reporting error 126.

According to StackOverflow this is due to a dependency error, so lo and behold I open up dependency walker and see a bunch of errors.
There's a bunch of DLLs, many more than seem relevant. All of them appear to be windows system32 or kernel32 related (judging from the names) so I'm not sure where the issue is. I'm also confused, why is this happening from VS but not Sublime?

Wish I could structure this question in a more educated way but I'm truly stumped. I'm downloading VS 2013 now to see if the issue lays somewhere in there. Any help would be much appreciated!

Mārtiņš Možeiko
1568 posts
1 project
#11700 Day 021: DLL Dependancy Errors?
10 months, 2 weeks ago

So what exactly dll files your binary depends? To see exact names launch following command in command-line:
dumpbin.exe /DEPENDENTS your_file.dll

Then copy&paste whatever you have under "Then Image has the following dependencies:" section.

And what do you mean by "functions are blank"? How functions are "blank" ?
3 posts
#11701 Day 021: DLL Dependancy Errors?
10 months, 2 weeks ago Edited by on April 16, 2017, 3:02 a.m.

Hey Martin,
The only dependency that appears is KERNEL32.dll, which is odd because from the dependency walker program I see many more dependencies all of which are children of KERNEL32.dll, which is loaded correctly, but yet all these child dependencies fail to load. I took a screenshot from dependency walker.

And by blank, I mean they are pointing to the empty stub function that we have the function point to when the .dll isn't loaded correctly.

Here's my build script:

@echo off

set CommonCompilerFlags= -MT -nologo -Gm- -GR- -EHa- -Od -Oi -WX -W4 -wd4505 -wd4201 -wd4100 -wd4189 -DHANDMADE_INTERNAL=1 -DHANDMADE_SLOW=1 -DHANDMADE_WIN32=1 -FC -Z7 -Fmwin32_handmade.map
set CommonLinkerFlags= -incremental:no -opt:ref user32.lib gdi32.lib winmm.lib

REM TODO - can we just build both with one exe?

IF NOT EXIST ..\..\build mkdir ..\..\build
pushd ..\..\build

REM 32-bit build
REM cl %CommonCompilerFlags% ..\handmade\code\win32_handmade.cpp /link -subsystem:windows,5.1 %CommonLinkerFlags%

REM 64-bit build
cl %CommonCompilerFlags% \code\handmade_game_engine.cpp -Fmhandmade_game_engine.map /LD /link /EXPORT:GameGetSoundSamples /EXPORT:GameUpdateAndRender
cl %CommonCompilerFlags% \code\win32_handmade_follow.cpp -Fmwin32_handmade_follow.map /link %CommonLinkerFlags%

Mārtiņš Možeiko
1568 posts
1 project
#11703 Day 021: DLL Dependancy Errors?
10 months, 2 weeks ago Edited by Mārtiņš Možeiko on April 16, 2017, 5:51 a.m.

You should ignore dependencies of system libraries. kernel32.dll will always work, so there's no point of hunting its dependencies. DLL files can have lazy imports - that means they reference some dll with some functions, but it's not a big deal if it does not exist, you will still be able to load dll file, it simply should not call the functions which are missing. This is called Delay Load Import.

Maybe the problem is that VS has not yet fully finished generation of .dll file when game tries to load it. Try the lock solution introduced in day 39: https://hero.handmade.network/episode/code/day039#3158
4 posts
#11722 Day 021: DLL Dependancy Errors?
10 months, 1 week ago Edited by on April 18, 2017, 11:41 p.m.

Might be a long shot, but isn't day 21 the one with the hardcoded dll path? If so you might want to check if the project working directory is the same with the build directory. Null on the return value means that the dll was not found.

Also looking at your build.bat, there is one more thing you could check. In one of the episodes there was a random pdb name added to the dll build line (/LD /link /PDB:"handmade_%random%.pdb" /EXPORT:GameGetSoundSamples).

Other than that can't think of anything else, and I'm using a similar setup (VS2017 & Sublime).

Edit: Don't rely on StackOverflow for answers >_<