Compilation Directives
$BCX$ macro substitute
$BCX$ is a replaceable macro substitute for the path to the \bin\ folder containing the BC.EXE file. This path is derived from the Registry entry made during the BCX installation process and includes a trailing backslash.
If the \bin\ folder has been moved since the installation then this macro will not function properly. To correct the Registry entry after such a move run the BCX translator with the -r switch.
BC -r
To determine, for certain, the value which would be returned by the $BCX$ macro, run the following one line program.
PRINT BCXPATH$
The $BCX$ macro can be used only with the $COMPILER, $LINKER, $RESOURCE, $ONENTRY and $ONEXIT directives.
Syntax:
$BCX$
Parameters:
|
$ONENTRY directive
Purpose: Directive to perform functions after BCX translation but before any $COMPILER, $LINKER, $RESOURCE, or $ONEXIT directives.
Syntax: $ONENTRY "StringLiteralDirective" Parameters:
|
Example:
$ONENTRY "echo Starting to compile $file$"
$ONEXIT directive
Purpose: Directive to perform functions after BCX translation and after any $COMPILER, $LINKER, $RESOURCE, or $ONENTRY directives.
Syntax: $ONEXIT "StringLiteralDirective" Parameters:
|
Example:
$ONEXIT "echo Completed compiling the C translation of $FILE$"
$FILE$ macro substitute
$FILE$ is a self-referencing substitute for the file name without the extension. For example, if the file name is ThisFile.bas, $FILE$ will substitute ThisFile.
$FILE$ can be used only with the $COMPILER, $LINKER, $RESOURCE, $ONENTRY and $ONEXIT directives.
Syntax:
$FILE$
Parameters:
|
$PELLES$ macro substitute
$PELLES$ is a replaceable macro substitute for the root path, including a trailing backslash, of the Pelle's C installation. The root path is derived from the Registry entry made by the Pelle's C installation process. If the Pelle's C folder has been moved since the installation then this macro will not function properly.
To determine for certain the value which would be returned by the $PELLES$ macro, run the following one line program.
PRINT PELLESPATH$
The $PELLES$ macro can be used only with the $COMPILER, $LINKER, $RESOURCE, $ONENTRY, and $ONEXIT directives.
Syntax:
$PELLES$
Parameters:
|
$RESOURCE directive
Purpose: Directive to invoke a resource compiler. If the $LINKER directive is used then the $RESOURCE directive must be placed before the $LINKER directive.
Syntax: $RESOURCE "ResourceCompiler" ["ResourceFile.rc"] Parameters:
|
Example:
$RESOURCE "$PELLES$\bin\porc.exe" "Resource.rc"
BCX_RESOURCE statement
Purpose: This statement is used to inline statements which would usually be placed in an .rc resource file.
If the BCX_RESOURCE statement is used without a prior $RESOURCE directive, a file named $FILE$__.rc is created in the default folder. In this case the $FILE$__.rc file is not compiled.
If a .rc resource file has been specified as a parameter in the $RESOURCE directive, the specified .rc file is copied to a new file named $FILE$__.rc to which the BCX_RESOURCE statements are concatenated. The $FILE$__.rc file is then compiled into a .res file. If the $LINKER directive is used after the $RESOURCE directive, the resulting .res file is also linked into the .exe file.
Syntax: BCX_RESOURCE .rc format statement Parameters:
|
Example:
The following example requires an icon file named "smiley.ico".
GUI "BCX_Template", ICON, 1234 $RESOURCE "$PELLES$\bin\porc.exe" $COMPILER "$PELLES$\Bin\pocc -W1 -Gd -Go -Ze -Zx -Tx86-coff $FILE$.c" $LINKER "$PELLES$\Bin\polink _ -release _ -machine:ix86 _ -subsystem:windows _ -OUT:$FILE$.exe _ $FILE$.obj " BCX_RESOURCE 1234 ICON "smiley.ico" SUB FORMLOAD GLOBAL Form1 AS HWND Form1 = BCX_FORM("BCX_TEMPLATE", 0, 0, 110, 110) BCX_SET_FORM_COLOR(Form1,QBCOLOR(31)) CENTER(Form1) SHOW(Form1) END SUB BEGIN EVENTS SELECT CASE CBMSG CASE WM_CLOSE DestroyWindow(Form1) EXIT FUNCTION END SELECT END EVENTS
$BCX_RESOURCE directive
Purpose: The $BCX_RESOURCE directive performs the same function as the BCX_RESOURCE statement above but it is used to bracket a block of resource statements. A $BCX_RESOURCE directive is placed before and after the resource statements.
Syntax: $BCX_RESOURCE /** Resource statements go here */ $BCX_RESOURCE |
Example:
$BCX_RESOURCE #define IDM_FONT 40001 "IDMAINMENU" MENU BEGIN MENUITEM "&About Me !", IDM_FONT END $BCX_RESOURCE
GETRESOURCE function
Purpose: The GETRESOURCE function returns, if successful, a pointer to the first byte of the resource; otherwise NULL is returned. The size of the resource is also returned through the &ResourceSize parameter.
Syntax: RetLPVOID = GETRESOURCE(ResourceID%, _ ResourceType$, _ &ResourceSize) Parameters:
|
Example:
$RESOURCE "$PELLES$\bin\porc.exe" $COMPILER "$PELLES$\Bin\pocc -W1 -Gd -Go -Ze -Zx -Tx86-coff $FILE$.c" $LINKER "$PELLES$\Bin\polink _ -release _ -machine:ix86 _ -subsystem:console _ -OUT:$FILE$.exe _ $FILE$.obj " ' The following .wav file resources are in ' BCX Yahoo Group files \Sound\multisound.zip BCX_RESOURCE 12345 RCDATA "bcx.wav" BCX_RESOURCE 12346 RCDATA "its_neat.wav" BCX_RESOURCE 12347 RCDATA "it_rocks.wav" GLOBAL hInstance AS HINSTANCE PlayRcSound(hInstance, 12345) ? : ? : ? : PRINT " B C X " :? : ? : ? sleep(100) PlayRcSound(hInstance , 12346) ? " Its Neat?" :? : ? : ? sleep(100) PlayRcSound(hInstance , 12347) ? " No! It Rocks" :? : ? : ? ? "Done, Hit any Key to Quit." KEYPRESS SUB PlayRcSound(hInst AS HINSTANCE, ResourceID%) DIM lpSndData AS LPVOID DIM RSize AS DWORD lpSndData = GETRESOURCE(ResourceID%, RT_RCDATA, &RSize) IF lpSndData <> 0 THEN PlaySound((LPCTSTR) lpSndData, hInstance, SND_MEMORY+SND_SYNC) EXIT SUB END IF END SUB
$COMPILER directive
Purpose: Directive to invoke a compiler.
Syntax: $COMPILER "StringLiteralDirective" Parameters:
|
Example:
$COMPILER "$PELLES$\Bin\pocc -W1 -Gd -Go -Ze -Zx -Tx86-coff $FILE$.c"
Using the Pelle's C Compiler driver, cc.exe, the following example, when placed at the beginning of the code for a DLL, will compile and link automatically when the bc.exe translator has finished translating the code file.
Example:
$COMPILER "$PELLES$\Bin\CC -W1 -Gz -Ze -Zx -Go -Tx86-coff $FILE$.c -release -machine:ix86 -subsystem:windows -dll"
$LINKER directive
Purpose: Directive to invoke a linker.
Syntax: $LINKER "StringLiteralDirective" Parameters:
|
Example 1: Windows mode
$LINKER "$PELLES$\Bin\polink _ -release _ -machine:ix86 _ -subsystem:windows _ -OUT:$FILE$.exe _ $FILE$.obj "
Example 2: Console mode
$LINKER "$PELLES$\Bin\polink _ -release _ -machine:ix86 _ -subsystem:console _ -OUT:$FILE$.exe _ $FILE$.obj "
Here is a complete GUI demo that demonstrates some of the above directives and macros. Included is a BCX_RESOURCE which is constructed from a bitmap file.
Save the following bitmap as BCX_BITMAP.BMP by
Save the following code as bcx_bitmap.bas into the same folder as BCX_BITMAP.BMP was saved then translate, compile and link by simply typing BC bcx_bitmap.
$RESOURCE "$PELLES$\bin\porc.exe" $COMPILER "$PELLES$\Bin\pocc -W1 -Gd -Go -Ze -Zx -Tx86-coff $FILE$.c" $LINKER "$PELLES$\Bin\polink _ -release _ -machine:ix86 _ -subsystem:windows _ -OUT:$FILE$.exe _ $FILE$.obj " BCX_RESOURCE 500 BITMAP "BCX_BITMAP.BMP" GUI "BCX_BITMAP" SUB FORMLOAD GLOBAL Form1 AS HWND GLOBAL Bmp1 AS CONTROL Form1 = BCX_FORM("BCX_BITMAP", 0, 0, 110, 110) BCX_SET_FORM_COLOR(Form1,QBCOLOR(15)) Bmp1 = BCX_BITMAP("", Form1, 115, 2, 35, 0, 0, 500) CENTER(Form1) SHOW(Form1) END SUB BEGIN EVENTS SELECT CASE CBMSG CASE WM_CLOSE IF MSGBOX("Are you sure?", "Quit Program!", MB_YESNO) = IDYES THEN DestroyWindow(Form1) END IF EXIT FUNCTION END SELECT END EVENTS
$BCXVERSION directive
Purpose:
The $BCXVERSION directive is placed at top of source file and if the BCX version is less than that specified by the directive, BCX will abort with a message that the translator must be updated. If the BCX version is equal to or greater than that specified by the directive, a statement is emitted stating the version of the translator specified in the $BCXVERSION directive.
The $BCXVERSION directive can be used to specify the minimum version of the BCX translator required to translate the program.
Syntax: $BCXVERSION "Version String" Parameters:
|
Example:
$BCXVERSION "3.82a"
BCX_VERSION$ variable
Purpose: BCX_VERSION$ can be used to specify the version of the BCX translator that was used when the program was translated.
Syntax: RetStr$ = BCX_VERSION$ Parameters:
Return Value:
|
Example 1 : This example will return the version of the BCX translator that was used when the example has been translated.
DIMRetStr$ RetStr$=BCX_VERSION$