Pelles C forum

C language => Beginner questions => Topic started by: Claudy on December 26, 2007, 02:10:36 PM

Title: filename extracting
Post by: Claudy on December 26, 2007, 02:10:36 PM
hi,

How can I get the filename of an exe file, from within that executable, while it is running, with the condition that the filename must be extracted BEFORE any window is created?

In other words: I run 'MyApp.exe', in that app before creating any window, I wish to get the filename "MyApp" in a string, extracted from 'MyApp.exe'.
Is this possible?

Claude Put     Belgium
Title: Re: filename extracting
Post by: TimoVJL on December 26, 2007, 03:14:27 PM
Use GetModuleFileName()
You get programname with path

Code: [Select]
int nIdx, nLen;
char szExe[260], szTitle[80];

GetModuleFileName(0, szExe, sizeof(szExe));
strcpy(szTitle, strrchr(szExe, '\\')+1);
nLen = strlen(szTitle);
if (nLen > 4) szTitle[nLen-4] = 0;

Title: Re: filename extracting
Post by: Claudy on December 31, 2007, 09:47:34 PM
Thank you timovjl, just what I needed...

Put Claude   Belgium