LS, I am using FindWindow method in c# application to get window handle from web browser
[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName );
it works well when the window title does not contain utf chars like here:
string caption1 = "pinvoke.net: findwindow (user32) - Google Chrome";
int hwnd = FindWindow(null, caption1);
but it fails when utf chars are present in window title:
string caption2 = "Słownik języka polskiego - Google Chrome";
int hwnd2 = FindWindow(null, caption2);
e.g. hwnd == 0
Would You please provide me with any suggestion how to get handle of browser window containing utf-8 chars in c# application. Thanks in advance.
ps I have already seen the comment about using FindWindow with utf in c++, saying: "You can explicitly use the Unicode version of the API HWND windowHnd = FindWindowW(NULL, L"Minesweeper");" but I still don't know how to do it properly in c#
I haven't tried this myself, but you should be able to do this:
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int FindWindow(string lpClassName, string lpWindowName );
According to MSDN's article on the DllImportAttribute.CharSet Field, the default assumption will be CharSet.Ansi
, and that would result in the behavior you're describing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With