Using Windows System Libraries as External Procedures Under
Title Using Windows System Libraries as External Procedures Under 9i Author Jens-Uwe Petersen (firstname.lastname@example.org) Type of info Technical background info (December 2003) Sources Oracle8 Externe Procedures aus PL/SQL (Urs Meier, Trivadis Publication) Externe Prozeduren unter Windows mit dem Freeware-Compiler MinGW (Jens-Uwe Petersen, Trivadis Publication) Introduction If you ever tried to install examples from the article Oracle8 Externe Procedures aus PL/SQL on a 9i database (9.0.1.x to 9.2.0.x), you were probably irritated when their callout aborted with an error: ORA-28576: lost RPC connection to external procedure agent First, make sure that there are no errors in the configuration (for example, by testing whether the supplied Oracle examples work perfectly). Should the problem persist, it is most probably the unpublished bug 2379740, which affects all Oracle 9i versions under Windows NT, 2000 and XP. The problem is caused by the fact that Windows uses more than one calling standard: Calling standard Linker Relevant calling standard Note directive in PL/SQL C declaration _cdecl C Default in C programs Standard call _stdcall PASCAL Used in Windows API These conventions determine the order in which the parameters are put on the stack and who clears the stack after the function is completed. When standard call is used, the invoked function clears the stack upon completion; when C declaration is used, the invoking function clears the stack and the parameters are placed on the stack in reverse order. External procedures don't currently work in Windows unless the DLL was created using the _cdecl calling standard. The system libraries, however, were created by Microsoft using the _stdcall calling standard. This shouldn't really matter, as you can specify the CALLING STANDARD, i.e. C or PASCAL, during the declaration of PL/SQL procedures. Unfortunately, according to an internal bug description, the PASCAL calling standard wasn't implemented completely, nor does it work. As a workaround, Oracle therefore always recommends re-creating the DLL using the _cdecl standard. If the source code is available, this is feasible. With the Windows APIs or other purchased DLLs, however, there is no source code.