How to get current operating system language? - winapi

I am newbie to mfc, and I got struck over how to get the current operating system language (Ex: If it is English operating system I must get it as English and locale can be different. For English OS locale can be Japanese vice versa).
Current locale I am getting it through GetSystemDefaultLangID and the only thing I was left with is I need to get the current operating system language.
Can anyone kindly help me to resolve this issue.

Perhaps you need GetUserDefaultUILanguage. The system's settings and user settings may not be the same.
User Interface Language Management
int wmain()
{
wcout << "GetUserDefaultUILanguage: " << GetUserDefaultUILanguage() << "\n";
wcout << "GetSystemDefaultUILanguage: " << GetSystemDefaultUILanguage() << "\n";
wcout << "\n";
wcout << "GetUserDefaultLangID: " << GetUserDefaultLangID() << "\n";
wcout << "GetSystemDefaultLangID: " << GetSystemDefaultLangID() << "\n";
wcout << "\n";
wcout << "GetUserDefaultLCID: " << GetUserDefaultLCID() << "\n";
wcout << "GetSystemDefaultLCID: " << GetSystemDefaultLCID() << "\n";
wcout << "\n";
wchar_t buf[100];
LCID lcid = GetUserDefaultLCID();
cout << "GetUserDefaultLCID: " << "\n";
if (GetLocaleInfo(lcid, LOCALE_ILANGUAGE, buf, 100)) wcout << buf << "\n";
if (GetLocaleInfo(lcid, LOCALE_SENGLANGUAGE, buf, 100)) wcout << buf << "\n";
if (GetLocaleInfo(lcid, LOCALE_SISO639LANGNAME, buf, 100)) wcout << buf << "\n";
return 0;
}

Related

Boost.Fibers hosted by worker threads seem not to work – why?

I'd like to use Boost.Fibers hosted by worker threads instead of just threads. I think I've done everything as in the manual while writing the code shown below, but it seems not to work – "<anonymous> called" is missing in the output.
Does anyone have an idea why?
#include <boost/fiber/all.hpp>
#include <boost/thread/barrier.hpp>
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <thread>
#define RIGHTNOW (std::cerr << "[thread " << std::this_thread::get_id() << "] ")
static inline
void run_worker(uint32_t threads, boost::barrier& barrier) {
RIGHTNOW << "run_worker(" << threads << ", " << (void*)&barrier << ") called" << std::endl;
boost::fibers::use_scheduling_algorithm<boost::fibers::algo::work_stealing>(threads);
barrier.wait();
RIGHTNOW << "run_worker(" << threads << ", " << (void*)&barrier << ") awaited everything else" << std::endl;
boost::fibers::mutex mutex;
boost::fibers::condition_variable_any cv;
mutex.lock();
RIGHTNOW << "run_worker(" << threads << ", " << (void*)&barrier << ") locked mutex" << std::endl;
cv.wait(mutex);
RIGHTNOW << "run_worker(" << threads << ", " << (void*)&barrier << ") awaited CV" << std::endl;
mutex.unlock();
}
void start_engine(uint32_t threads) {
RIGHTNOW << "start_engine(" << threads << ") called" << std::endl;
if (threads < 1u) {
threads = 1;
}
boost::barrier barrier (threads + 1u);
auto scheduler ([threads, &barrier]() { run_worker(threads, barrier); });
for (auto i (threads); i; --i) {
std::thread(scheduler).detach();
}
barrier.wait();
RIGHTNOW << "start_engine(" << threads << ") awaited everything else" << std::endl;
}
int main() {
RIGHTNOW << "main() called" << std::endl;
start_engine(1);
boost::fibers::fiber([]() {
RIGHTNOW << "<anonymous> called" << std::endl;
_Exit(1);
}).detach();
RIGHTNOW << "main() waiting" << std::endl;
for (;;) {
}
}
clang++ -std=c++11 -I ~/homebrew/Cellar/boost/1.70.0/include -L ~/homebrew/Cellar/boost/1.70.0/lib -l boost_fiber-mt -l boost_context-mt -l boost_thread-mt -o fibers fibers.cpp
./fibers

