PBORCA_CompileEntryImport

Description

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

Syntax

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

Argument

Description

hORCASession

Handle to previously established ORCA session.

lpszLibraryName

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

lpszEntryName

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

otEntryType

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

PBORCA_APPLICATION

PBORCA_BINARY

PBORCA_DATAWINDOW

PBORCA_FUNCTION

PBORCA_MENU

PBORCA_PIPELINE

PBORCA_PROJECT

PBORCA_PROXYOBJECT

PBORCA_QUERY

PBORCA_STRUCTURE

PBORCA_USEROBJECT

PBORCA_WINDOW

lpszComments

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

lpszEntrySyntax

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.

lEntrySyntaxBuffSize

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

pCompErrorProc

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.

pUserData

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

Description

0       PBORCA_OK

Operation successful

-1      PBORCA_INVALIDPARMS

Invalid parameter list

-4      PBORCA_BADLIBRARY

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

-6      PBORCA_LIBNOTINLIST

Library not in list

-8      PBORCA_COMPERROR

Compile error

-9      PBORCA_INVALIDNAME

Name does not follow PowerBuilder naming rules

-13      PBORCA_CURRAPPLNOTSET

The current application has not been set


Usage

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

PowerBuilder

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.

Caution

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.

Examples

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:

PBORCA_ERRPROC fpError;
int nReturnCode;
 
fpError = (PBORCA_ERRPROC) ErrorProc;
nReturnCode = PBORCA_CompileEntryImport(
   lpORCA_Info->hORCASession,
   _TEXT("c:\\app\\dwobjects.pbl)",
   _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[])
#else
INT main ( int argc, char *argv[])
#endif
{
   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,
     NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 
if( hOpenFile == INVALID_HANDLE_VALUE )
    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;
    else
       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)
{ 
    LPWSTR
          pszUniBinHeader;
    LPWSTR
    pUniBinStart;
    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);
    }
    else
    {
    iSourceSize = (INT) dFileSize;
    iBinarySize = 0;
    }
}
else
{
    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);
    }        
    else        
    {            
       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(
   hPbOrca,
   pszLibraryName[4], 
   _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(
       hPbOrca,
              pszLibraryName[4], 
      _TEXT("w_edit_connect"), PBORCA_BINARY, 
      NULL,
         (LPTSTR) pEndBuffer, iBinarySize,
                 fpError, NULL);
}   
}
TestExit:
if ( hOpenFile != INVALID_HANDLE_VALUE )
         CloseHandle(hOpenFile);
if (pReadBuffer)
   free(pReadBuffer);   
PBORCA_SessionClose(hPbOrca);   
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

PBORCA_LibraryEntryExport

PBORCA_CompileEntryImportList

PBORCA_CompileEntryRegenerate

PBORCA_ApplicationRebuild