char aExt[_MAX_EXT]; if(*pFileName != '.')   { aExt[0] = '.'; aExt[1] = '\0'; strcat(aExt, pFileName); pFileName = aExt; }
BOOL FEU_FindExecutable(const char *pFileName, char *pExecutable, BOOL bIdentity, BOOL bExtension) {    BOOL bRetval = FALSE;    BOOL bFound = FALSE;    BOOL bFreeFileName = FALSE;        char aViewer[_MAX_PATH];    memset(aViewer, 0, sizeof(aViewer));    //  pFileName may not be a file name, but an extension.    //  We want to support just extensions for ease, so check on it.    if(bExtension && pFileName) {        //  We have an extension.        //  Fill out the rest of the name.        bFreeFileName = TRUE;        pFileName = (const char *)WH_TempFileName(xpTemporary, "G", pFileName);    }    if(!bFound && pFileName && *pFileName) {        //   Does pFileName actually exists, if not we will need to         //      create it temporarily so that ::FindExecutable will work.        BOOL bCreatedFile = FALSE;        if(_access(pFileName, 00) != 0) {            HFILE hCreate = _lcreat(pFileName, 0);            if(hCreate != HFILE_ERROR) {                bCreatedFile = TRUE;                _lclose(hCreate);            }        }        HINSTANCE hRet = FindExecutable(pFileName, NULL, aViewer);        if((int)hRet > 32) {            //  Found a viewer.            bFound = TRUE;        }                /* Cleanup */        if(bCreatedFile) {            _unlink(pFileName);        }    }    //  Do we fill in the return value?    //  Note that we fill it in regardless of the bIdentity flag.    if(pExecutable)  {        strcpy(pExecutable, aViewer);    }    //  Decide return value based on bIdentity if an EXE found.    if(bFound)   {        if(bIdentity) {            bRetval = TRUE;        }        else {            //  Must make sure executable and filename are not the            //      same.            //  Do a case insensitive comparison.            char *pCompareFile = (char *)pFileName;            char *pCompareExe = (char *)aViewer;                #ifdef XP_WIN32            //  On win32, we compare short names to avoid any confusion.            char aShortFile[_MAX_PATH];            char aShortExe[_MAX_PATH];                        memset(aShortFile, 0, sizeof(aShortFile));            memset(aShortExe, 0, sizeof(aShortExe));                        GetShortPathName(pCompareFile, aShortFile, sizeof(aShortFile));            GetShortPathName(pCompareExe, aShortExe, sizeof(aShortFile));                        pCompareFile = aShortFile;            pCompareExe = aShortExe;    #endif            //  Case insensitive comparison.            if(stricmp(pCompareFile, pCompareExe))   {                //  Not the same.                bRetval = TRUE;            }        }    }        if(bFreeFileName && pFileName) {        XP_FREE((void *)pFileName);        pFileName = NULL;    }    return(bRetval);}