Find all statically linked libraries required before your process can start

There’s some code in this post What external code does your EXE depend on? that determines all the statically linked libraries and function calls of a particular EXE. VFP9.EXE links to about 18 modules. However, there are about 83 modules loaded when VFP is up and running. Much of this is due to these 18 modules depending on other modules.


To get all statically linked libraries from all modules, the code needs to recur: for each module, find its dependent modules.


Below is code that finds a tree of 78 statically linked modules and the almost 10,000 functions that need to be loaded for the first line of VFP9.exe code to execute.

The code uses LoadLibrary and GetModuleFileName to get the module full path name because the module may not be on the path.




DECLARE integer GetModuleFileName IN WIN32API integer hModule, string @ lpfilename, integer nSize

DECLARE integer LoadLibrary IN WIN32API  string FileName

DECLARE integer FreeLibrary IN WIN32API integer hModule


CREATE CURSOR imports (Parent c(40), Module c(40),address c(10),FuncName c(40))

CREATE CURSOR modules (module c(40),Level i)

INDEX on UPPER(module) TAG module

GetImports(_vfp.FullName, 1)



PROCEDURE GetImports(Parent as String,nLevel as Integer)

          LOCAL i,mybat,nLines,aa[1],Module,cLine,Address,FuncName

          hm = LoadLibrary(parent)

          IF hm=0

                   ?"Can't load "+parent






                   INSERT INTO modules VALUES (UPPER(JUSTFNAME(Parent)), nLevel)

                   cVars=LOCFILE("c:\Program Files\Microsoft Visual Studio 8\Vc\bin\vcvars32.bat")      && VS2005

*                  cVars=LOCFILE("c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\vcvars32.bat") && VS2003

                   TEXT TO mybat TEXTMERGE NOSHOW

                             call "<<cVars>>"

                             dumpbin /imports  "<<Parent>>" > c:\t.txt



                   !cmd /c t.bat


                   FOR i = 1 TO nLines

                             cLine=aaIdea [I]

                             IF cLine="  Summary"



                             IF cLine = "DUMPBIN : fatal error " OR cLine="    Bound to"




                             IF !EMPTY(cLine) AND LEFT(cLine,4)="    "

*                                     ?cLine

                                      IF SUBSTR(cLine,5)!=' '



                                                IF !SEEK(UPPER(m.Module),"modules")

                                                          GetImports(m.Module,nLevel+1) &&Recur!



                                                IF LEFT(cline,8) = SPACE(8)                                      

                                                          m.Address = GETWORDNUM(cline,1)

                                                          m.FuncName = GETWORDNUM(cline,2)

                                                          IF m.FuncName != "Import" AND "0" != m.address

                                                                   INSERT INTO imports FROM MEMVAR









Comments (11)

  1. CalvinH says:

    For some reason, the new version of blog software changed my code: the line with the light bulb should say

    cLine = aaIdea [I]

  2. CalvinH says:

    it’s even changing the comments.

    That should be Cline = square brackets around the variable i<sigh>

  3. Pranav Wagh says:

    Did You try giving a space between sq bracket open and close i mean [ i ]

  4. Pranav Wagh says:

    So, I don’t see a bulb like [i] <- in my previous comment so you could use the same stuff..

  5. CalvinH says:

    It appears the light bulb thing was fixed in the blog hosting software. Here’s a test:

    This should be an ‘i’ in square brackets: [i]

  6. Let’s log all the calls that Excel makes to open or create a file. Start Visual Studio (any version),

  7. When you start a program on your Windows XP computer, a process is created and several DLLs (Dynamic

  8. When you start a program on your Windows XP computer, a process is created and several DLLs (Dynamic

  9. You can use CreateToolhelp32Snapshot and its family of functions to enumerate the running processes on

Skip to main content