User Guide : Scripting : Using Scripts to Perform Specific Tasks : Calling External DLLs
 
Share this page             
Calling External DLLs
A Dynamically Linked Library (DLL) is a small program that can be called from an application as required instead of loading into memory when the application is run. DLLs enable you to add third-party subroutines and functions to an existing application. Because DLLs are linked dynamically, the library code within a DLL can be shared by linking code among multiple, synchronous tasks.
Map Designer enables you to use any "callable" external DLL to perform additional cleaning or modification of the data during a transformation. External DLLs can be called using the Declare statement.
Caution!  Incorporating DLLs in a transformation is an advanced-level skill that should be performed only by experienced users. The problems with calling third-party external DLLs cannot be addressed by technical support engineers and no responsibility is assumed for loss of data.
Limitations
When using the Declare statement, the syntax in your call statement must be exact.
You must provide the parameter types, number, order, and data type.
You must know whether the type is ByVal or ByReference.
Calling DLLs using a Declare statement
The Declare statement can be used to call a DLL that contains linking code to a library or contains a user-defined function or subroutine.
Syntax
Use one of the following:
Declare function lib dllname
Declare Function publicname Lib "dllname" [Alias "alias"] [([[ByVal] variable [As type] [,[ByVal] variable [As type]]...])] As Type
Declare subroutine lib dllname
Declare Subroutine publicname Lib "subrname" [Alias "alias"] [([[ByVal] variable [As type] [,[ByVal] variable [As type]]...])]
The parameter data types are:
integer
long
single
double
string
By Reference or By Value (using the ByVal keyword) are both valid unless you are passing a string. A string is passed "by reference". If you specify ByVal, a string variable argument gets passed By Reference. If you do not specify ByVal, an error occurs.
Examples of Calling External DLLs
To call an external DLL (user32.exe) to transform your OEM data to ANSI, the following are the function calls that are executed in the Map:
Note:  The Code Page property option can be used to accomplish the same steps.
' Declare the OemToChar function
Declare function OemToCharA lib "user32" (byval lpszSrc as string, byval lpszDst as string) as long
' Declare the OemToChar Buffer function
Declare function OemToCharBuffA lib "user32" (byval lpszSrc as string, byval lpszDst as string, byval cchDstLength as long) as long
' Define private variables to return function results
private buffretvalue
private retvalue
' Call functions
OemToCharBuffA ([Field1] , buffretvalue, 25)
OemToCharA ([Field1] , retvalue)
' Place returned value into Target field
retvalue