is this a bug in the eigen matrix log() implementation?

This simple test program...
#include <iostream>
#include <Eigen/Dense>
#include <unsupported/Eigen/MatrixFunctions>
using namespace Eigen;
int main()
{
Matrix<double,1,1> m11;
Matrix<double,2,2> m22;
Matrix<double,3,3> m33;
Matrix<double,4,4> m44;
m22.setZero();
m33.setZero();
m44.setZero();
std::cout << "Eigen version: " << EIGEN_WORLD_VERSION << "."
<< EIGEN_MAJOR_VERSION << "." << EIGEN_MINOR_VERSION << "\n";
std::cout << "11: " << m11.log() << "\n";
std::cout << "22: " << m22.log() << "\n";
std::cout << "33: " << m33.log() << "\n";
std::cout << "44: " << m44.log() << "\n";
}
hangs apparently while calculating m33.log(), giving the output:
Eigen version: 3.3.5
11: -728.932
22: -nan -nan
-nan -nan
[hangs here at 100% cpu]
with
g++ --version
g++ (GCC) 7.3.1 20180712 (Red Hat 7.3.1-6)
and also with
clang++ --version
clang version 5.0.2 (tags/RELEASE_502/final)
so I know it's invalid, but maybe a failure would be better than a hang, or do I really always need to check isInvertible() && all the eigenvalues before calling log() ?

How to fix incompatible character encodings: UTF-8 and ASCII-8BIT

The issue is with the 'chap << "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"' line.
chaps = []
ctoc = "toc1\x00"
ctoc << [3, chapters.size].pack("CC")
chapters.each_with_index do |ch, i|
num = i+1
title = ch[:title]
description = ch[:description]
link = ch[:link]
ctoc << "ch#{num}\x00"
chap = "ch#{num}\x00"
chap << [ch[:start]*1000, ch[:end]*1000].pack("NN");
chap << "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
title_tag = [title.encode("utf-16")].pack("a*");
chap << "TIT2"
chap << [title_tag.size+1].pack("N")
chap << "\x00\x00\x01"
chap << title_tag
chaps << chap
end
I have added the following to the top of the file but that didn't fix the issue. Any other ideas to try?
# encoding: utf-8

std::binary_search returns different result than std::find

Actually I couldn't see what's my mistake in my code but std::binary_search returns false for the element that have already added to vec_barcode. For comparison I tried std::find method & it works properly.
std::find(vec_barcode.begin(), vec_barcode.end(), "LOGUS") != vec_barcode.end() ? std::cout << "yes" << std::endl : std::cout << "no" << std::endl;
std::binary_search(vec_barcode.begin(), vec_barcode.end(), "LOGUS") ? std::cout << "yes" << std::endl : std::cout << "no" << std::endl;
Any help is appreciated.

c++11 type_traits: different result in INTEL 2013 and GCC 4.7.2

For the following class, INTEL 2013 (update 3) and GCC 4.7.2 give different type_traits results. Which one is right?
#include <iostream>
#include <type_traits>
using namespace std;
class A
{
public:
A() = default;
private:
double t_;
};
int main()
{
cout << boolalpha;
cout << "is_trivial<A> : " << is_trivial<A>::value << endl;
cout << "is_compound<A> : " << is_compound<A>::value << endl;
cout << "is_pod<A> : " << is_pod<A>::value << endl;
cout << "is_standard_layout<A> : " << is_standard_layout<A>::value << endl;
cout << "is_literal_type<A> : " << is_literal_type<A>::value << endl;
return 0;
}
INTEL output:
is_trivial<A> : true
is_compound<A> : true
is_pod<A> : false
is_standard_layout<A> : true
is_literal_type<A> : false
GCC output:
is_trivial<A> : true
is_compound<A> : true
is_pod<A> : true
is_standard_layout<A> : true
is_literal_type<A> : true
I would say GCC is correct. is_pod is true if it's both is_trivial and is_standard_layout: http://en.cppreference.com/w/cpp/types/is_pod . Intel compiler doesn't comply with this. is_literal_type should also be true since all the conditions seem valid for A: http://en.cppreference.com/w/cpp/types/is_literal_type

Resources