Calling Procedures in DLLs

 

DLLs or Dynamic-link libraries are used extensively by Engineers to funtions and subroutines located there.  There are two main ways that Enable can be extended, one way is to call functions and subroutines in DLLs and the other way is to call functions and subroutines located in the calling application.  The mechanisms used for calling procedures in either place are similar.  (See the Declare Statement for more deatils)

 

To declare a DLL procedure or a procedure located in your calling application place a declare statement in your declares file or outside the code area.  All declarations in Enable are Global to the run and accesible by all subroutines and functions.  If the procedure does not return a value, declare it as a subroutine.  If the procedure does have a return value declare it as a function.

 

Declare Function GetPrivateProfileString Lib "Kernel32" (ByVal lpApplicationName As String, ByVal _ lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As _ Integer, ByVal lpFileName As String) As Integer

 

Declare Sub InvertRect Lib “User” (ByVal hDC AS Integer, aRect As Rectangle)

 

Notice the line extension character “-“ the underscore.  If a piece of code is too long to fit on one line a line extension character can be used when needed.

 

Once a procedure is declared, you can call it just as you would another Enable Function.

 

It is important to note that Enable cannot verify that you are passing correct values to a DLL procedure.  If you pass incorrect values, the procedure may fail.

 

Passing and Returning Strings

 

Cypress Enable  maintains variable-length strings internally as BSTRs.

BSTRs  are  defined  in the  OLE header  files  as  OLECHAR FAR *. An

OLECHAR is a UNICODE character in 32-bit OLE and an ANSI character in

16-bit OLE. A BSTR  can  contain NULL values because a length is also

maintained with the BSTR. BSTRs  are also NULL terminated so they can

be treated as an LPSTR. Currently this length  is stored  immediately

prior  to the  string. This may change in the future, however, so you

should use the OLE APIs to access the string length.

 

You  can pass a string from Cypress Enable to a DLL in one of two ways.

You can pass it "by value" (ByVal) or "by reference". When you pass a

string  ByVal, Cypress Enable  passes a pointer to the beginning of the

string  data  (i.e. it passes a BSTR). When  a  string  is  passed by

reference, Enable passes a  pointer to  a pointer to the string

data (i.e. it passes a BSTR *).

 

OLE API

SysAllocString/SysAllocStringLen

SysAllocString/SysAllocStringLen

SysFreeString

SysStringLen

SysReAllocStringLen

SysReAllocString

 

NOTE:  The  BSTR  is a  pointer  to the  string, so you don't need to

dereference it.