Wednesday, August 27, 2014

A hole in decorated C++ names

At the first glance Decorated C++ Names are ideal, they encode all possible C++ method names and allow links between .obj and .lib files. Read Format of a C++ Decorated Name.

But sometime these names can bring some mystics into your life. Today we spent plenty of time revealing a method of a one class doesn't work. It IS called, but you NEVER hit it. This became possible because there were TWO(!!) different classes of the same name.

Here is a prototype project reproducing such a case.



ClassA.h:
#include "Base.h"
class
ClassA : public Base
{
public:
   ClassA(void);
   int f(void);
};

ClassB.h:
#include "Base.h"
class
ClassA : public Base
{
public:
   ClassA(int a);
   int g(void);
};


The reason why compiler and linker produce no errors is because they have different Decorated C++ Names.
ClassA.obj:

?g@ClassA@@QAEHXZ (public: int __thiscall ClassA::g(void))
??0ClassA@@QAE@H@Z (public: __thiscall ClassA::ClassA(int))
??1ClassA@@QAE@XZ (public: __thiscall ClassA::~ClassA(void))

ClassB.obj:
?f@ClassA@@QAEHXZ (public: int __thiscall ClassA::f(void))
??0ClassA@@QAE@XZ (public: __thiscall ClassA::ClassA(void))
??1ClassA@@QAE@XZ (public: __thiscall ClassA::~ClassA(void))

Decorated Name of destructors are the same, but linker was surprisingly silent
(See Viewing Decorated Names for reference)


Monday, August 11, 2014

Fitting multilungual resources in Visual Studio C++ project in user-friendly manner

Going to I18n with our MFC Visual Studio C++ projects, we were considering several methods for organizing resources, (read here for details):
  1. Language-dependent binary 
  2. One resource DLL for all languages 
  3. One resource DLL per target language 

I bet #2 is the best one, and here is how to organize .rc files and VS projects in the way good both: for machine and for humanity. Good for machine, because:
Good for humanity because:
  • resources for all languages will be capable of manual editing with Visual Studio (thus you can keep resources synchronized among different languages), 
  • It would be possible to edit TEXTINCLUDE from VS GUI.
Plenty of time spent for investigation, reading docs, exploring existing projects and collegial disputes made it possible to get desired structure of VS C++ project and .rc files. This structure might be used as a template for other projects, and even might be an Ariadne's thread in localization labyrinth.