Article View: comp.windows.ms.programmer
Article #1594Re: Finding full pathname of Windows Executable
From: Eric Bergman-Terrell
Date: Sun, 10 Mar 1991 19:00
Date: Sun, 10 Mar 1991 19:00
47 lines
1391 bytes
1391 bytes
Well, (I think) that I've answered my question:
Here's how I'm opening a file which exists in the same directory as my
program:
BOOL file_exists(char *filename)
/*
Returns TRUE iff the specified filename exists.
*/
{
OFSTRUCT of;
return OpenFile((LPSTR) filename, &of, OF_EXIST) != -1;
}
void open_file(HWND hwnd, const char *filename)
/*
Attempt to open the specified file.
*/
{
char pathname[MAXPATH], drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE],
ext[MAXEXT];
/* Get full pathname of file. */
GetModuleFileName(GetModuleHandle("program.exe"), pathname, MAXPATH);
fnsplit(pathname, drive, dir, file, ext);
sprintf(pathname, "%s\%s\%s", drive, dir, filename);
if (file_exists(pathname))
input_file = fopen(pathname, "r");
if (input_file == (FILE *) NULL)
MessageBox(hwnd, "File not found", "", MB_OK | MB_ICONSTOP);
}
IS THERE A BETTER WAY?
Terrell
Technical Details
Message-ID:
<1991Mar10.190023.6036@isis.cs.du.edu>Path:
arc1-ca.pugleaf.net!utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uunet!isis!ebergmanReferences:
<1991Mar10.164713.26980@isis.cs.du.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uunet!isis!ebergman From: ebergman@isis.cs.du.edu (Eric Bergman-Terrell) Newsgroups: comp.windows.ms.programmer Subject: Re: Finding full pathname of Windows Executable Message-ID: <1991Mar10.190023.6036@isis.cs.du.edu> Date: 10 Mar 91 19:00:23 GMT References: <1991Mar10.164713.26980@isis.cs.du.edu> Reply-To: ebergman@isis.UUCP (Eric Bergman-Terrell) Organization: Math/CS, University of Denver Lines: 47