Re: Calling DLL's from Triger

From: Beverley Williams <bev_at_starfleet.bt.co.uk>
Date: 1996/08/22
Message-ID: <4vh6st$g4c_at_pheidippides.axion.bt.co.uk>


"Mark Spiteri" <fotolux_at_pathcom.com> wrote:
>Hi there,
> Is it possible to call a DLL from within a Triger. If it is possible
>please let me know. Also if anyone has some saample code on how to do
>this, I would greatly appreciate a copy of it.
>
>Thanks in Advance
>Mark

Mark,

I hope this is of some use:-

Document ID:         107448.325
Title:               WIN: Creating User Exits for Forms 4.0.13
Creation Date:       27 January 1995
Last Revision Date:  30 January 1995
Revision Number:     1
Product:             Oracle Forms
Product Version:     4.0.13
Platform:            DESKTOP
Information Type:    ADVISORY
Impact:              MEDIUM
Abstract:            This bulletin gives detailed instructions on how to
                     create user exits to use with Oracle Forms on Windows.
                     This bulletin applies ONLY to forms 4.0.13.
Keywords:            WINDOWS;FORMS;ORAFORMS;USEREXIT;COMPILE;IAPXTB
_______________________________________________________________________________
            Creating a User Exit for Oracle Forms 4.0.13 on Windows
 This bulletin contains additional information that will help you create user exits for Oracle Forms version 4.0.13 on Microsoft Windows.  NOTE: This bulletin applies ONLY to Forms 4.0.13, NOT to any other version.  The sample files referenced in this bulletin should be found in your C:\ORAWIN\FORMS40\USEREXIT directory. It is very important that you carefully examine the following files in that directory: UE_SAMP.PC, UE_XTB.C, UE_SAMP.MAK, and F40XTB.DEF.
  SUPPORTED COMPILER AND PRECOMPILER VERSIONS  You must use the Microsoft Visual C++ compiler version 1.0 or 1.5. No other compiler is supported. If you intend to embed SQL in your user exit you must use Pro*C 1.5.10 for Windows. No earlier version of this precompiler is supported.
  USER EXIT OVERVIEW
 All of the user exits you write go into one file: F40XTB.DLL. Forms will look in \ORAWIN\BIN for this file. In answer to a common question: There is no way to name this file differently or to split it into several pieces. Forms loads this DLL, and then looks inside of it for the iapxtb data structure which you have built into the DLL. This structure "registers" your user exit so that Forms knows about it. Typically, mistakes in building F40XTB.DLL or bugs in your code will result in Forms being unable to find your user exit, or more commonly in a General Protection Fault.
  STEP ONE: WRITE THE CODE FOR YOUR USER EXIT  Carefully examine the file UE_SAMP.PC and model your user exit after this. If you have never written a Windows 3.1 application before, you should not attempt to build a user exit until you have taken a Windows 3.1 programming course and can build your own (non-Oracle) DLL and call it from your own Windows executable. Reccomended reading: "Programming Windows 3.1" by Charles Petzold.
 When Forms calls your user exit, it passes you 5 arguments. The first argument contains all the arguments passed to your userexit from the trigger and is a string. It is up to you to parse this string to get the individual parameters. The other 4 parameters can be examined by looking at the uxsql() function call in UE_SAMP.PC.
  STEP TWO: REGISTER YOUR USER EXITS
 Use the code in the file "UE_XTB.C" as an example of how to properly register your user exit in the IAPXTB structure (which contains a list of all the user exits linked in with Oracle Forms). Here is an example of registering two user exits:

     #ifndef UE
    #include "ue.h"
    #endif /* UE */

     #include "ue_samp.h"
     /* Define the user exit structure */
     extern exitr iapxtb[] =  {  /* Holds exit routine pointers */
         "USEREXECSQL", uxsql, XITCC,
         "CHECKSTAT", foo, XITCC,
         (char *) 0, 0, 0         /* zero entry marks the end */
    }; /* end iapxtb */
 This example associates user exits "USEREXECSQL" and "CHECKSTAT" (the names that Oracle Forms will use for the user exits) with the C functions "uxsql" and "foo" respectively. The third entry on each line of the ipaxtb struct tells what language the user exit was written in, C in this case (that's what the "XITCC" means).
 To complete this example, you would need to add prototypes for your "uxsql" and "foo" functions to the file "UE_SAMP.H".   STEP THREE: PRECOMPILE YOUR USER EXIT
 NOTE: Please ignore the file PCOMP.BAT. It cannot be used with your precompiler.
 The following steps illustrate how to precompile a .PC file and convert it into a .C file.
  1. Start up Pro*C 1.5.10.
  2. From the menu choose "Edit" then "Add".
  3. Using the file browser, go to \ORAWIN\FORMS40\USEREXIT and select the file "UE_SAMP.PC" You should now see "ue_samp.pc" listed under the column "Input File".
  4. Use the mouse to click on the filename "UE-SAMP.PC" which will highlight it.
  5. Now from the menu choose "Edit" then "Options". If you don't see this, you haven't highlighted the filename.
  6. Under the section labeled "Formatting", set "Input Line Length" to 132 and "Output Line Length" to 132.
  7. In the box under the heading "Includes Path", type the following: "c:\orawin\pro15\c\"
  8. If you need to set any other Pro*C options set them now. (This is all that is required for UE_SAMP.PC.)
  9. Click the "OK" button to dismiss the Options window.
  10. You should now see the following under the "Options" column: "ireclen=132 oreclen=132 include=c:\orawin\pro15\c\"
  11. From the menu choose "File" then "Run" to begin precompiling.
  12. You should see a green check mark in the first column which indicates success. If you see a red "X" or yellow check you should click on it to see what error you have made.
  13. You will now have created "UE_SAMP.C" in your \ORAWIN\FORMS40\USEREXIT directory. STEP FOUR: TRY BUILDING F40XTB.DLL USING OUR SAMPLE PROJECT The following steps show how to use the UE_SAMP.MAK file we provide in building a F40XTB.DLL that contains the sample user exit.
  14. Start up the Visual C++ compiler from Windows (workbench).
  15. From the menu choose "Project", then "Open"
  16. Use the file browser to go to the /ORAWIN/FORMS40/USEREXIT directory and choose "UE_SAMP.MAK"
  17. From the menu choose "Options", then "Directories". To the "Include Files Path" add "c:\orawin\pro15\c". To the "Library Files Path:" add "c:\orawin\pro15\lib" and also "c:\orawin\pro15\userexit".
  18. From the menu, choose "Project" then "Rebuild all". You should get the following 2 warnings: RC: warning RW4002: Entry point segment 1 set to PRELOAD RC: warning RW4002: Non-discardable segment 3 set to PRELOAD These are normal. You should not get other errors or warnings.
  19. You have now created UE_SAMP.DLL which will be located in \ORAWIN\FORMS40\USEREXIT.
  20. Rename UE_SAMP.DLL to F40XTB.DLL and place it in the \ORAWIN\BIN directory (replacing any previous copy of this file). STEP FIVE: VERIFY THAT THE SAMPLE USER EXIT HAS BEEN BUILT CORRECTLY The following steps will help you find out whether or not you have done the previous steps correctly or not.
  21. Launch RUNFORM and select the file "UE_SAMP.FMX".
  22. Click on "UserExit Demonstration".
  23. In the "SQL statement to execute" field, enter: "create table uetest (n number)"
  24. You should see the message "Successfully Executed Statement" Note: You can only execute one SQL statement per run with this user exit. To try another SQL statement you must restart the form.
  25. Shut down the form.
  26. From SQL*Plus, log in as the same user. Do a "select * from uetest".
  27. You should see "no rows selected". If you see a ORA-942 at this point, or got any other errors while running the form, the user exit was incorrectly built. STEP SIX: SETTING UP YOUR OWN PROJECT Before attempting to build your own project, you should first make sure you can build and run the sample project we provide (see instructions above). After successfully doing that, examine the settings we have used in our project. The only major difference between UE_SAMP.MAK and your own make file should be that you have included your own version of "ue_xtb.c" and a C file (or files) similar to "ue_samp.c". In fact, you can simply modify our ue_samp.mak, removing our ue_xtb.c and replacing it with yours, and removing ue_samp.c and replacing it with your .C files. Or, you may wish to create a whole new project from scratch. The following steps show you in detail how to configure your own project file from scratch.
  28. From the Menu choose "Project", then "New".
  29. Choose a project name, and choose a project type of "Windows dynamic link library".
  30. From the Menu choose "Project", then "Edit".
  31. Use the browser to go to the \ORAWIN\FORMS40\USEREXIT directory and highlight each of the following files, then press the button labeled "Add": "RUNFORM.LIB","OSSWEP.OBJ", "UEZ.OBJ", "F40XTB.DEF". You should see each of these 4 files appear in the "Files in Project" box.
  32. Use the same browser to locate your .C file(s) that contains your userexit (and that you have already precompiled -- in our example this was ue_samp.c) and select "Add" for this file(s) as well.
  33. Using the same tecnique, "Add" your modified "ue_xtb.c" file as well.
  34. From the menu choose "Options", then "Project"
  35. Click on "Compiler", then on the "Use Project Defaults" button.
  36. Under "Category" select "PreProcessor".
  37. In the field "Symbols and Macros to define" add the following to what is already there: "MSWINDOWS, _WINDLL".
  38. Under "Category", select "Memory Model". Choose "Large" and "SS !=DS, DS NOT loaded on function entry", then click OK.
  39. Now click on the "Linker" button. Click on "Use Project Defaults".
  40. Under "Categeory", highlight "Input" and in the "Libraries" field type the following library names: "oldnames, libw, ldllcew, sql15win.lib, sqx15win.lib". If you don't have these libraries, you will need to reinstall your compiler (custom install) and choose to install libraries for the Large Memory Model.
  41. Under "Category", highlight "Windows Libraries", then under "Import Libraries and DLL's", deselect any of these that you don't specifically need. (Generally you can deselect them all.)
  42. Click OK and close all windows.
  43. From the menu choose "Options", then "Directories". To the "Include Files Path" add "c:\orawin\pro15\c". To the "Library Files Path:" add "c:\orawin\pro15\lib" and also "c:\orawin\pro15\userexit"
  44. From the menu, choose "Project" then "Rebuild all". You should get the following 2 warnings: RC: warning RW4002: Entry point segment 1 set to PRELOAD RC: warning RW4002: Non-discardable segment 3 set to PRELOAD These are normal. You should invesitigate any other warnings or errors.
  45. You have now created a .DLL (with the name of your project) which will be located in \ORAWIN\FORMS40\USEREXIT.
  46. Rename this DLL to F40XTB.DLL and place it in the \ORAWIN\BIN directory (replacing any previous copy of this file). ANSWERS TO COMMON QUESTIONS ABOUT BUILDING USER EXITS o If you find information in the Online help files, Advanced Techniques manual, or Install Guide that differs or contradicts this bulletin, please use the information in this bulletin instead. o There is no way to name the F40XTB.DLL file some other name or to split it into several files. All your user exits must go into the F40XTB.DLL located in \ORAWIN\BIN. o User Exits are not supported with Pro*Cobol for Windows. o There is NOT a GENXTB utility available to automatically set up the iapxtb.c structure. You have to use the method listed in step 2. o If, during precompilation, you get the error: "Unable to open include file SQLCA" Follow the instructions above in step 3 above to set the "Includes Path" o If you get the compile time warnings, 'strlen' undefined; assuming extern returning int, 'strcpy' undefined; assuming extern returning int, and 'sqlcex' undefined; assuming extern returning int, you haven't included "sqlproto.h" and "string.h" to your .PC file. o If you get the following compile time error: L4051 SQL15WIN.LIB unable to find library, or L4051 SQx15WIN.LIB unable to find library you should set the "Library Files Path:" for the compiler. (See step 4.) o If you get these warnings while building the project, please ignore them, they are normal: Entry point segment 1 set to PRELOAD Non-discardable segment 3 set to PRELOAD o If you get this error during compile: fatal error C1083: Cannot open include file: 'sqlproto.h' you should set the Include Files Path for the compiler. (See step 4.) o If you get an "unresolved external: _sqlca" error when you compile UE_SAMP.PC, then change the line "#define SQLCA_STORAGE_CLASS extern" in that file to just read "#define SQLCA_STORAGE_CLASS". o If you get an "unresolved external: _sprintf" error when you compile UE_SAMP.PC, then add the library LLIBCEW.LIB to your program.
    Oracle WorldWide Customer Support
Received on Thu Aug 22 1996 - 00:00:00 CEST

Original text of this message