Главная страница | назад





Article #26084: Resolving strange runtime errors in my VCL enabled console application.

Symptoms:

Access violation at application start up or shut down. Access violation when dynamically allocating STL objects. STL strings lose data for no reason. Most likely to happen in VCL enabled console applications created with Console Wizard.

Problem:

Any application that uses the VCL must be compiled with the thread safety compiler setting and linked to the VCL enabled runtime library (cp32mt.lib or cp32mti.lib). The IDE usually takes care of these settings for you, based on the project type you select. Unfortunately, a bug in the Console Wizard makes it possible to create a VCL enabled console project that does not compile for thread safety, but does link to the correct library.

Inside the Console Wizard (File | New... | Console Wizard), you'll notice that the 'Multithread' box grays out when you check 'Use VCL' but does not become checked if it was not checked to begin with. Clicking 'OK' when 'VCL' is checked and 'Multithreaded' is not checked causes the error condition.

Solution:

For new projects, make sure 'Multithreaded' is checked if you are using the VCL.

For existing projects, you must manually fix the problem in the project file.

Open the project file (.BPR file) in an external editor such as notepad. Search for the line beginning with:

<CFLAG1 value="-tW -tWM- -Od

Remove the trailing minus symbol from the "-tWM-" flag. Save and close the file. Open the project in C++Builder and rebuild your project.

Last Modified: 20-NOV-00