Unmanaged C++ String Table

Hi, I'm evaluating this add-on for my company, and I have a question about it's functionality for unmanaged C++ projects - Is it possible to add new strings to the string table through the add-in or do they have do be added through Visual Studio's resource editor first?
> Hi, I'm evaluating this add-on for my company, and I have a question about it's functionality for unmanaged C++ projects - Is it possible to add new strings to the string table through the add-in or do they have do be added through Visual Studio's resource editor first?

Germany

I'm on vacation at present and can't try it out, but I don't think it is possible.

I'll take a look when I get back home, and I'll think about whether it would be an easy feature to add. (I'll be back home next week.)

Phil


Thanks for looking into this issue!
If it is possible to add the "add string" feature, please also consider adding an option that would use the value of a new string entry as the default value of the new entries for all languages. This would help immensely for our application.

Germany

Sorry that it has taken me such a long time to reply to this.frown

There is no direct function to add a new string to the string table, but it is performed automatically if you select a string for translation in the source code.

As a test, I made a small source file:

C source without localization
#include "stdafx.h"

void junk_function()
{
  CString TestText = "Example Text" ;
}

After scanning the project, this is shown in the source code tab.
Image

If I select the text by clicking on the check box...
Image

then a resource ID number is assigned to the string, and the macro ML_STRING is inserted into the code...

C source with localization
#include "stdafx.h"

void junk_function()
{
  CString TestText = ML_STRING(102, "Example Text") ;
}

I was expecting the string table to be generated automatically, but that didn't seem to work.
However, after using the menu command "Store resources for unmanaged projects"...
Image

the files resource.h and projectname.rc were updated.

from resource.h
#define IDS_MULTILANG_102               102
from projectname.rc
STRINGTABLE PRELOAD DISCARDABLE
BEGIN
    IDS_ABOUTBOX            "&About CmnCtrl1..."
    IDS_MULTILANG_102       "Example Text"
END

The define in resource.h is actually unnecessary, because it isn't really used. The string table in the .rc file is actually much bigger than shown here.

Note that it also generated Croation resources, using the English texts.

from projectname.rc
/////////////////////////////////////////////////////////////////////////////
// Croatian resources (Added by Multi-Language Add-In)

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_HRV)
#ifdef _WIN32
LANGUAGE LANG_CROATIAN, SUBLANG_NEUTRAL
#endif //_WIN32

STRINGTABLE PRELOAD DISCARDABLE
BEGIN
    IDS_ABOUTBOX            "&About CmnCtrl1..."
    IDS_MULTILANG_102       "Example Text"
END

So, although you can't directly add items to the string table, they are added by the Add-In when you select a string in the source code.

Do you have a requirement to add strings to the string table, which are used in some other manner? I'm sure that I could add such a function, but I'm not sure that it is necessary.

With regard to your other question, about using the original string as the default for other languages, this should work already, as shown with the (non) Croatian text above.

The original text is shown in grey in the Add-In's grid, which is meant to indicate resource fallback. For .NET projects, there is a built-in fallback mechanism. Although this doesn't work with unmanaged resources, the Add-In mimics it by exporting the original text to the .rc file if no language specific text is available.

(This should also work between regional languages and the non-regional parent, e.g. US-English and English.)

I mentioned above that I had expected the .rc file to be updated automatically, but it was not. I will look into this.

I'm also not sure that it was a good idea that the function ml_string (called by the macro ML_STRING) returns a CString object.

Let me know if you have more questions about C++ support.

Best regards
Phil

Germany

I have just looked into why the .rc file was not updated automatically.

This only occurs if there is only one language in the project. If there at least two languages, then the .rc file is updated immediately. This will be fixed in the next version.

(For .NET projects skips generating language specific .resx files if there is only one language, because the neutral .resx file contains the same strings. This condition is nonsense for unmanaged projects.)

Phil