Category Archives: C/C++

C++ builder EAccessViolation when calling Variant.OlePropertySet() for Excel Automation

After migrating an application from C++ Builder 4 to C++builder 6, the excel COM automation started to crash with error EAccessViolation at address 00000800 when calling the Variant.OlePropertySet(), OlePropertyGet() or OleFunction() methods, as in the following code :

[code lang=cpp]
Variant xlApp = Variant::CreateObject(“Excel.Application”);
xlApp.OlePropertySet(“Visible”, true); // causes the EAccessViolation
Variant workbooks = xlApp.OlePropertyGet(“Workbooks”);
Variant currentWorkbook ClasseurCourant = workbooks.OleFunction(“Open”, L”C:\\MyExcelFile.xls”);
[/code]
Excel-OlePropertySet-EAccessViolation
This code was working fine with Builder 4, it was also working fine when used in a brand new application, but it always crashed in the converted app. Given that many developers reported the same error, with no known fix, and that one couldn’t expect support for a 12 years old IDE, I eventually fixed the issue by bypassing the Borland Wrappers and using directly COM.
Continue reading

Which command line parser for C++ apps ?

If you need to parse command line arguments in C++, don’t reinvent the wheel, use an existing library. That’s the kind of problem that seems so simple that it’s obvious you’ll quickly hack it. Then you face parsing bugs, spaces within parameters, special characters, optional parameters, config files, etc. Eventually you’ll switch to a library, so save time and do it from the beginning.

Many libraries are available out there for C++ applications, I’ll focus on two of them : Boost.Program_options and GetPot. Continue reading

Basic color scale conversion algorithm

Your app has some pictures/icons, and you’d like to have them in different color scales, for highlighting for example.
Rather than creating a different set of icons, it is cheaper to convert them dynamically to the desired color : redscale, greenscale, or bluescale.
earth
Continue reading

How to enable/disable Windows application Visual Styles at runtime ?

The challenge : update the look&feel of an outdated Borland C++ Builder 4 application, while changing the minimum amount of code, and keeping the same old 1998 compiler… To make things even easier, the new look and feel must be enabled/disabled at runtime.

First, the application UI controls  are straight out of the nineties. To modernize their look without replacing or rewriting them, Microsoft introduced in Windows XP “Application Visual Styles”. The MSDN doc about Visual Styles is not great, but this CodeProject article from Martin Mitáš gives a great overview. Continue reading