Dynalib Miscellaneous

From Team Developer SqlWindows Wiki
Jump to: navigation, search

Dynalibs miscellaneous


Pointer2.png How to determine dynalib filename Pointer.png

At runtime it could be handy to determine the Dynalib filename of the current execution context.
This can be used to display the Dynalib name in error messages within the Dynalib where the error occurred.
Specially for finding the location of the issue, displaying the name of the Dynalib could really help.

Use this piece of code within the Dynalib to get the filename (with or without path).
It also works when executed within an executable. In that case, the exe name is determined !
Both SalOutline functions are undocumented.

! First get the current outline handle. Every dynalib in the system has an unique handle at runtime
Set nCurrentOutline = SalOutlineCurrent( )

! Now get the filename of this handle.
! The boolean parameter indicates if the receive variable sFile will have the full path (TRUE) or only the filename (FALSE)
Call SalOutlineGetFileName( nCurrentOutline, sFile, FALSE )

The sample can be downloaded here:
Down.png WIKI_GetDynalibFilename.zip

Pointer2.png Send message back to executable from a dynalib Pointer.png

Using the tip about sending messages to the Application Actions section which is described here:

we are able to send a message from a dynalib back to the main executable.

A dynalib itself does not have a working Application Actions section, so any messages which are defined there at dynalib level are not processed.

Messages like SAM_AppStartup and SAM_SqlError are ignored when the dynalib runs within an executable.
The only place where messages at application level are processed is in the main executable.

But there is a way to have some kind of communication between dynalibs and the main executable at runtime.
A dynalib can use the described trick to send a message to the main executable message actions.
When the dynalib passes a window handle which is running inside the dynalib with that message, the main executable is able to send a message back.

This is the list of steps to take for this kind of message communication:

  • Dynalib sends an application message to the main executable message actions and passes the window handle (as number) with this message
  • The main executable receives the message at application level and gets from the passed parameter the window handle of the caller
  • The main executable performs whatever needed and sends a respond message back to the dynalib using the received window handle

You are able to pass custom data from the dynalib to the executable and visa versa. Constructing a string with multiple data elements and then convert it
to a HSTRING (=number) and pass it as the wParam or lParam.

The supplied sample shows an implementation of this.

The main executable starts a FormWindow from a dynalib. The dynalib form has a button to request an action from the main executable.
It sends an application message and passes the dynalib form window handle.
The main executable receives this message and displays a dialog to select an action.
The selected action is send back to the dynalib form and displayed there.

A sample can be downloaded here:
Down.png WIKI_SendAppMsgFromDynalib.zip

Pointer2.png How to distinguish exports Pointer.png

When your project imports several items from dynalibs, it could be helpful to see from where an item is exported.
In the dynalib, place behind the __Exported pragma some text to indicate the source of the item :


See sample above. Now it is easy to see where the item is from.