Resolving linker errors when using TMetafileCanvas

By: CodeGear

Abstract: Fix for "Unresolved external" errors when using TMetafileCanvas. Involves updating the VCLE50.LIB file

Many people in the developer community have run into a problem using TMetafileCanvas with Builder 5. When compiling code that calls one of the TMetafileCanvas constructors, the linker reports an unresolved external error resembling one of the following:

"Unresolved external '__fastcall Graphics::TMetafileCanvas::TMetafileCanvas(Graphics::TMetafile *, void *, const System::AnsiString, const System::AnsiString)' referenced from "

or

"Unresolved external '__fastcall Graphics::TMetafileCanvas::TMetafileCanvas(Graphics::TMetafile *, int)' referenced from D:\PROGRAM FILES\BORLAND\CBUILDER5\LIB\RELEASE\VCLE50.LIB|_t_Graph"

This is caused by a bug in one of the libraries that enables the use of the VCL from the C++ language.

One work around is to edit the VCL header file Graphics.hpp, changing the type of the second parameter of the TMetafileCanvas constructors from 'HDC' to 'unsigned int'. After this change, calling the constrctors will require typecasting the second parameter to unsigned int.

While this works, it is not the best solution. When the bug causing this problem is fixed, the typecast will no longer be necessary and will cause compiler errors (albeit easy to fix compiler errors) when the source is recompiled.

The following fix addresses the problem at the source; the library file that contains the bug. Special thanks to Stefan Hoffmeister for developing and posting this fix on the Borland public newsgroups.

The file being fixed is VCLE50.LIB, found in both the "\lib\Release" and "\lib\Debug" folders. These paths are relative to the root folder of the C++ Builder installation. The default root folder is "C:\Program Files\Borland\CBuilder5", but may be different depending on installation configuration. Know where the Builder root directory is on your system before attempting this fix.

Corruption of VCLE50.LIB file or other files in the same directory will cripple Builder, leaving it unable to build VCL projects. If this happens, restoration of the corrupted files from the Builder 5 installation CD will be necessary.

This fix requires use of the command console (COMMAND.EXE on Win9x and CMD.EXE on WinNT). Succcessfulling implementing this fix requires familiariarity with navigating, running executables, and changing the path on the command line. The command-line tools TLIB.EXE and TASM32.EXE will be used during the course of this fix. Be certain that the Builder 5 "bin" directory is on your path before other versions of Builder. Using the wrong version of these tools could corrupt the file you are fixing.

Do not attempt this fix unless you completely understand the instructions given and are confident using the command line environment.

Save the assembly code below to a text file. Name the text file "TMetaFileCanvasFix.asm" and save it in the "\lib\Release" folder and the "\lib\debug" folder.



       .386
       .MODEL FLAT
       .CODE

       EXTRN     @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafileuix17System@AnsiStringt3:NEAR
_TEXT  segment   dword public 'CODE' use32
       @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilepvx17System@AnsiStringt3    segment virtual
       @@Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilepvx17System@AnsiStringt3  PROC
       jmp       @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafileuix17System@AnsiStringt3
       @@Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilepvx17System@AnsiStringt3  ENDP
       @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilepvx17System@AnsiStringt3    ends
_TEXT  ends

       EXTRN     @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafileuix17System@AnsiStringt3:NEAR
_TEXT  segment   dword public 'CODE' use32
       @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilep5HDC__x17System@AnsiStringt3    segment virtual
       @@Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilep5HDC__x17System@AnsiStringt3  PROC
       jmp       @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafileuix17System@AnsiStringt3
       @@Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilep5HDC__x17System@AnsiStringt3  ENDP
       @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilep5HDC__x17System@AnsiStringt3    ends
_TEXT  ends


       EXTRN     @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafileui:NEAR
_TEXT  segment   dword public 'CODE' use32
       @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilepv    segment virtual
       @@Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilepv  PROC
       jmp       @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafileui
       @@Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilepv  ENDP
       @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilepv    ends
_TEXT  ends


       EXTRN     @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafileui:NEAR
_TEXT  segment   dword public 'CODE' use32
       @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilep5HDC__    segment virtual
       @@Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilep5HDC__  PROC
       jmp       @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafileui
       @@Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilep5HDC__  ENDP
       @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilep5HDC__    ends
_TEXT  ends


       EXTRN     @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafileui:NEAR
_TEXT  segment   dword public 'CODE' use32
       @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilei    segment virtual
       @@Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilei  PROC
       jmp       @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafileui
       @@Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilei  ENDP
       @Graphics@TMetafileCanvas@$bctr$qqrp18Graphics@TMetafilei    ends
_TEXT  ends

       END

Open a command console and navigate to the "\lib\Release" directory. Run the following commands:


TASM32 /ml TMetafileCanvasFix.asm
TLIB /C VCLE50.LIB +TMetafileCanvasFix.obj

Navigate to the "\lib\Debug" directory and repeat the above commands.


Server Response from: ETNASC04