From: Chris H. <pop...@so...> - 2002-04-16 07:26:24
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I don't assume this is a bug. I'm just wondering why this piece of code doesn't show a link to 'strlen' in MSVCRT.DLL while viewing the .EXE file in Dependency Walker. The code compiles fine, and it works the way it should. I use the MinGW-runtime version 2 and... C:\>gcc -v Reading specs from C:/usr/bin/../lib/gcc-lib/mingw32/2.95.3-7/specs gcc version 2.95.3-7 (mingw experimental) This is what I do, and further down is my code: C:\>gcc -Wall -o myapp.exe mysourcecode.c -Os -s -lversion #define WIN32_LEAN_AND_MEAN 1 #include <windows.h> #include <stdio.h> #include <string.h> #define FILENAME "foobar.exe" #define DATFILE "output.dat" typedef struct _fileversion { int nVersion; int nMajor; int nMinor; int nRevision; } FILEVERSION, *LPFILEVERSION; char * BaseName (char *p) { char *fn = strrchr (p, '\\'); return fn ? fn + 1 : p; } char * DirName (char *lpPath) { int i; char *fn = strrchr (lpPath, '\\'); if (fn) { i = strlen (lpPath) - strlen (fn); /* Here's the 'strlen' that I use */ lpPath[i] = '\0'; } return lpPath; } void GetFileVersion (LPFILEVERSION lpfv, LPCTSTR lpFileName) { DWORD dwSize, dwHandle; LPBYTE lpBlock = NULL; UINT uLen; VS_FIXEDFILEINFO *pvsffi; dwSize = GetFileVersionInfoSize ((LPTSTR) lpFileName, &dwHandle); lpBlock = (LPBYTE) HeapAlloc (GetProcessHeap (), 0, dwSize + 1); ZeroMemory (lpBlock, dwSize + 1); GetFileVersionInfo ((LPTSTR) lpFileName, 0L, dwSize, lpBlock); VerQueryValue (lpBlock, TEXT ("\\"), (LPVOID *) &pvsffi, &uLen); HeapFree (GetProcessHeap (), 0, lpBlock); lpfv->nVersion = HIWORD (pvsffi->dwFileVersionMS); lpfv->nMajor = LOWORD (pvsffi->dwFileVersionMS); lpfv->nMinor = HIWORD (pvsffi->dwFileVersionLS); lpfv->nRevision = LOWORD (pvsffi->dwFileVersionLS); return; } int main (int argc, char **argv) { char buf[MAX_PATH], datfile[MAX_PATH]; FILEVERSION fv; GetModuleFileName (NULL, buf, MAX_PATH); sprintf (datfile, "%s\\%s", DirName (buf), DATFILE); GetFileVersion (&fv, FILENAME); sprintf (buf, "%d", fv.nVersion); WritePrivateProfileString ("Version", "Version", buf, datfile); sprintf (buf, "%d", fv.nMajor); WritePrivateProfileString ("Version", "Major", buf, datfile); sprintf (buf, "%d", fv.nMinor); WritePrivateProfileString ("Version", "Minor", buf, datfile); sprintf (buf, "%d", fv.nRevision); WritePrivateProfileString ("Version", "Revision", buf, datfile); WritePrivateProfileString ("Download", "FileName", BaseName (FILENAME), datfile); return 0; } Regards Chris -----BEGIN PGP SIGNATURE----- Version: PGP 7.0.4 iQA/AwUBPLvSEQ6qxNNoghKpEQIORQCg4xpLLZj8PzIb2HUE4rOlmXYS0/AAoM8D d7Nwu87kCJh3aS/fKsnRdebW =w8DE -----END PGP SIGNATURE----- |