ThirdParty Miscellaneous
From TeamDeveloperWiki
This page covers miscellaneous Third Party component tips.
Contents |
WinSock wrapper
When programming WinSock in TD, one major drawback you might discover is that detailed WinSock errors normally fetched using
the API function WSAGetLastError always returns 0 (zero).
This is caused by the fact that TD internally resets the last error code so your code will not be able to get it.
A solution is to use a wrapper dll, which offers the same API as WinSock, but internally calls WSAGetLastError when an error occurs.
The fetched error code is then passed back to TD so you can display the detailed error info.
A small wrapper is build and can be downloaded from the Sample Vault which does the above.
The source (Visual Studio 6 C++ project) is also part of the ZIP file.
Along with the TD sample, a INI file is present which holds all WinSock error codes and their short and long descriptions.
The sample application uses this INI to display the detailed error message.
Callback
Using the Callback dll, created by Christian Schubert, you are able to use Window API features
which require a callback function. In short, when using these features, Windows is able to call functions
within your TD application. Without the Callback DLL principle, TD does not offer a way to support callbacks.
An example where a callback function is used:
The Windows API function EnumThreadWindows is able
to enumerate all
nonchild windows associated with a thread. This means you can obtain all opened top level windows within
your application (all other windows present in the system take no part in the enumeration).
Reading the MSDN documentation on this function:
"The EnumThreadWindows function enumerates all nonchild windows associated with a thread by passing
the handle to each window, in turn, to 'an application-defined callback function'.
EnumThreadWindows continues until the last window is enumerated or the callback function returns FALSE."''
So, by calling this function and passing a "pointer" to an application defined function, all window handles are passed to that function in sequence.
As TD does not support pointers to functions, you are not able to utilize this function.
Callback DLL is the solution. It offers you a simple way to register a TD function (in a class, global function, window function)
which can be used as callback function.
TODO: create a callback sample on EnumThreadWindows.
You can download Callback from Christian Schuberts website
or from the Sample Vault

