Imports the source code for a PowerBuilder object into a library and compiles it.


INT PBORCA_CompileEntryImport ( HPBORCA hORCASession, 
   LPTSTR lpszLibraryName, 
   LPTSTR lpszEntryName, 
   PBORCA_TYPE otEntryType, 
   LPTSTR lpszEntrySyntax, 
   LONG lEntrySyntaxBuffSize, 
   PBORCA_ERRPROC pCompErrorProc, 
   LPVOID pUserData );




Handle to previously established ORCA session.


Pointer to a string whose value is the file name of the library into which you want to import the object.


Pointer to a string whose value is the name of the object being imported.


A value of the PBORCA_TYPE enumerated data type specifying the object type of the entry being imported. Values are:














Pointer to a string whose value is the comments you are providing for the object.


Pointer to a buffer whose value is source code for the object to be imported. If an export header exists in the source code it is ignored. The source encoding for lpszEntrySyntax is specified by the eImportEncoding property in the PBORCA_CONFIG_SESSION structure.


Length of the lpszEntrySyntax buffer. This length is specified in bytes regardless of the source encoding.


Pointer to the PBORCA_CompileEntryImport callback function. The callback function is called for each error that occurs as the imported object is compiled.

The information ORCA passes to the callback function is error level, message number, message text, line number, and column number, stored in a structure of type PBORCA_COMPERR. The object name and script name are part of the message text.

If you don't want to use a callback function, set pCompErrorProc to 0.


Pointer to user data to be passed to the PBORCA_CompileEntryImport callback function.

The user data typically includes the buffer or a pointer to the buffer in which the callback function stores the error information as well as information about the size of the buffer.

If you are not using a callback function, set pUserData to 0.

Return value

INT. Typical return codes are:

Return code


0       PBORCA_OK

Operation successful


Invalid parameter list


Bad library name, library not found, or object could not be saved in the library


Library not in list


Compile error


Name does not follow PowerBuilder naming rules


The current application has not been set


You must set the library list and current Application object before calling this function.


In PowerBuilder 10 and higher, you must specify the source encoding for the objects to be imported. You do this by setting the eImportEncoding property in the PBORCA_CONFIG_SESSION structure and calling PBORCA_ConfigureSession. For ANSI clients the default source encoding is ANSI/DBCS; for Unicode clients the default source encoding is Unicode.

Importing objects with embedded binary information

Two separate calls to PBORCA_CompileEntryImport are required to import objects containing embedded binary data such as OLE objects. The first call imports the source component. The second call imports the binary component using an otEntryType argument set to PBORCA_BINARY and an lpszEntrySyntax argument pointing to the start of the binary header record.

When errors occur

When errors occur during importing, the object is brought into the library but might need editing. An object with minor errors can be opened in its painter for editing. If the errors are severe enough, the object can fail to open in the painter and you will have to export the object, fix the source code, and import it again. If errors are due to the order in which the objects are compiled, you can call the PBORCA_ApplicationRebuild function after all the objects are imported.


When you import an entry with the same name as an existing entry, the old entry is deleted before the import takes place. If an import fails, the old object will already be deleted.

For information about callback processing for errors, see PBORCA_CompileEntryImportList.


This example imports a DataWindow called d_labels into the library DWOBJECTS.PBL. The source code is stored in a buffer called szEntrySource.

Each time an error occurs, PBORCA_CompileEntryImport calls the callback CompileEntryErrors. In the code you write for CompileEntryErrors, you store the error messages in the buffer pointed to by lpUserData:

int nReturnCode;
fpError = (PBORCA_ERRPROC) ErrorProc;
nReturnCode = PBORCA_CompileEntryImport(
   _TEXT("d_labels"), PBORCA_DATAWINDOW,
   (LPTSTR) szEntrySource, 60000,
   fpError, lpUserData);

In these examples, session information is saved in the data structure ORCA_Info, shown in About the examples.

This example reads a source file, determines the encoding format of the source file, and imports it into a PBL. If the file contains an embedded binary object, this is also imported using a second call to PBORCA_CompileEntryImport.

