wxAutomationObject Cyrillic Text Problem

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
SandyHip
Earned a small fee
Earned a small fee
Posts: 11
Joined: Wed Jun 02, 2010 9:44 am

wxAutomationObject Cyrillic Text Problem

Post by SandyHip » Wed Jun 02, 2010 9:47 am

WX : 2.8.3 (Not Unicode)
OS : Windows XP
COMPILER: GCC 3.4.5 (Code::Blocks); VC 7 (VS 2003.NET)

Code: Select all

wxAutomationObject obj.
/* ... */
wxVariant v = wxVariant(wxT("Мама")); // Cyrillic text
/*
wxCSConv convFrom(wxT("cp-1251"));
wxCSConv convTo(wxT("utf-8"));
wxString s = wxT("Мама");	// Cyrillic text
v = wxVariant(wxString(s.wc_str(convFrom), convTo));
*/
if (!obj.PutProperty(wxT("Value"), v)) {
	throw wxXlsException("Can't Write Value!");
}
Result: "Ìàìà"

Please, help me!
P.S.: If text in english, or numeric value - all Ok
[/code]

catalin
Moderator
Moderator
Posts: 1526
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Post by catalin » Wed Jun 02, 2010 11:05 am

You probably need to set the correct encoding in C::B. Read this for a slightly different example.

You may also need to set the correct locale for your program. The default one is taken from the OS, i.e. if your Windows is in English, you're program will run by default using English locale.

SandyHip
Earned a small fee
Earned a small fee
Posts: 11
Joined: Wed Jun 02, 2010 9:44 am

Post by SandyHip » Wed Jun 02, 2010 2:48 pm

In Visual Studio has realized so:

Code: Select all

/// Need #include <comutil.h>
/// Need Link comsupp.lib

bool SetStringValue(IDispatch* pDisp, PSTR sValue)
{
	VARIANTARG	rParam[1];
	DISPPARAMS	pParam = {&rParam[0], NULL, 1, 0};
	_bstr_t		pValue = sValue;
	DISPID		nIdName = DISPID_PROPERTYPUT;

	VariantInit(&rParam[0]);
	rParam[0].vt = VT_BSTR;
	rParam[0].bstrVal = SysAllocString((BSTR)pValue);

	pParam.cNamedArgs = 1;
	pParam.rgdispidNamedArgs = &nIdName;

	const HRESULT hResult = pDisp->Invoke(6, IID_NULL, 
		GetSystemDefaultLCID(), 
		DISPATCH_PROPERTYPUT, 
		&pParam, NULL, NULL, NULL);
	SysFreeString(rParam[0].bstrVal);

	return hResult == S_OK;
}


/* ... */
wxAutomationObject obj.
/* ... */
wxVariant v = wxVariant(wxT("Мама")); // Cyrillic text
/* ... */
if (v.IsType(wxT("string"))) {
    SetStringValue((IDispatch*)obj.GetDispatchPtr(), 
        (char*)v.GetString().c_str());
}
else {
    obj.PutProperty(wxT("Value"), v);
}
/* ... */

Post Reply