debugging tool for pb and "brand m" basic users.
shell'ed exe source code follows; requires pb/win 7.x to compile.
complete archive - all source code, compiled exes, and "brand m" #include file and demo program
at http://www.powerbasic.com/files/pub/...ls/modlist.zip
thanks to balthasar indermuehle, who ported the pb #include file and wrote the "brand m" demo application.
***** #include file for pb/cc or pb/win *****
***** demo appplication for pb/cc 3.x or pb.win 7.x *****
------------------
michael mattias
tal systems inc.
racine wi usa
mailto:[email protected][email protected]</a>
www.talsystems.com
shell'ed exe source code follows; requires pb/win 7.x to compile.
complete archive - all source code, compiled exes, and "brand m" #include file and demo program
at http://www.powerbasic.com/files/pub/...ls/modlist.zip
thanks to balthasar indermuehle, who ported the pb #include file and wrote the "brand m" demo application.
***** #include file for pb/cc or pb/win *****
Code:
' file: modlist_inc.inc ' #include file to use with pb/win or pb/cc program to show loaded modules ' this file intended to be used to call the 'modlist.exe' program ' as a debugging tool. ' author: michael mattias racine wi usa. ' visual basic conversion of this file and test program courtesy balthasar indermuehle ' comments/suggestions via email to [email protected] ' use and redistribution: source and executable placed in public domain ' by the authors june 7 2003. ' written: june 2003. ' compilers used for testing: powerbasic pb/win version 7.02 and pb/cc 3.02 ' dates of pb-supplied windows header files used in this include file: ' win32api.inc may 9, 2002 '------------------------------------------------------------------------------- ' program usage: ' the shelled program is executed with a command line of: ' modlist.exe process-id [program-name] ' process-id can be obtained by using the windows api call getcurrentprocessid ' (it can also be obtained a number of other ways). ' optional program-name is simply a string which will be put in the caption ' of the dialog of $modlist_program_name; if null it does not hurt. ' ====[ history ] ================================================================= ' 06/07/03 1.0.0 original ' ================================================================ ' usage at the powerbasic pb/cc or pb/win source code level ' #include this file. requires windows functions/equates detailed below. ' so include after including win32api.inc ' call the function "showmeallloadedmodules" at whatever points ' in the program you want to know exactly which modules are loaded ' into your process space. the listing will include any modules ' loaded at load-time (i.e., declared with a lib) or any modules ' currently dynamically loaded with loadlibrary ' requirements ' 1. $modlist_program_name must available via shell to calling program: on path, ' in system directory or in or in the same directory as calling program). ' 2. $modlist_program_name may not contain spaces unless quotation marks ' are explictly added when building the command line to shell ' 3. relies on powerbasic compilers continuing to translate shell into a ' call to the windows function createprocess. ' this is an undocumented feature, so it is subject to change in future ' versions of compilers; and since the feature is undocumentd, any changes ' will likely be undocumented, too. ' 3a. ok, so i could have used createprocess myself and spared myself the angst ' regarding the shell function. ' the author originally used shellexecuteex rather than shell; however, ' shellexecuteex itself requires shell32.dll, gdi32.dll, shwlapi.dll and comctl32.dll ' which are not necessarily required by the program being tested (or imported by ' default by the powerbasic compiler). ' === end of preliminaries. begin main event ===================================== ' program shelled by the main function; must be available to calling program. $modlist_program_name = "modlist.exe" ' ===== alternate program which can be shelled ==================================== ' at http://www.powerbasic.com/support/pb...ad.php?t=23470 is another ' version of this program, which enumerates all processes and modules with version ' info currently running on the system. that program may be substituted for this ' program if complete system process and module listing is desired. (does not ' isolate modules for specific process). ' that software is collaborative effort of semen matusovsky, borje hagsten, ' dave navarro and bob scott ' ================================================================================= ' include the windows header file #if not %def(%winapi) #include "win32api.inc" #endif ' ================================================================================= ' function to shell $modlist_program_name and wait until it enters idle state ' (that program does not enter idle state until snapshot taken and dialog is built) ' ================================================================================= function showmeallloadedmodules () as long ' build command line = "pid, space, program name to appear in dialog caption" ' shell function to get pid ' open that pid to get process handle on which to wait ' wait for shelled program (a gui program) to enter idle state and exit. local dwpid as dword, szprogramname as asciiz * %max_path, szparameters as asciiz * %max_path local stat as long, e as long, szfile as asciiz * %max_path local idshellprocess as dword local hshellprocess as dword local timeout2 as long, smsg as string local funcval as long funcval = -1 ' default to failure ' get the name and process id of this (the calling) program getmodulefilename byval %null, szprogramname, sizeof(szprogramname) szprogramname = mid$(szprogramname, instr(-1, szprogramname, "\") + 1) dwpid = getcurrentprocessid() ' get the name and build the parameters for the program which will actually ' show the modules loaded by this program szfile = $modlist_program_name szparameters = ltrim$(str$(dwpid)) & $spc & szprogramname timeout2 = %infinite ' this ought be be long enough! ' start the module-lister program and wait until it has entered idle state, ' meaning it has completed its snapshot and has all the info it needs. idshellprocess = shell (szfile & $spc & szparameters) if idshellprocess > &h20 then hshellprocess = openprocess (%synchronize, %false, idshellprocess) if istrue hshellprocess then stat = waitforinputidle (hshellprocess, timeout2) select case as long stat case %wait_object_0 ' program entered input idle, this is good, we do nothing funcval = 0 ' success! end select closehandle hshellprocess else smsg = "could not open shelled process for synchronize access!" #if %def(%pb_cc32) stdout smsg #else msgbox smsg, %mb_iconhand, "oops" #endif end if elseif idshellprocess = 0 then e = err smsg = "shell failed on error " & str$(e) & $spc & error$(e) #if %def(%pb_cc32) stdout smsg #else msgbox smsg, %mb_iconhand, "oops" #endif end if function = funcval end function ' *** end of file
Code:
' test_modlist.bas ' program to test the shell of the modlist program ' author: michael mattias racine wi usa 6/7/03 ' for pb/cc 3.02 and pb win 7.02 ' placed in public domain by author. #compile exe #register none #debug error on #dim all #tools off ' include file for modlist program #include "modlist_inc.inc" ' just for testing to make sure i am reading the loaded from path correctly.. ' this should be loaded from c:\utility\dll $test_dll_name = "ddoc32.dll" ' declare a function in $test_dll_name to test if modules correctly itemized ' when load-time linking is done 'declare function dpprintercount lib "ddoc32.dll" alias "dpprintercount" as long function winmain( byval hinstance as long , _ byval hprevinst as long , _ lpszcmdline as asciiz ptr, _ byval ncmdshow as long ) as long local hlib as long, smsg as string, lresult as long hlib = %null ' statements for testing if 2 = 2 then ' test if it shows modules loaded by loadlibrary. yes, it does hlib = loadlibrary ("ddoc32.dll") ' test if it shows modules loaded when program starts. yes, it does. 'call dpprintercount < ' uncomment to test load-time linking end if call showmeallloadedmodules to lresult ' launches the viewer and returns if istrue hlib then freelibrary hlib end if smsg = iif$(lresult, "error getting module list", "all currently loaded modules shown.") #if %def(%pb_cc32) stdout smsg stdout "any key to terminate program" waitkey$ #else msgbox smsg, %mb_iconinformation, "all done" #endif end function ' ** end of file ***
------------------
michael mattias
tal systems inc.
racine wi usa
mailto:[email protected][email protected]</a>
www.talsystems.com
Comment