//    Headers, Defines, Typdefs 
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <tchar.h>
extern "C" {
#include "pborca.h"
//    Global Variables
HPBORCA        hPbOrca;
PBORCA_ERRPROC           fpError;
//    Function Declarations
void CALLBACK ErrorProc(PBORCA_COMPERR *lpCompErr,
       LPVOID lpUserData);
// NAME:      Impbin.cpp
// Synopsis:    Import w_edit_connect.srw (which contains 
// an embedded OLE object) into a work PBL.
//   This example can be compiled as an ANSI client
//   or a Unicode client. To compile as Unicode
//   use /DUNICODE /D_UNICODE compiler directives.
#if defined (UNICODE)
INT wmain ( int argc, wchar_t *argv[])
INT main ( int argc, char *argv[])
   LPTSTR            pszLibraryName[5];
   LPTSTR            pszImportFile;   
   HANDLE            hOpenFile = NULL;   
   INT            iErrCode;   
   BOOL               rc;   
   wchar_t            chMarker;   
   unsignedchar            chMarker3;   
   DWORD            dBytesRead;   
   DWORD            dFileSize;   
   PBORCA_CONFIG_SESSION              Config;   
   LPBYTE            pReadBuffer = NULL;   
   LPBYTE            pEndBuffer;   
   INT            iSourceSize;   
   INT            iBinarySize;
pszLibraryName[0] = _TEXT("c:\\pb12.5\\main\\pbls\\qadb\\qadbtest\\qadbtest.pbl");
pszLibraryName[1] = _TEXT("c:\\pb12.5\\main\\pbls\\qadb\\shared_obj\\shared_obj.pbl");
pszLibraryName[2] = _TEXT("c:\\pb12.5\\main\\pbls\\qadb\\datatypes\\datatype.pbl");
pszLibraryName[3] = _TEXT("c:\\pb12.5\\main\\pbls\\qadb\\chgreqs\\chgreqs.pbl");
pszLibraryName[4] = _TEXT("c:\\pb12.5\\main\\orca\\testexport\\work.pbl");
pszImportFile = _TEXT("c:\\pb12.5\\main\\pbls\\qadb\\qadbtest\\w_edit_connect.srw");
memset(&Config, 0x00, sizeof(PBORCA_CONFIG_SESSION));
PbOrca = PBORCA_SessionOpen();   
//  Delete and re-create work.pbl   
iErrCode = PBORCA_LibraryDelete(hPbOrca, pszLibraryName[4]);   
iErrCode = PBORCA_LibraryCreate(hPbOrca,
    pszLibraryName[4], _TEXT("work pbl"));   
iErrCode = PBORCA_SessionSetLibraryList(hPbOrca,
              pszLibraryName, 5);
if (iErrCode != PBORCA_OK)
   goto TestExit;
iErrCode = PBORCA_SessionSetCurrentAppl(hPbOrca,
    pszLibraryName[0], _TEXT("qadbtest"));   
if (iErrCode != PBORCA_OK)
   goto TestExit;
//  PBORCA_CompileEntryImport ignores export headers, 
//  so the ORCA application must progrmmatically 
//  determine the source encoding of the import file.  
//  This is done by reading the first two or three 
//  bytes of the file. 
hOpenFile = CreateFile(pszImportFile, GENERIC_READ, 0,
    goto TestExit;
rc =  ReadFile(hOpenFile, (LPVOID)&chMarker,
     sizeof(wchar_t), &dBytesRead, NULL); 
if( rc )
    if (chMarker == 0xfeff)
       Config.eImportEncoding = PBORCA_UNICODE;
    else if (chMarker == 0xbbef)
       rc =  ReadFile(hOpenFile, (LPVOID)&chMarker3,
           sizeof(CHAR),&dBytesRead, NULL); 
       if (chMarker3 == 0xbf)
          Config.eImportEncoding = PBORCA_UTF8;
    else if (memcmp((LPBYTE) &chMarker, "HA", 2) == 0)
       Config.eImportEncoding = PBORCA_HEXASCII;
       Config.eImportEncoding = PBORCA_ANSI_DBCS;
//  Now allocate memory for a source buffer and read 
//  entire file      
SetFilePointer( hOpenFile, 0, NULL,   FILE_BEGIN);
dFileSize = GetFileSize(hOpenFile, NULL) ;
pReadBuffer = (LPBYTE) malloc((size_t) dFileSize + 2);
rc =  ReadFile(hOpenFile, pReadBuffer, dFileSize,
      &dBytesRead, NULL); 
//  Append a null terminator to enable strstr() call 
pEndBuffer = pReadBuffer + dFileSize;
memset(pEndBuffer, 0x00, 2);  // unicode EOF marker
if (!rc)         
    goto TestExit;
//  Determine if the object includes a binary component.
//  If it does, then make two separate calls to 
//  PBORCA_CompileEntryImport. 
if (Config.eImportEncoding == PBORCA_UNICODE)
    pszUniBinHeader = "Start of PowerBuilder Binary
         Data Section";
    pUniBinStart = wcsstr((const wchar_t *)
         pReadBuffer, pszUniBinHeader);
    if (pUniBinStart)
    pEndBuffer = (LPBYTE) pUniBinStart;
    iSourceSize = (INT) (pEndBuffer - pReadBuffer);
    iBinarySize = (INT) (dFileSize - iSourceSize);
    iSourceSize = (INT) dFileSize;
    iBinarySize = 0;
    LPSTR  pszAnsiBinHeader;
    LPSTR  pAnsiBinStart;
    pszAnsiBinHeader = "Start of PowerBuilder Binary
        Data Section";
    pAnsiBinStart = (LPSTR) strstr((const char *)
        pReadBuffer, (const char *) pszAnsiBinHeader);
    if (pAnsiBinStart)
       pEndBuffer = (LPBYTE) pAnsiBinStart;
       iSourceSize = (INT) (pEndBuffer - pReadBuffer);
                   iBinarySize = (INT) (dFileSize - iSourceSize);
       iSourceSize = (INT) dFileSize;
       iBinarySize = 0;
//  Configure ORCA session to read appropriate source 
//  encoding
iErrCode = PBORCA_ConfigureSession(hPbOrca, &Config);
//  Now import the source for the entry
fpError = (PBORCA_ERRPROC) ErrorProc;
iErrCode = PBORCA_CompileEntryImport(
   _TEXT("w_edit_connect"), PBORCA_WINDOW,
   _TEXT("test embedded OLE object"),
   (LPTSTR) pReadBuffer, iSourceSize,
         fpError, NULL);
if (iErrCode != PBORCA_OK)
   goto TestExit;
if (iBinarySize > 0)
   iErrCode = PBORCA_CompileEntryImport(
      _TEXT("w_edit_connect"), PBORCA_BINARY, 
         (LPTSTR) pEndBuffer, iBinarySize,
                 fpError, NULL);
if ( hOpenFile != INVALID_HANDLE_VALUE )
if (pReadBuffer)
return iErrCode;
// Callback error procedure used by the call to compile 
// an object. In this example it is supplied by the 
// program and is not a method of the ORCA class.
void CALLBACK ErrorProc(PBORCA_COMPERR *lpCompErr,
     LPVOID lpUserData)
 _tprintf(_TEXT("%s \n"), lpCompErr->lpszMessageText );

See also