none
Change language of Win32 DLL RRS feed

  • Question

  • Hello,

    I use an unmanaged Win32 C++ library in my C# project. The library contains two string tables (English and German). Therefore the German string table is used when the language of Windows is set to German, otherwise the English string table is used.

    I would like to set the language manually. In a C++ application I use the function SetThreadUILanguage().
    In C#, I tried Thread.CurrentThread.CurrentCulture, Thread.CurrentThread.CurrentUICulture, CultureInfo.DefaultThreadCurrentCulture,  CultureInfo.DefaultThreadCurrentUICulture and SetThreadUILanguage (via DllImport) but it doesn't work. The Win32 library uses the operating system language.

    Is there a way to change the language of the Win32 library in C# or do I need to implement a function in the Win32 library that changes the language?

    Monday, September 17, 2018 6:56 AM

Answers

  • Hi Zhanglong,

    thank you for your answer.

    I was able to solve the problem in the meantime. The language of the Win32 DLL can be set using the Win32 function SetThreadUILanguage(). On my first attempt, I called the function in the wrong thread...

    Regards,

    Manuel

    • Marked as answer by Parfant Wednesday, September 19, 2018 12:58 PM
    Wednesday, September 19, 2018 12:58 PM

All replies

  • By my understanding, you wanna mannualy change the current culture? try  using Globalization? Here is the MSDN link.

    https://docs.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo?view=netframework-4.7.2

    Monday, September 17, 2018 9:50 PM
  • Thank you for your reply.

    Yes, you understand it right, I wanna change the current culture manually.
    In my attempts, this was possible with the .NET application (GUI, Resources, ...) but not with the functions of the Win32 DLL used by the .NET application.

    Is it possible to define the culture via DllImport Attribute?


    • Edited by Parfant Tuesday, September 18, 2018 7:12 AM
    Tuesday, September 18, 2018 6:06 AM
  • Hi Parfant,

    As far as I know, C# interop does not provide a parameter to set language information, I would suggest that you could add a language parameter into your C++ method and return different result via this language parameter.

    Best regards,

    Zhanglong 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 18, 2018 8:09 AM
    Moderator
  • Hi Zhanglong,

    thank you for your answer.

    I was able to solve the problem in the meantime. The language of the Win32 DLL can be set using the Win32 function SetThreadUILanguage(). On my first attempt, I called the function in the wrong thread...

    Regards,

    Manuel

    • Marked as answer by Parfant Wednesday, September 19, 2018 12:58 PM
    Wednesday, September 19, 2018 12:58 PM