Copyright: build 2.1
Citation: build 2.1


Contents
  Index of  "Using API Functions"

In this seven topics help you'll find:

 how to know if a DLL has been loaded

 how to know if a DLL function has been loaded

 how to know which modules (ex. DLLs, executables, etc) are currently loaded

 how to know if an module has been loaded

 how to know the path of a specified module

 how to get information about version of a module

 how to unlink DLLs

 Credits.


  sysLinkedDlls

Description: sysLinkedDlls is a System Property which returns a list of DLLs (with path names) that are currently linked to the ToolBook instance.

Tip.

Try this:

-- This script cecks if DBIII Dynamic Link Library

-- is currently loaded; put it in a button script.

to handle buttonClick

if "tb40db3.dll" is not in sysLinkedDlls

request "You can't use DB3 files!"

end if

end


Using  API  functions  with  ToolBook:

Marco  Perrotti  (February  1996)

perrotti@mbox.vol.it


DllFunctions
  dllFunctions()

Description: dllFunctions() is a System Property that returns a list of DLLs that are currently loaded.

Try this:

-- Following script cecks if a function

-- (ex. messageBox()) is currently available,

-- otherwise script loads it.

to handle buttonClick

get messageBox is in DllFunctions("user.exe")

if it is "false"

linkDll "user"

INT messageBox(WORD,STRING,STRING,WORD)

end linkDll

end if

get messageBox(sysWindowHandle,\

"MessageBox() function is available!","",0x30)

unLinkDll functions "messageBox" from "user"

end


getModuleList
  getModuleList()

Description: the getModuleList function returns a list of Windows modules that are currently loaded on the system.

Try this:

-- Following script puts in a field called "list"

-- a sorted list of modules currently loaded,

-- then frees memory from sortList(), listToTextLine() and

-- getModuleList() functions.

to handle buttonClick

linkDll "tb40dlg.dll"

STRING sortList(STRING)

STRING listToTextLine(STRING)

end linkDll

linkDll "tb40win.dll"

STRING getModuleList()

end linkDll

get listToTextLine(sortList(getModuleList()))

put it into text of field "list"

unLinkDll functions "sortList," &\

"listToTextLine,getModuleList" &\

from "tb40dlg.dll,tb40win.dll"

end

P.S.


getModuleHandle
  getModuleHandle()

Description: the getModuleHandle function retrieves the handle of the specified module.

Try this:

-- Following script tests if an executable (write.exe)

-- is currently loaded; put it in a button script.

to handle buttonClick

linkDll kernel

WORD getModuleHandle(STRING)

end linkDll

end

notifyBefore idle

get getModuleHandle("write")

if it is not 0

put "Write is working"

else

put "Write is not working"

end if

end


getModuleFileName
  getModuleFileName()

Description: the getModuleFileName function retrieves the full path and filename of the executable file from wich the specified module was loaded.

Try this:

Tip 1    Tip 2

-- Following script shows how to use getModuleHandle()

-- and getModuleFileName(). It builds three 128 chars buffers

-- without using memory functions! (It also gives information

-- about Windows and System paths).

to handle buttonClick

linkDll kernel

WORD getModuleHandle(STRING)

WORD getModuleFileName(WORD,STRING,WORD)

INT  getWindowsDirectory(STRING,INT)

INT  getSystemDirectory(STRING,INT)

end linkDll

set hModule to getModuleHandle("write")

if hModule <> 0

set bufferOne to makeBuffer(128)

get getModuleFileName(hModule,bufferOne,\

charCount(bufferOne) - 1)

request bufferOne

end if

set bufferTwo to makeBuffer(128)

get getWindowsDirectory(bufferTwo,charCount(bufferTwo) - 1)

request bufferTwo

set bufferThree to makeBuffer(128)

get getSystemDirectory(bufferThree,charCount(bufferThree) - 1)

request bufferThree

end

to get makeBuffer n

local s

set c to "*"

step i from 1 to n

set s to s & c

end step

return s

end


getVersion
  getVersion()

Description: the getVersion function retrieves information about a specified module.

Try this:

-- This script tests which release of Windows USER you have.

-- Put it in a button script.

-- In this way, you can test executables, DLLs and so on.

to handle buttonClick

linkDll "tb40win.dll"

STRING getFileVersion(STRING)

end linkDll

get second word of getFileVersion("user.exe")

request it

unLinkDll functions "getFileVersion" from "tb40win.dll"

end

P.S.


Tip!

You can see also WIDGETS.TBK, topic: "Windows or WFW" (page 21 of 69).


Tip!

You can use also getModulePath function. The getModulePath() (from tb40win.dll or tb30win.dll) returns the path of any specified Windows module currently loaded on the system.


If you have ToolBook 3.0, you've to link tb30dlg.dll and tb30win.dll instead of tb40dlg.dll and tb40win.dll.


If you have ToolBook 3.0, you've to link tb30win.dll instead of  tb40win.dll.


Tip!

You can use also following script to check if a specified function is available or if a DLL has been linked.

to handle buttonClick

set sysSuspend to false

clear sysError

linkDll "tb40db3.dll"

STRING theDb3Team()

end linkDll

if sysError is not null

request "Error linking tb40db3.dll"

break

else

request theDb3Team()

end if

clear sysError

set sysSuspend to true

end


unlink API functions
  unlink DLLs

To unlink API functions you can use:

1) unLinkDll <dll name>

   (<dll name> is the name of the DLL to unlink), unlinks the specified DLL.

2) unLinkDll function <function list> from <dll name>

  unLinkDll functions <function list> from <dll name>

   (<function list> contains a list of one or more function names.

  The <dll name> contains the name of  the DLL from which to unlink the functions.)

3)  The restore system command unlinks all DLLs.

If you have CBT Edition or Database Connection don't use the restore system command, because it may leave the system in an unknown state, so use 1) or 2).