c++windowscomatlole-automation

How to call GetAltMonthNames to fill a safe array of foreign locale month strings?


I saw this function and was wondering how to call this. I might like to write a component and export this function to a COM client so I wanted to fill a safearray of strings (other Automation types are fine). So I wanted to leverage an ATL smart class. This is what I have so far, a console application.

#include "pch.h"
#include <iostream>
// in pch.h ...
//#include "windows.h"
//#include "comutil.h"
//#include "atlbase.h"
//#include <comdef.h>
//#include "atlsafe.h"


int main()
{
    LCID germany(7);
    LPOLESTR *rgp;
    HRESULT hr;
    hr=::GetAltMonthNames(germany, &rgp); // can't see results
    if (hr != S_OK) return hr;

    CComSafeArray<BSTR> months;
    hr = ::GetAltMonthNames(germany,(LPOLESTR**) &months); //forced compile but no joy
    if (hr != S_OK) return hr;
    std::cout << "Hello World!\n"; 
}

Solution

  • Your first code is ok but there's no alternate names for German language defined. Try Polish:

    LPOLESTR* rgp;
    if (SUCCEEDED(GetAltMonthNames(1045, &rgp)))
    {
        int i = 0;
        while (rgp[i])
        {
            wprintf(L"%s\n", rgp[i++]);
        }
    }
    

    Documentation says:

    Useful for Hijri, Polish and Russian alternate month names.