SharpDX.Windows.RenderForm is not Unicode compatibility #185
Comments
Can you, please, post a project where the issue can be reproduced? I've tried to modify the MiniCube.Desktop sample to reproduce - but it works correctly as shown in this screenshot. The DllImport.CharSet field specifies how the strings parameters are passed between unmanaged and managed code and it doesn't influence the RenderForm title. I suppose you have a different usage scenario, so please provide more details about it. |
Thanks for your comment. I am explaining in more details as below... Method Update(GameTime gameTime) is called the first time before game run (see code). At this time, the statement { Window.Title = "Tiếng Việt"; } can change the window title correctly because the WndProc hasn't been changed. Then, after WndProc is hooked, RenderForm becomes non-Unicode, but in next Update() calls, the statement { Window.Title = "Tiếng Việt"; } won't change the window title (see code) and you won't see the error in your sample. If you modify the code of MiniCube.Desktop as following, you will reproduce the bug:
|
…to instead of Ansi (github issue #185).
Thank you for explanation. It should be fixed now. Once the changeset above will get into master branch - it will be integrated into latest dev package. |
Thanks for your update but I see that the bug won't be fixed if Win32Native.CallWindowProc is still using Ansi version. I think all other classes, structs, functions... mapped from Win32 API with 2 versions Unicode & Ansi should use CharSet.Auto or CharSet.Unicode also. For examples: Function GetFocus does not require CharSet, then we can delete this attribute. |
While it is a good idea to fix these, I am not sure if it is worth to make these changes blindly without a good test case. Thank you for pointing out these issues, I will look into them as soon as will find some time. |
If I change game window title with a Unicode string "Tiếng Việt", the window title will become "Ti?ng Vi?t" (this error occurs after game is initialized).
Beside, if I handle Key_Press event of the window form, I will never get KeyChar with a Unicode character.
I think the problem comes from MessageFilterHook.cs when SharpDX call Win32Native.SetWindowLong to change WndProc of the window with a non-Unicode one.
In Win32Native.cs, the following DllImport lines:
[DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Ansi)]
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", CharSet = CharSet.Ansi)]
should be modified CharSet = CharSet.Auto instead of CharSet.Ansi.
All other Win32Native functions should use CharSet.Auto too.
The text was updated successfully, but these errors were encountered: