-getcwd does not return it at least when debugging with VS 2010.
-i have no access to main's arguments because of the user interface kit i'm using
so is there anything to do?
PS. please note the restrictions before tagging this as duplicate
-getcwd does not return it at least when debugging with VS 2010.
-i have no access to main's arguments because of the user interface kit i'm using
so is there anything to do?
PS. please note the restrictions before tagging this as duplicate
Use GetModuleFileName() and pass NULL as the first argument:
DWORD last_error;
DWORD result;
DWORD path_size = 1024;
char* path = malloc(1024);
for (;;)
{
memset(path, 0, path_size);
result = GetModuleFileName(0, path, path_size - 1);
last_error = GetLastError();
if (0 == result)
{
free(path);
path = 0;
break;
}
else if (result == path_size - 1)
{
free(path);
/* May need to also check for ERROR_SUCCESS here if XP/2K */
if (ERROR_INSUFFICIENT_BUFFER != last_error)
{
path = 0;
break;
}
path_size = path_size * 2;
path = malloc(path_size);
}
else
{
break;
}
}
if (!path)
{
fprintf(stderr, "Failure: %d\n", last_error);
}
else
{
printf("path=%s\n", path);
}
C:\Program Files\myapplication\my.exe.sizeof(exe_path) by itself.