Handmade Hero»Forums»Code
5 posts
Day 22 - Why not use relative paths?
On day 22 Casey got the EXE path using a windows function and then made an concat function to build a path to the dll and temp dll.

Why did he not just use a relative path, e.g. "../../build/handmade.dll".

Thanks for the help!
19 posts
Day 22 - Why not use relative paths?
Edited by Bigpet on
Because the "current working directory" (which is what "relative paths" are relative to) and the directory the *.exe is in are not always the same.

You can test it yourself. Make simple executable like this

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include <stdio.h>


int main(int argc, char **argv)
{
	FILE *f = fopen("./test.txt","r");
	if (f == NULL)
	{
		printf("File not found\n");
	}
	else
	{
		printf("File found\n");
	}
	return 0;
}


Then if you create a "test.txt" in the same diretory as the executable you will see a different output for

1
2
3
4
5
C:\Location\to\exe> test.exe
File found
C:\Location\to\exe> cd ..
C:\Location\to> exe\test.exe
File not found


So if you code the path just relative to the cwd then shortcuts to your your game exe may suddenly not work (which is a terrible user experience).
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
Day 22 - Why not use relative paths?
Yes - I just wanted to make sure that the code would work no matter where people were building the EXE. I didn't want to force them to build it in the same relative path to the data directory (the working directory of the game) as I was.

- Casey
5 posts
Day 22 - Why not use relative paths?
Edited by Brainversation on
Thanks Bigpet and Casey for your answers. I should have guessed because you keep saying you want the game to always work, AKA bullet proof.

I appreciate the quick responses!
25 posts
None
Day 22 - Why not use relative paths?
By day 24 trying to load the loop_edit.hmi from the current dir is not working for me.

State->OnePastLastEXEFileNameSlash and State->EXEFileName are empty when I try to record the input.

Using a hardcoded path "c:\\myGame\\handmade\\build", works fine.

I have no idea why State-> changes their values and everything fails.

Any idea? Or have that been fixed in a future stream?
Mārtiņš Možeiko
2559 posts / 2 projects
Day 22 - Why not use relative paths?
Try to debug Win32GetEXEFileName function, and see what GetModuleFileNameA function fills in State->EXEFileName array and what value it returns.