PBORCA_CompileEntryImport
Description
Imports the source code for a PowerBuilder object into a library and
compiles it.
Syntax
|
1 2 3 4 5 6 7 8 9 |
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 |
|
lpszLibraryName |
Pointer to a string whose value is the file name of |
|
lpszEntryName |
Pointer to a string whose value is the name of the |
|
otEntryType |
A value of the PBORCA_TYPE enumerated data type 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 |
|
lpszEntrySyntax |
Pointer to a buffer whose value is source code for |
|
lEntrySyntaxBuffSize |
Length of the lpszEntrySyntax buffer. This length is |
|
pCompErrorProc |
Pointer to the PBORCA_CompileEntryImport callback The If you don’t |
|
pUserData |
Pointer to user data to be passed to the The user If you |
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 |
|
-6 PBORCA_LIBNOTINLIST |
Library not in list |
|
-8 PBORCA_COMPERROR |
Compile error |
|
-9 PBORCA_INVALIDNAME |
Name does not follow PowerBuilder naming |
|
-13 PBORCA_CURRAPPLNOTSET |
The current application has not been |
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:
|
1 2 3 4 5 6 7 8 9 10 |
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.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
// 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 "), lpCompErr->lpszMessageText ); } |
See also