Interpreting Arguments and Strings Based on the Locale ID

Some methods or properties need to interpret arguments based on the LCID. These methods or properties can require that an LCID be passed as an argument. Therefore, properties should be designed to have an LCID parameter.

The following example code of an object description language file implements a property that takes a LCID.

[
    uuid(83219430-CB36-11cd-B774-00DD01103DE1),
    helpstring("Bank Account object."),
    oleautomation,
    dual
    ]
    interface IBankAccount : IDispatch
    {
        [propget, helpstring("Returns account balance formatted for the             country described by localeID.")]
        HRESULT CheckingBalance([in, lcid] long localeID, [out, retval]         BSTR* retval);
        :
    }
 

In this example, get_CheckingBalance returns a currency string that contains the balance in the checking account. The currency string should be correctly formatted depending on the locale that is passed in. ConvertCurrency is a private function that converts the checking balance to the currency of the country described by the LCID. The string form of converted currency is placed in m_szBalance. GetCurrencyFormat is a 32-bit Windows function that formats a currency string for the given locale.

The following represents the information contained in the header file:

class FAR CBankAccount : public IBankAccount
{
    public:
    // IUnknown methods (omitted).
        :

    // IDispatch methods (omitted).
        :

    // IBankAccount methods.
    STDMETHOD(get_CheckingBalance)(long llcid, BSTR FAR* pbstr);
        :
}
 

The following represents the .cpp file:

STDMETHODIMP
CBankAccount::get_CheckingBalance(long llcid, BSTR FAR* pbstr)
{
    TCHAR ach[100];
    ConvertCurrency(llcid);
        GetCurrencyFormat(llcid, 0, m_szBalance, NULL, ach,
        sizeof(ach));
        *pbstr = SysAllocString(ach);         // Return currency string                                                 // formatted according to 
                                            // locale ID. 
                                     
        return NOERROR;
}
 

The LCID is commonly used to parse strings that contain locale-dependent information. For example, a function that takes a string such as "6/11/96" needs the LCID to determine whether the month is June (6) or November (11). You should not use the LCID for output strings, including error strings. These strings should always be displayed in the current system language.