Retrieving VFP runtime DLL name required by EXE or DLL

VFP stores in an EXE/DLL information about what runtime DLL is required to run it.

This is sample code. Add error handling and adjust to your requirements as necessary.

? VfpVersionFromExeOrDll("C:\Program Files\My Company\MyVfpApplication.exe")
? VfpVersionFromExeOrDll("X:\Somefolder\MyVfpDll.dll")

* VfpVersionFromExeOrDll.PRG
FUNCTION VfpVersionFromExeOrDll
LPARAMETERS tcExeDllName
LOCAL lcSig, lnHandle, lcVersion, lcBuffer, lnPos, lcSigMT
lcSig = "VisualFoxProRuntime."
lcSigMT = "VisualFoxProRuntimeMT."
lcVersion = "(Unknown)"
 
lnHandle = FOPEN(tcExeDllName, 0)
IF lnHandle < 0
    ? "Unable to Open file + '" + tcExeDllName + "'. Error:" +   FERROR()
   RETURN lcVersion
ENDIF
* Read first 64KB
lcBuffer = FREAD(lnHandle, 65535) 
=FCLOSE(lnHandle)
 
* Check for regular runtime signature
lnPos = AT(lcSig, lcBuffer)
IF lnPos > 0
	*lcVersion = "Vfp " + STRTRAN(SUBSTR(lcBuffer, lnPos + LEN(lcSig),2), CHR(0), "") + ".0"
	lcVersion = "Vfp" + STRTRAN(SUBSTR(lcBuffer, lnPos + LEN(lcSig),2), CHR(0), "") + "R.dll"
ELSE
	* Check for Multithreaded (MT) runtime signature
	lnPos = AT(lcSigMT, lcBuffer)
	IF lnPos > 0
		*lcVersion = "Vfp MT " + STRTRAN(SUBSTR(lcBuffer, lnPos + LEN(lcSigMT),2), CHR(0), "") + ".0"
		lcVersion = "Vfp" + STRTRAN(SUBSTR(lcBuffer, lnPos + LEN(lcSigMT),2), CHR(0), "") + "T.dll"
	ENDIF
ENDIF
 
RETURN lcVersion

Add new comment

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.