CompulsiveCode


jyPresDLL

A DLL for accessing databases and web services

from PrintSoft Pres  

  HyperLink  
     
  This is a .NET Framework (4.5.2) DLL that can be called from PrintSoft Pres.  This DLL can be used to perform database queries and run stored procedures, and to interact with web services.  The ability to call .Net DLLs from Pres greatly expands the functionality available to Pres.

To call a custom DLL from Pres, the USERHOOK statement is used.  Pres can pass two ALPHA fields and one NUMERIC array to the DLL.  The numeric array must be at least 5 elements long.  DLLs can also return data to the Pres script through any of these fields.

The numeric array needs to be large enough for the Pres DLL functions being called.  For this DBsql DLL, none of the functions require more than 5 array elements. 
NUMERIC dllNumArray [5]
ALPHA dllAlpha1 L32000     ;might as well be as large as possible
ALPHA dllAlpha2 L32000     ;might as well be as large as possible


For this DLL (and any Pres DLL that I write), the first element (index 0) in the array should specify the number of elements being passed.  This tells the DLL how big the array is.
dllNumArray [0] = 5

Since the DLL can only expose one function to Pres, we use the second element (index 1) in the array to specify what function we want to call within the DLL.
In this particular DLL:
2=Open Connection  (Pass the Connection String in dllAlpha1)
3=Set the delimiter to use when returning a Row (pass the delimiter in dllAlpha1)
4=Execute a SQL command (pass the command in dllAlpha1, this function returns the Column Headers in dllAlpha2)
5=Read Headers of Returned Data (this function returns the Column Headers in dllAlpha2)
6=Read a Row of Returned Data (this function returns a row of data in dllAlpha2)
7=Execute Stored Proc (dllAlpha1 = Command String)
8=Close Connection

The third element (index 2) in the array will be used for a return code back from the DLL.
Pres will populate the fourth and fifth elements (index 3 and 4) with length of dllAlpha1 and dllAlpha2 when calling USERHOOK with the 'A' parameter

So, to open a connection, the code would look like:
dllAlpha1 = connectionString
dllAlpha2 = ""
INITARRAY dllNumArray, 0
dllNumArray [0] = 5  ;specify the number of elements being passed to the DLL. 
dllNumArray [1] = 2  ;specify DLL internal function #2 -- Open Connection
dllNumArray [2] = 0  ;clear the return value.  This is used by the DLL for returning an error code.
dllNumArray [3] = 0  ;pres will populate this with length of dllAlpha1 when calling USERHOOK with the 'A' parameter
dllNumArray [4] = 0  ;pres will populate this with length of dllAlpha2 when calling USERHOOK with the 'A' parameter
USERHOOK dllFileName, dllNumArray, dllAlpha1, dllAlpha2, 'A'
IF (dllNumArray [2] = 0) {
 ;connected!
}
ELSE {
 ;error
}

The convention is similar for function #2 thru #8, and  #20 thru #26.

DLL functions:

MsgBox = 1     ;Pass the msgbox text in dllAlpha1, and the title text in dllAlpha2.  This function is just a debugging tool.

DB_OpenConn = 2    ;pass connection string in dllAlpha1.  Opens a connection to the database.
DB_SetColumnDelimiter = 3    ;pass desired column delimiter char in dllAlpha1.  used when returning a row.
DB_ExecCommand = 4   ;pass the SQL command in dllAlpha1.  Column Headers are returned in dllAlpha2.
DB_ReadHeaders = 5     ;Column Headers are returned in dllAlpha2.
DB_ReadRow = 6      ;The next Row is returned in dllAlpha2.
DB_ExecStoreProc = 7     ;pass the stored procedure name in dllAlpha1.  Column Headers are returned in dllAlpha2.
DB_Close = 8    ;Closes the connection. 

WebSvc_CallWebSvc = 20     ;pass the URL in dllAlpha1.  The response is returned in dllAlpha2.  HTTP response code is returned in dllNumArray [5].

Advanced WebRequests:
WebSvc_SetRequestMethod = 21     ;Pass the HTTP request method in dllAlpha1, like "GET" or "POST" or "PUT".
WebSvc_SetRequestContentType = 22    ;Pass the HTTP request content type in dllAlpha1. 
WebSvc_SetRequestAccept = 23     ;Pass the HTTP request accept type in dllAlpha1.
WebSvc_AddRequestHeader = 24      ;Pass the HTTP request header in dllAlpha1.
WebSvc_ClearRequestHeaders = 25     ;Clears the headers on the current HTTP request.
WebSvc_CallWebSvc_GETorPOST = 26   ;pass the URL in dllAlpha1.  The response is returned in dllAlpha2.  HTTP response code is returned in dllNumArray [5].